Skip to content

Instantly share code, notes, and snippets.

Created August 8, 2009 16:01
Show Gist options
  • Save anonymous/164440 to your computer and use it in GitHub Desktop.
Save anonymous/164440 to your computer and use it in GitHub Desktop.
import os
PATCHIDCACHE={}
def getpatchid(commit):
if commit in PATCHIDCACHE:
return PATCHIDCACHE[commit]
r = os.popen("git-diff-tree -p %s | git-patch-id" % commit).read().strip().split()
if r:
PATCHIDCACHE[commit] = r
return r
def cherryharder(trunk, user):
first = os.popen("git rev-list --topo-order --reverse %s..%s | head -n 1" % (trunk, user)).read().strip()
base = os.popen("git rev-parse %s^ " % first).read().strip()
trunk_changes = os.popen("git rev-list %s..%s" % (base, trunk)).read().strip().split()
user_changesx = os.popen("git rev-list --reverse --pretty=oneline %s..%s" % (base, user)).read().strip().split("\n")
user_changes = [x.split(" ",1)[0] for x in user_changesx]
commit_patchids = {}
for c in trunk_changes + user_changes:
t = getpatchid(c)
if not t:
continue
[pid, cmt] = t
commit_patchids[cmt] = pid
trunk_patches = dict([(commit_patchids[x], x) for x in trunk_changes if x in commit_patchids])
res = []
for p in user_changes:
if not (p in trunk_changes or p not in commit_patchids or commit_patchids[p] in trunk_patches):
res.append(p)
return res
def mergetest(base, other):
# Should be possible to do something like this to
# test merge without workdir..
# 12:17 < mugwump> eg, git-read-tree --index-output=tmpindex treeish
# 12:17 < mugwump> git-read-tree -m --index-output=tmpindex tree2ish
os.system("git reset --hard %s >/dev/null" % base)
clean = os.system("git merge --no-commit %s >/dev/null 2>/dev/null" % other)
os.system("git reset --hard %s >/dev/null" % base)
return not bool(clean)
def changes(base, other):
c = os.popen("git rev-list --pretty=oneline %s..%s" % (base, other)).read().split("\n")
return dict([x.split(" ",1) for x in c if x])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment