Skip to content

Instantly share code, notes, and snippets.

@mwicat
Created October 24, 2013 10:55
Show Gist options
  • Select an option

  • Save mwicat/7135069 to your computer and use it in GitHub Desktop.

Select an option

Save mwicat/7135069 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import sys
import re
import os
import hglib
repos_dir = sys.argv[1]
ticket = sys.argv[2]
patches_dir = sys.argv[3]
repos = []
def get_msg(c):
m = re.sub('[\.@\- ]', '_', c.desc)
m = re.sub('\W', '', m)
m = re.sub('_{2,}', '_', m)
return m
def diff_for(client, reponame):
commits = client.log(keyword='#%s' % ticket)
for commit in commits:
r = commit.rev
fn = '%s_%s.diff' % (reponame, get_msg(commit))
fn = os.path.join(patches_dir, fn)
diff = client.diff(revs=[r+'^', r])
open(fn, 'w').write(diff)
print '%s (%s, %s, %s)' % (fn, reponame, commit.rev, commit.desc)
for repo in os.listdir(repos_dir):
try:
repo = os.path.abspath(os.path.join(repos_dir, repo))
reponame = os.path.basename(repo)
if reponame not in repos:
continue
client = hglib.open(repo)
diff_for(client, reponame)
except hglib.client.error.ServerError, e:
print 'error on processing %s, omitting...' % reponame
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment