Patchwork [2,of,4,censor,RFC] revlog: add "iscensored()" to revlog public API

login
register
mail settings
Submitter adgar@google.com
Date Feb. 6, 2015, 3:57 a.m.
Message ID <75e6aa3db49612a96fe7.1423195068@adgar.nyc.corp.google.com>
Download mbox | patch
Permalink /patch/7707/
State Accepted
Headers show

Comments

adgar@google.com - Feb. 6, 2015, 3:57 a.m.
# HG changeset patch
# User Mike Edgar <adgar@google.com>
# Date 1422050499 18000
#      Fri Jan 23 17:01:39 2015 -0500
# Node ID 75e6aa3db49612a96fe768e16fd17c22f0a21ce9
# Parent  e24ad0a4a1d819c4d79799b5a453987ea88e1b9e
revlog: add "iscensored()" to revlog public API

The iscensored method will be used by the exchange layer to reject
nonconforming deltas involving censored revisions (and to produce
conforming deltas).

For background and broader design of the censorship feature, see:
http://mercurial.selenic.com/wiki/CensorPlan

Patch

diff -r e24ad0a4a1d8 -r 75e6aa3db496 mercurial/filelog.py
--- a/mercurial/filelog.py	Fri Feb 06 01:44:24 2015 +0000
+++ b/mercurial/filelog.py	Fri Jan 23 17:01:39 2015 -0500
@@ -64,7 +64,7 @@ 
         node = self.node(rev)
         if self.renamed(node):
             return len(self.read(node))
-        if self._iscensored(rev):
+        if self.iscensored(rev):
             return 0
 
         # XXX if self.read(node).startswith("\1\n"), this returns (size+4)
@@ -85,7 +85,7 @@ 
             return False
 
         # censored files compare against the empty file
-        if self._iscensored(self.rev(node)):
+        if self.iscensored(self.rev(node)):
             return text != ''
 
         # renaming a file produces a different hash, even if the data
@@ -104,9 +104,9 @@ 
                 raise error.CensoredNodeError(self.indexfile, node)
             raise
 
+    def iscensored(self, rev):
+        """Check if a file revision is censored."""
+        return self.flags(rev) & revlog.REVIDX_ISCENSORED
+
     def _file(self, f):
         return filelog(self.opener, f)
-
-    def _iscensored(self, rev):
-        """Check if a file revision is censored."""
-        return self.flags(rev) & revlog.REVIDX_ISCENSORED
diff -r e24ad0a4a1d8 -r 75e6aa3db496 mercurial/revlog.py
--- a/mercurial/revlog.py	Fri Feb 06 01:44:24 2015 +0000
+++ b/mercurial/revlog.py	Fri Jan 23 17:01:39 2015 -0500
@@ -1417,6 +1417,10 @@ 
 
         return content
 
+    def iscensored(self, rev):
+        """Check if a file revision is censored."""
+        return False
+
     def getstrippoint(self, minlink):
         """find the minimum rev that must be stripped to strip the linkrev
 
diff -r e24ad0a4a1d8 -r 75e6aa3db496 mercurial/unionrepo.py
--- a/mercurial/unionrepo.py	Fri Feb 06 01:44:24 2015 +0000
+++ b/mercurial/unionrepo.py	Fri Jan 23 17:01:39 2015 -0500
@@ -163,6 +163,12 @@ 
     def _file(self, f):
         self._repo.file(f)
 
+    def iscensored(self, rev):
+        """Check if a revision is censored."""
+        if rev <= self.repotiprev:
+            return filelog.filelog.iscensored(self, rev)
+        return self.revlog2.iscensored(rev)
+
 class unionpeer(localrepo.localpeer):
     def canpush(self):
         return False