Fix traceback when nothing was added during unbundle
authorBenoit Boissinot <benoit.boissinot@ens-lyon.org>
Mon, 03 Oct 2005 14:45:14 -0700
changeset 1375 f2b00be33e2c
parent 1374 c3654cfaa77d
child 1376 524ca4a06f70
Fix traceback when nothing was added during unbundle The changegroup and commit hook are now run only when something is modified. The correct number of changesets added is printed.
mercurial/localrepo.py
--- a/mercurial/localrepo.py	Mon Oct 03 14:43:11 2005 -0700
+++ b/mercurial/localrepo.py	Mon Oct 03 14:45:14 2005 -0700
@@ -992,6 +992,8 @@
         co = self.changelog.tip()
         cn = self.changelog.addgroup(getgroup(), csmap, tr, 1) # unique
         cnr, cor = map(self.changelog.rev, (cn, co))
+        if cn == nullid:
+            cnr = cor
         changesets = cnr - cor
 
         # pull off the manifest group
@@ -1022,12 +1024,14 @@
 
         tr.close()
 
-        if not self.hook("changegroup", node=hex(self.changelog.node(cor+1))):
-            self.ui.warn("abort: changegroup hook returned failure!\n")
-            return 1
+        if changesets > 0:
+            if not self.hook("changegroup",
+                              node=hex(self.changelog.node(cor+1))):
+                self.ui.warn("abort: changegroup hook returned failure!\n")
+                return 1
 
-        for i in range(cor + 1, cnr + 1):
-            self.hook("commit", node=hex(self.changelog.node(i)))
+            for i in range(cor + 1, cnr + 1):
+                self.hook("commit", node=hex(self.changelog.node(i)))
 
         return