[PATCH] changegroup: do not prompt to merge after adding only closed heads (issue2697)

Adrian Buehlmann adrian at cadifra.com
Sun Apr 24 18:33:48 CDT 2011


On 2011-04-14 21:34, Matt Mackall wrote:
> On Thu, 2011-04-14 at 14:31 -0400, Kevin Gessner wrote:
>> # HG changeset patch
>> # User Kevin Gessner <kevin at fogcreek.com>
>> # Date 1302729493 14400
>> # Node ID 9afc365d6c2a351d01d6ae18021fc67c45ceb139
>> # Parent  3d83c7d70a98a1fd4ff1ad4f840c8ce82100bfdb
>> changegroup: do not prompt to merge after adding only closed heads (issue2697)
>>
>> When adding a changegroup adds closed heads, note them in the "(+n heads)"
>> alert. Don't count them in the total number of heads for the note to merge
>> or update.
>>
>> diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
>> --- a/mercurial/localrepo.py
>> +++ b/mercurial/localrepo.py
>> @@ -1691,6 +1691,8 @@
>>          cl = self.changelog
>>          cl.delayupdate()
>>          oldheads = len(cl.heads())
>> +        oldclosedheads = len([h for h in cl.heads()
>> +                              if 'close' in self[h].extra()])
> 
> This doesn't look very efficient. What happens if you've got 1000 heads?
> 
> Can't we simply look at whether any of the new heads are closed?
> 
>>          tr = self.transaction("\n".join([srctype, urlmod.hidepassword(url)]))
>>          try:
>> @@ -1782,9 +1784,18 @@
>>                              (f, hex(n)))
>>  
>>              newheads = len(cl.heads())
>> +            newclosedheads = len([h for h in cl.heads()
>> +                                  if 'close' in self[h].extra()])
>> +            closingheads = max(0, newclosedheads - oldclosedheads)
>>              heads = ""
>>              if oldheads and newheads != oldheads:
>> -                heads = _(" (%+d heads)") % (newheads - oldheads)
>> +                closedheads = ""
>> +                if closingheads:
>> +                    closedheads = _(", %d closed") % closingheads
>> +                heads = _(" (%+d heads%s)") % ((newheads - oldheads),
>> +                                               closedheads)
>> +            oldheads -= oldclosedheads
>> +            newheads -= newclosedheads
>>  
>>              self.ui.status(_("added %d changesets"
>>                               " with %d changes to %d files%s\n")

This passes the testsuite:

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1690,7 +1690,7 @@
         # inconsistent view
         cl = self.changelog
         cl.delayupdate()
-        oldheads = len(cl.heads())
+        oldheads = cl.heads()
 
         tr = self.transaction("\n".join([srctype, urlmod.hidepassword(url)]))
         try:
@@ -1781,14 +1781,20 @@
                             _('missing file data for %s:%s - run hg verify') %
                             (f, hex(n)))
 
-            newheads = len(cl.heads())
-            heads = ""
-            if oldheads and newheads != oldheads:
-                heads = _(" (%+d heads)") % (newheads - oldheads)
+            dh = 0
+            if oldheads:
+                heads = cl.heads()
+                dh = len(heads) - len(oldheads)
+                for h in heads:
+                    if h not in oldheads and 'close' in self[h].extra():
+                        dh -= 1
+            htext = ""
+            if dh:
+                htext = _(" (%+d heads)") % dh
 
             self.ui.status(_("added %d changesets"
                              " with %d changes to %d files%s\n")
-                             % (changesets, revisions, files, heads))
+                             % (changesets, revisions, files, htext))
 
             if changesets > 0:
                 p = lambda: cl.writepending() and self.root or ""
@@ -1817,11 +1823,10 @@
                           source=srctype, url=url)
 
         # never return 0 here:
-        if newheads < oldheads:
-            return newheads - oldheads - 1
+        if dh < 0:
+            return dh - 1
         else:
-            return newheads - oldheads + 1
-
+            return dh + 1
 
     def stream_in(self, remote, requirements):
         lock = self.lock()


More information about the Mercurial-devel mailing list