[PATCH 07 of 10] Match new branch style API

Edouard Gomez ed.gomez at free.fr
Sun Dec 17 09:31:53 CST 2006


# HG changeset patch
# User Edouard Gomez <ed.gomez at free.fr>
# Date 1166365118 -3600
# Node ID 6c3c7fd48f4d7a56dadbc89384b97ac16558214e
# Parent  3d3b602596f8f1904a54f8f1cad88a600644b55e
Match new branch style API

The script doesn't work on post 0.9.2 because of old style branches removal.

Anyway new branch style simplifies thing a bit. It's welcome

diff -r 3d3b602596f8 -r 6c3c7fd48f4d hg-cvs-import
--- a/hg-cvs-import	Sun Dec 17 15:18:38 2006 +0100
+++ b/hg-cvs-import	Sun Dec 17 15:18:38 2006 +0100
@@ -146,7 +146,7 @@ def finish_checkout(f, file):
 
 def addtag(tag, rev):
     global alltags
-    alltags.setdefault(tag, []).append(rev)
+    alltags.setdefault(util.fromlocal(tag), []).append(rev)
 
 def committags(patchset):
     global alltags
@@ -180,36 +180,25 @@ def committags(patchset):
         mapf.write("%d %s\n" % (patchset, hg.hex(repo.changelog.tip())))
 
 def branchlookup(branch):
-    global alltags
-    tags = repo.tags()
-    if branch in savebranch:
-        return ("rev", savebranch[branch])
-    elif branch in tags:
-        return ("branch", branch)
-    elif branch in alltags:
-        return ("rev", alltags[branch][-1])
-    elif branch in ancestorbranches:
-        return branchlookup(ancestorbranches[branch])
-    else:
-        return ("rev", hg.hex(hg.nullid))
-
-def branchhead(branch):
-    br, cache = repo.branchlookup(prune=False)
-    found = []
-    for x in br:
-        if branch in br[x]:
-            found.append(x)
-    if len(found) > 1:
-        sys.stderr.write("Found multiple heads for %s\n" % branch)
-        return None
-    if len(found) == 1:
-        node = repo.changelog.node(found[0])
-        sys.stderr.write("Using head %s for branch %s\n" % (hg.short(node), branch))
-        return hg.hex(node)
-    else:
-        sys.stderr.write("branch %s not found\n" % (branch))
-        raise Abort()
-        return None
+    # XXX: Flush the repo branch cache
+    repo.branchcache = None
+
+    bl = repo.branchtags()
+
+    # See if the branch has a head
+    n = bl.get(branch, None)
+    if n is not None:
+        return hg.hex(n)
+
+    # This seems to be a new branch, link it to the head of the ancestor
+    # branch
+    if branch in ancestorbranches:
+        n = bl.get(ancestorbranches[branch], None)
+    if n is not None:
+        return hg.hex(n)
+
+    # No parent, link it to nullid
+    return hg.hex(hg.nullid)
 
 def addrev(branch, tag, r, user, date, log, files):
     global lastbranch
@@ -225,13 +214,9 @@ def addrev(branch, tag, r, user, date, l
     if branch != lastbranch:
         savebranch[lastbranch] = hg.hex(repo.changelog.tip())
         if r in ancestorpatches:
-            type, v = 'rev', map[int(ancestorpatches[r])]
+            node = map[int(ancestorpatches[r])]
         else:
-            type, v = branchlookup(branch)
-        if type == "branch":
-            node = branchhead(v)
-        else:
-            node = v
+            node = branchlookup(branch)
         if node == None:
             u.warn("Unable to find parent rev for %s\n" % branch)
             mapf.close()
@@ -266,22 +251,16 @@ def addrev(branch, tag, r, user, date, l
             log.append("")
         llog = "\n".join(log)
         user = namemap.get(user, user)
+        extra = {'branch': util.fromlocal(branch).strip()}
         repo.rawcommit(filelist, llog, user, dateconv, hg.bin(node),
-                       wlock=wlock)
+                       wlock=wlock, extra=extra)
         n = repo.changelog.tip()
         map[int(r)] = hg.hex(n)
         mapf.write("%d %s\n" % (r, hg.hex(n)))
-        print "added patch %d %s" % (r, hg.hex(n))
+        print "%s: added patch %d %s (%s)" % (branch, r, hg.hex(n), node)
     lastbranch = branch
     lastrev = hg.hex(n)
-    tags = repo.tags()
-    branchdone = False
-    if branch not in tags and branch not in alltags:
-        addtag(branch, hg.hex(n))
-        branchdone = True
     if tag != None:
-        if not branchdone:
-            addtag(branch, hg.hex(n))
         addtag(tag, hg.hex(n))
 
 def readnamemap(filename):


More information about the Mercurial-devel mailing list