Patchwork [12,of,21,RFC] filelog: censored files compare equal to empty files, have size of 0

login
register
mail settings
Submitter michaeljedgar@gmail.com
Date Sept. 11, 2014, 12:26 a.m.
Message ID <c81c9a42fb6f1b2f402e.1410395173@adgar-macbookpro3.roam.corp.google.com>
Download mbox | patch
Permalink /patch/5787/
State Changes Requested
Headers show

Comments

michaeljedgar@gmail.com - Sept. 11, 2014, 12:26 a.m.
# HG changeset patch
# User Mike Edgar <adgar@google.com>
# Date 1410322674 14400
#      Wed Sep 10 00:17:54 2014 -0400
# Node ID c81c9a42fb6f1b2f402e4e6607fe2a531469b08e
# Parent  00627d21f79b34b2d0fc95e295047ed4feebbcd7
filelog: censored files compare equal to empty files, have size of 0

This change makes `hg status` correctly show censored files as clean when they
are empty in the working directory.
Durham Goode - Sept. 11, 2014, 1:40 a.m.
On 9/10/14, 5:26 PM, michaeljedgar@gmail.com wrote:
> # HG changeset patch
> # User Mike Edgar <adgar@google.com>
> # Date 1410322674 14400
> #      Wed Sep 10 00:17:54 2014 -0400
> # Node ID c81c9a42fb6f1b2f402e4e6607fe2a531469b08e
> # Parent  00627d21f79b34b2d0fc95e295047ed4feebbcd7
> filelog: censored files compare equal to empty files, have size of 0
>
> This change makes `hg status` correctly show censored files as clean when they
> are empty in the working directory.
>
> diff -r 00627d21f79b -r c81c9a42fb6f mercurial/filelog.py
> --- a/mercurial/filelog.py	Wed Sep 10 16:24:56 2014 -0400
> +++ b/mercurial/filelog.py	Wed Sep 10 00:17:54 2014 -0400
> @@ -57,6 +57,14 @@
>               return (m["copy"], revlog.bin(m["copyrev"]))
>           return False
>   
> +    def censormeta(self, revornode):
> +        """Proactive check for whether a given revision is censored."""
It’s not clear to me what the metadata here is. Might want to change the 
doccomment to explain that. The doccomment also implies that the 
function is boolean (i.e. iscensored), which seems inaccurate.
> +        try:
> +            self.revision(revornode)
> +            return ''
> +        except error.CensoredNodeError, e:
> +            return e.metadata
> +
>       def size(self, rev):
>           """return the size of a given revision"""
>   
> @@ -64,6 +72,8 @@
>           node = self.node(rev)
>           if self.renamed(node):
>               return len(self.read(node))
> +        if self.censormeta(rev):
> +            return 0
>   
>           # XXX if self.read(node).startswith("\1\n"), this returns (size+4)
>           return super(filelog, self).size(rev)
> @@ -82,6 +92,10 @@
>           if samehashes:
>               return False
>   
> +        # censored files compare against the empty file
> +        if self.censormeta(node):
> +            return text != ''
> +
>           # renaming a file produces a different hash, even if the data
>           # remains unchanged. Check if it's the case (slow):
>           if self.renamed(node):
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff -r 00627d21f79b -r c81c9a42fb6f mercurial/filelog.py
--- a/mercurial/filelog.py	Wed Sep 10 16:24:56 2014 -0400
+++ b/mercurial/filelog.py	Wed Sep 10 00:17:54 2014 -0400
@@ -57,6 +57,14 @@ 
             return (m["copy"], revlog.bin(m["copyrev"]))
         return False
 
+    def censormeta(self, revornode):
+        """Proactive check for whether a given revision is censored."""
+        try:
+            self.revision(revornode)
+            return ''
+        except error.CensoredNodeError, e:
+            return e.metadata
+
     def size(self, rev):
         """return the size of a given revision"""
 
@@ -64,6 +72,8 @@ 
         node = self.node(rev)
         if self.renamed(node):
             return len(self.read(node))
+        if self.censormeta(rev):
+            return 0
 
         # XXX if self.read(node).startswith("\1\n"), this returns (size+4)
         return super(filelog, self).size(rev)
@@ -82,6 +92,10 @@ 
         if samehashes:
             return False
 
+        # censored files compare against the empty file
+        if self.censormeta(node):
+            return text != ''
+
         # renaming a file produces a different hash, even if the data
         # remains unchanged. Check if it's the case (slow):
         if self.renamed(node):