Skip to content

Instantly share code, notes, and snippets.

@dunhamsteve
Last active December 15, 2015 14:28
Show Gist options
  • Save dunhamsteve/5274383 to your computer and use it in GitHub Desktop.
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.
#!/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