Patchwork [3,of,5] memctx: add _manifest implementation that computes the filenode

login
register
mail settings
Submitter Sean Farley
Date June 13, 2014, 11:56 p.m.
Message ID <8bc35c83920f4a20a1de.1402703764@laptop.local>
Download mbox | patch
Permalink /patch/5003/
State Accepted
Headers show

Comments

Sean Farley - June 13, 2014, 11:56 p.m.
# HG changeset patch
# User Sean Farley <sean.michael.farley@gmail.com>
# Date 1401397979 18000
#      Thu May 29 16:12:59 2014 -0500
# Node ID 8bc35c83920f4a20a1de3e020662d73fa949c0a3
# Parent  2c35a9d4b14a62fa13cc2f3a06a4a729a90ed85f
memctx: add _manifest implementation that computes the filenode

This is an initial implementation of having a manifest for memctx that computes
the hash in the same way that filenodes are computed elsewhere.
Sean Farley - June 19, 2014, 4:19 a.m.
Sean Farley writes:

> # HG changeset patch
> # User Sean Farley <sean.michael.farley@gmail.com>
> # Date 1401397979 18000
> #      Thu May 29 16:12:59 2014 -0500
> # Node ID 8bc35c83920f4a20a1de3e020662d73fa949c0a3
> # Parent  2c35a9d4b14a62fa13cc2f3a06a4a729a90ed85f
> memctx: add _manifest implementation that computes the filenode
>
> This is an initial implementation of having a manifest for memctx that computes
> the hash in the same way that filenodes are computed elsewhere.
>
> diff --git a/mercurial/context.py b/mercurial/context.py
> --- a/mercurial/context.py
> +++ b/mercurial/context.py
> @@ -11,10 +11,11 @@ import mdiff, error, util, scmutil, subr
>  import match as matchmod
>  import os, errno, stat
>  import obsolete as obsmod
>  import repoview
>  import fileset
> +import revlog
>  
>  propertycache = util.propertycache
>  
>  class basectx(object):
>      """A basectx object represents the common logic for its children:
> @@ -1585,10 +1586,31 @@ class memctx(committablectx):
>  
>      def commit(self):
>          """commit context to the repo"""
>          return self._repo.commitctx(self)
>  
> +    @propertycache
> +    def _manifest(self):
> +        """generate a manifest based on the return values of filectxfn"""
> +
> +        # keep this simple for now; just worry about p1
> +        pctx = self._parents[0]
> +        man = pctx.manifest().copy()
> +
> +        for f, fnode in man.iteritems():

Perhaps this should be 'for f in self.files()' since 'files' is required
to be sent into the constructor?

Patch

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -11,10 +11,11 @@  import mdiff, error, util, scmutil, subr
 import match as matchmod
 import os, errno, stat
 import obsolete as obsmod
 import repoview
 import fileset
+import revlog
 
 propertycache = util.propertycache
 
 class basectx(object):
     """A basectx object represents the common logic for its children:
@@ -1585,10 +1586,31 @@  class memctx(committablectx):
 
     def commit(self):
         """commit context to the repo"""
         return self._repo.commitctx(self)
 
+    @propertycache
+    def _manifest(self):
+        """generate a manifest based on the return values of filectxfn"""
+
+        # keep this simple for now; just worry about p1
+        pctx = self._parents[0]
+        man = pctx.manifest().copy()
+
+        for f, fnode in man.iteritems():
+            p1node = nullid
+            p2node = nullid
+            p = pctx[f].parents()
+            if len(p) > 0:
+                p1node = p[0].node()
+                if len(p) > 1:
+                    p2node = p[1].node()
+            man[f] = revlog.hash(self[f].data(), p1node, p2node)
+
+        return man
+
+
 class memfilectx(committablefilectx):
     """memfilectx represents an in-memory file to commit.
 
     See memctx and commitablefilectx for more details.
     """