Patchwork [2,of,9,RFC] localrepo: add a helper method for creating a marker

login
register
mail settings
Submitter Sean Farley
Date March 30, 2014, 11:09 p.m.
Message ID <a3a201495fe43a7c89b9.1396220940@laptop.local>
Download mbox | patch
Permalink /patch/4149/
State Deferred
Headers show

Comments

Sean Farley - March 30, 2014, 11:09 p.m.
# HG changeset patch
# User Sean Farley <sean.michael.farley@gmail.com>
# Date 1396217998 18000
#      Sun Mar 30 17:19:58 2014 -0500
# Node ID a3a201495fe43a7c89b913680da8b2adc03cb650
# Parent  bd7ad5e093455aefd73e1c66ad1ea260eb3051a3
localrepo: add a helper method for creating a marker
Sean Farley - March 31, 2014, 2:03 p.m.
Martin Geisler <martin@geisler.net> writes:

> Sean Farley <sean.michael.farley@gmail.com> writes:
>
>> # HG changeset patch
>> # User Sean Farley <sean.michael.farley@gmail.com>
>> # Date 1396217998 18000
>> #      Sun Mar 30 17:19:58 2014 -0500
>> # Node ID a3a201495fe43a7c89b913680da8b2adc03cb650
>> # Parent  bd7ad5e093455aefd73e1c66ad1ea260eb3051a3
>> localrepo: add a helper method for creating a marker
>>
>> diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
>> --- a/mercurial/localrepo.py
>> +++ b/mercurial/localrepo.py
>> @@ -655,10 +655,18 @@ class localrepository(object):
>>          for bookmark, n in self._bookmarks.iteritems():
>>              if n == node:
>>                  marks.append(bookmark)
>>          return sorted(marks)
>>  
>> +    def _createmarkernamespace(self, namespace):
>> +        '''Function to create a dictionary entry for namespace. Exists to avoid code
>> +        duplication.
>> +        '''
>> +        if namespace not in self._markers:
>> +            # ensure a blank dictionary exists
>> +            self._markers[namespace] = {}
>
> I think you could let self._markers be a collections.defaultdict and
> avoid this method completely.

Actually, in patch 7 of this series I use this if-block to create a
templatekw for the marker, so defaultdict wouldn't be helpful here. I
admit I did use defaultdict at first, though, but later changed it since
I needed to do fancier things.

Patch

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -655,10 +655,18 @@  class localrepository(object):
         for bookmark, n in self._bookmarks.iteritems():
             if n == node:
                 marks.append(bookmark)
         return sorted(marks)
 
+    def _createmarkernamespace(self, namespace):
+        '''Function to create a dictionary entry for namespace. Exists to avoid code
+        duplication.
+        '''
+        if namespace not in self._markers:
+            # ensure a blank dictionary exists
+            self._markers[namespace] = {}
+
     def branchmap(self):
         '''returns a dictionary {branch: [branchheads]} with branchheads
         ordered by increasing revision number'''
         branchmap.updatecache(self)
         return self._branchcaches[self.filtername]