Patchwork D6023: branchcache: move loading of branch names and nodes into it's own function

login
register
mail settings
Submitter phabricator
Date Feb. 25, 2019, 6:21 p.m.
Message ID <cab65040267978c9dbe58175bd56ea4e@localhost.localdomain>
Download mbox | patch
Permalink /patch/38930/
State Not Applicable
Headers show

Comments

phabricator - Feb. 25, 2019, 6:21 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG68bbcc70e274: branchcache: move loading of branch names and nodes into it&#039;s own function (authored by pulkit, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6023?vs=14234&id=14238

REVISION DETAIL
  https://phab.mercurial-scm.org/D6023

AFFECTED FILES
  mercurial/branchmap.py

CHANGE DETAILS




To: pulkit, #hg-reviewers, lothiraldan
Cc: lothiraldan, mercurial-devel
Yuya Nishihara - Feb. 25, 2019, 10:56 p.m.
>              if not bcache.validfor(repo):
>                  # invalidate the cache
>                  raise ValueError(r'tip differs')
> -            cl = repo.changelog
> -            for line in lineiter:
> -                line = line.rstrip('\n')
> -                if not line:
> -                    continue
> -                node, state, label = line.split(" ", 2)
> -                if state not in 'oc':
> -                    raise ValueError(r'invalid branch state')
> -                label = encoding.tolocal(label.strip())
> -                node = bin(node)
> -                if not cl.hasnode(node):
> -                    raise ValueError(
> -                        r'node %s does not exist' % pycompat.sysstr(hex(node)))
> -                bcache.setdefault(label, []).append(node)
> -                if state == 'c':
> -                    bcache._closednodes.add(node)
> -
> +            bcache.load(repo, f)
>          except (IOError, OSError):
>              return None
>  
> @@ -214,6 +198,26 @@
>  
>          return bcache
>  
> +    def load(self, repo, f):
> +        """ fully loads the branchcache by reading from the file f """
> +        cl = repo.changelog
> +        lineiter = iter(f)

Breaks test-static-http.t probably because `f` is read twice through
different iterators.
phabricator - Feb. 25, 2019, 10:58 p.m.
yuja added a comment.


  >   if not bcache.validfor(repo):
  >       # invalidate the cache
  >       raise ValueError(r'tip differs')
  > 
  > - cl = repo.changelog
  > - for line in lineiter:
  > - line = line.rstrip('\n')
  > - if not line:
  > - continue
  > - node, state, label = line.split(" ", 2)
  > - if state not in 'oc':
  > - raise ValueError(r'invalid branch state')
  > - label = encoding.tolocal(label.strip())
  > - node = bin(node)
  > - if not cl.hasnode(node):
  > - raise ValueError(
  > - r'node %s does not exist' % pycompat.sysstr(hex(node)))
  > - bcache.setdefault(label, []).append(node)
  > - if state == 'c':
  > - bcache._closednodes.add(node) - +            bcache.load(repo, f) except (IOError, OSError): return None
  > 
  >   @@ -214,6 +198,26 @@
  > 
  >   return bcache
  > 
  >   +    def load(self, repo, f): +        """ fully loads the branchcache by reading from the file f """ +        cl = repo.changelog +        lineiter = iter(f)
  
  Breaks test-static-http.t probably because `f` is read twice through
  different iterators.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D6023

To: pulkit, #hg-reviewers, lothiraldan
Cc: yuja, lothiraldan, mercurial-devel

Patch

diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py
--- a/mercurial/branchmap.py
+++ b/mercurial/branchmap.py
@@ -179,23 +179,7 @@ 
             if not bcache.validfor(repo):
                 # invalidate the cache
                 raise ValueError(r'tip differs')
-            cl = repo.changelog
-            for line in lineiter:
-                line = line.rstrip('\n')
-                if not line:
-                    continue
-                node, state, label = line.split(" ", 2)
-                if state not in 'oc':
-                    raise ValueError(r'invalid branch state')
-                label = encoding.tolocal(label.strip())
-                node = bin(node)
-                if not cl.hasnode(node):
-                    raise ValueError(
-                        r'node %s does not exist' % pycompat.sysstr(hex(node)))
-                bcache.setdefault(label, []).append(node)
-                if state == 'c':
-                    bcache._closednodes.add(node)
-
+            bcache.load(repo, f)
         except (IOError, OSError):
             return None
 
@@ -214,6 +198,26 @@ 
 
         return bcache
 
+    def load(self, repo, f):
+        """ fully loads the branchcache by reading from the file f """
+        cl = repo.changelog
+        lineiter = iter(f)
+        for line in lineiter:
+            line = line.rstrip('\n')
+            if not line:
+                continue
+            node, state, label = line.split(" ", 2)
+            if state not in 'oc':
+                raise ValueError(r'invalid branch state')
+            label = encoding.tolocal(label.strip())
+            node = bin(node)
+            if not cl.hasnode(node):
+                raise ValueError(
+                    r'node %s does not exist' % pycompat.sysstr(hex(node)))
+            self.setdefault(label, []).append(node)
+            if state == 'c':
+                self._closednodes.add(node)
+
     @staticmethod
     def _filename(repo):
         """name of a branchcache file for a given repo or repoview"""