Patchwork [6,of,7,RFC,v2] filelog: censored files compare against empty data, have 0 size

login
register
mail settings
Submitter michaeljedgar@gmail.com
Date Sept. 15, 2014, 12:01 p.m.
Message ID <03684b2891165ba0f662.1410782487@adgar-macbookpro3.roam.corp.google.com>
Download mbox | patch
Permalink /patch/5823/
State Accepted
Headers show

Comments

michaeljedgar@gmail.com - Sept. 15, 2014, 12:01 p.m.
# HG changeset patch
# User Mike Edgar <adgar@google.com>
# Date 1410741154 14400
#      Sun Sep 14 20:32:34 2014 -0400
# Node ID 03684b2891165ba0f6626216a1a6eaed4c502547
# Parent  cb2d62a677e6df6b50df1699e7eea212a82af98d
filelog: censored files compare against empty data, have 0 size

To support "status" operations against working directories that are
the children of censored revisions, filelog must define "cmp" and "size"
for censored content.
Matt Mackall - Oct. 1, 2014, 4:52 p.m.
On Mon, 2014-09-15 at 08:01 -0400, Mike Edgar wrote:
> # HG changeset patch
> # User Mike Edgar <adgar@google.com>
> # Date 1410741154 14400
> #      Sun Sep 14 20:32:34 2014 -0400
> # Node ID 03684b2891165ba0f6626216a1a6eaed4c502547
> # Parent  cb2d62a677e6df6b50df1699e7eea212a82af98d
> filelog: censored files compare against empty data, have 0 size

I've queued 1, 2, and 6 here. But I'm not convinced about the layering
of the policy bits yet. Basically, I think we need to have less
knowledge about censored files at high levels like this, otherwise we'll
end up with special case code everywhere.

I think we should instead have two behaviors when we ask for file
contents:

- abort (default, but hint about the next option)
- quietly treat file as empty

..and have this buried down in the fctx layer (which is the lowest layer
that has access to a ui object).

Before we add in a config file, we should probably first add a master
config switch that just chooses between the above two basic behaviors.
We can add in a policy file as a later step. You've used censor.allow
for this, but it might be better as censor.policy=abort/ignore/file.

And then we get something like:

$ hg update
abort: file censored .config@XXXX!
(use --config censor.policy=ignore to continue)

Also, we probably don't want verify to warn about ancient censored nodes
if policy allows them because it'll distract from real issues.

Patch

diff -r cb2d62a677e6 -r 03684b289116 mercurial/filelog.py
--- a/mercurial/filelog.py	Sun Sep 14 20:30:09 2014 -0400
+++ b/mercurial/filelog.py	Sun Sep 14 20:32:34 2014 -0400
@@ -64,6 +64,8 @@ 
         node = self.node(rev)
         if self.renamed(node):
             return len(self.read(node))
+        if self._iscensored(rev):
+            return 0
 
         # XXX if self.read(node).startswith("\1\n"), this returns (size+4)
         return super(filelog, self).size(rev)
@@ -82,6 +84,10 @@ 
         if samehashes:
             return False
 
+        # censored files compare against the empty file
+        if self._iscensored(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):
@@ -100,3 +106,11 @@ 
 
     def _file(self, f):
         return filelog(self.opener, f)
+
+    def _iscensored(self, revornode):
+        """Check if a file revision is censored."""
+        try:
+            self.revision(revornode)
+            return False
+        except error.CensoredNodeError:
+            return True