Last active
December 15, 2015 14:28
-
-
Save dunhamsteve/5274383 to your computer and use it in GitHub Desktop.
A little utility to enumerate all of the svn, hg, and git repositories on the current machine. Requires a locate database. Outputs the type, remote url, and local path.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# This code is public domain, share and enjoy. | |
"""Enumerates svn, git, and mercurial repositories in locate database | |
""" | |
from subprocess import Popen,PIPE, check_output | |
import re, os.path | |
def find(pattern): | |
for line in Popen(['locate',pattern],stdout=PIPE).stdout: | |
fn = line.strip() | |
if not os.path.exists(fn): | |
continue | |
repo = line[:-len(pattern)] | |
yield repo,line.strip() | |
for repo,fn in find('*/.hg/hgrc'): | |
data = open(fn).read() | |
m = re.search(r'default\s*=\s*(.*?)\n',data) | |
print 'HG', m.group(1), repo | |
for repo,fn in find('*/.git/config'): | |
data = open(fn).read() | |
m = re.search(r'url\s*=\s*(.*?)\n', data) | |
if m: | |
print 'GIT', m.group(1), repo | |
prev = "None" | |
for repo,fn in find('*/.svn'): | |
if repo.startswith(prev): | |
continue | |
prev = repo | |
data = check_output(['svn','info',repo]) | |
m = re.search(r'URL: *(.*?)\n',data) | |
print 'SVN', m.group(1), repo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment