Created
August 13, 2012 23:39
-
-
Save jasonmc/3344867 to your computer and use it in GitHub Desktop.
Find unnamed heads in Mercurial
This file contains hidden or 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
from mercurial import commands, ui, localrepo | |
import sys | |
# default git branch name | |
cfg_master='master' | |
origin_name='' | |
def get_branch(name): | |
# 'HEAD' is the result of a bug in mutt's cvs->hg conversion, | |
# other CVS imports may need it, too | |
if name=='HEAD' or name=='default' or name=='': | |
name=cfg_master | |
if origin_name: | |
return origin_name + '/' + name | |
return name | |
def get_changeset(ui,repo,revision): | |
node=repo.lookup(revision) | |
(_,_,_,_,_,extra)=repo.changelog.read(node) | |
branch=get_branch(extra.get('branch','master')) | |
return branch | |
def verify_heads(ui,repo): | |
# verify that branch has exactly one head | |
t={} | |
for h in repo.heads(): | |
branch=get_changeset(ui,repo,h) | |
if t.get(branch,False): | |
sys.stderr.write('Error: repository has at least one unnamed head: hg r%s\n' % repo.changelog.rev(h)) | |
t[branch]=True | |
return True | |
if __name__=='__main__': | |
HG_DIR = sys.argv[1] | |
ui = ui.ui() | |
repo = localrepo.instance(ui, HG_DIR, create=False) | |
verify_heads(ui,repo) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment