[PATCH 07 of 12] Match new branch style API

Edouard Gomez ed.gomez at free.fr
Tue Dec 19 06:05:48 UTC 2006


# HG changeset patch
# User Edouard Gomez <ed.gomez at free.fr>
# Date 1166511815 -3600
# Node ID 22e9a03043477a6c2c3283c2dbc36abf6b8896d5
# Parent  634c6cf8bd1aceb50deb929b88aba7307d262bca
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 634c6cf8bd1a -r 22e9a0304347 hg-cvs-import
--- a/hg-cvs-import	Tue Dec 19 08:03:35 2006 +0100
+++ b/hg-cvs-import	Tue Dec 19 08:03:35 2006 +0100
@@ -147,7 +147,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
@@ -181,36 +181,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
@@ -226,13 +215,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()
@@ -267,22 +252,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