Patchwork [1,of,6,V3] branchmap: read and write key part related to filtered revision

login
register
mail settings
Submitter Pierre-Yves David
Date Jan. 1, 2013, 10:14 p.m.
Message ID <d5a9f27529d3f7c6fdf3.1357078479@yamac.lan>
Download mbox | patch
Permalink /patch/340/
State Accepted
Commit 8d48af68e2ae780950479e5a65cda5a4c0730a09
Headers show

Comments

Pierre-Yves David - Jan. 1, 2013, 10:14 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at logilab.fr>
# Date 1357060764 -3600
# Node ID d5a9f27529d3f7c6fdf3e927847b82f29c888573
# Parent  9916d104c485e744dad50d63398d540f429e0caa
branchmap: read and write key part related to filtered revision

Now that we have a third part for the cache key we need to write and read it on
disk. It is only written when there is filtered revision. This keep the format
compatible with older version.

Notes that, at this state, filtered repository does not use any disk caches yet.
Augie Fackler - Jan. 1, 2013, 11:35 p.m.
queued the whole series. thanks for your patience.

On Jan 1, 2013, at 5:14 PM, Pierre-Yves David <pierre-yves.david at ens-lyon.org> wrote:

> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david at logilab.fr>
> # Date 1357060764 -3600
> # Node ID d5a9f27529d3f7c6fdf3e927847b82f29c888573
> # Parent  9916d104c485e744dad50d63398d540f429e0caa
> branchmap: read and write key part related to filtered revision
> 
> Now that we have a third part for the cache key we need to write and read it on
> disk. It is only written when there is filtered revision. This keep the format
> compatible with older version.
> 
> Notes that, at this state, filtered repository does not use any disk caches yet.
> 
> diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py
> --- a/mercurial/branchmap.py
> +++ b/mercurial/branchmap.py
> @@ -16,13 +16,18 @@ def read(repo):
>         f.close()
>     except (IOError, OSError):
>         return branchcache()
> 
>     try:
> -        last, lrev = lines.pop(0).split(" ", 1)
> +        cachekey = lines.pop(0).split(" ", 2)
> +        last, lrev = cachekey[:2]
>         last, lrev = bin(last), int(lrev)
> -        partial = branchcache(tipnode=last, tiprev=lrev)
> +        filteredhash = None
> +        if len(cachekey) > 2:
> +            filteredhash = bin(cachekey[2])
> +        partial = branchcache(tipnode=last, tiprev=lrev,
> +                              filteredhash=filteredhash)
>         if not partial.validfor(repo):
>             # invalidate the cache
>             raise ValueError('tip differs')
>         for l in lines:
>             if not l:
> @@ -111,11 +116,14 @@ class branchcache(dict):
> 
> 
>     def write(self, repo):
>         try:
>             f = repo.opener("cache/branchheads", "w", atomictemp=True)
> -            f.write("%s %s\n" % (hex(self.tipnode), self.tiprev))
> +            cachekey = [hex(self.tipnode), str(self.tiprev)]
> +            if self.filteredhash is not None:
> +                cachekey.append(hex(self.filteredhash))
> +            f.write(" ".join(cachekey) + '\n')
>             for label, nodes in self.iteritems():
>                 for node in nodes:
>                     f.write("%s %s\n" % (hex(node), encoding.fromlocal(label)))
>             f.close()
>         except (IOError, OSError):

Patch

diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py
--- a/mercurial/branchmap.py
+++ b/mercurial/branchmap.py
@@ -16,13 +16,18 @@  def read(repo):
         f.close()
     except (IOError, OSError):
         return branchcache()
 
     try:
-        last, lrev = lines.pop(0).split(" ", 1)
+        cachekey = lines.pop(0).split(" ", 2)
+        last, lrev = cachekey[:2]
         last, lrev = bin(last), int(lrev)
-        partial = branchcache(tipnode=last, tiprev=lrev)
+        filteredhash = None
+        if len(cachekey) > 2:
+            filteredhash = bin(cachekey[2])
+        partial = branchcache(tipnode=last, tiprev=lrev,
+                              filteredhash=filteredhash)
         if not partial.validfor(repo):
             # invalidate the cache
             raise ValueError('tip differs')
         for l in lines:
             if not l:
@@ -111,11 +116,14 @@  class branchcache(dict):
 
 
     def write(self, repo):
         try:
             f = repo.opener("cache/branchheads", "w", atomictemp=True)
-            f.write("%s %s\n" % (hex(self.tipnode), self.tiprev))
+            cachekey = [hex(self.tipnode), str(self.tiprev)]
+            if self.filteredhash is not None:
+                cachekey.append(hex(self.filteredhash))
+            f.write(" ".join(cachekey) + '\n')
             for label, nodes in self.iteritems():
                 for node in nodes:
                     f.write("%s %s\n" % (hex(node), encoding.fromlocal(label)))
             f.close()
         except (IOError, OSError):