D6306: copies: write empty entries in changeset when also writing to filelog

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Sun May 5 01:23:36 EDT 2019


martinvonz updated this revision to Diff 15018.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6306?vs=14900&id=15018

REVISION DETAIL
  https://phab.mercurial-scm.org/D6306

AFFECTED FILES
  mercurial/changelog.py
  mercurial/localrepo.py
  tests/test-copies-in-changeset.t

CHANGE DETAILS

diff --git a/tests/test-copies-in-changeset.t b/tests/test-copies-in-changeset.t
--- a/tests/test-copies-in-changeset.t
+++ b/tests/test-copies-in-changeset.t
@@ -101,6 +101,7 @@
   $ hg changesetcopies
   files: j
   p1copies: j\x00a (esc)
+  p2copies: 
   $ hg debugdata j 0
   \x01 (esc)
   copy: a
@@ -113,6 +114,14 @@
   a -> j
   $ hg showcopies --config experimental.copies.read-from=filelog-only
   a -> j
+The entries should be written to extras even if they're empty (so the client
+won't have to fall back to reading from filelogs)
+  $ echo x >> j
+  $ hg ci -m 'modify j' --config experimental.copies.write-to=compatibility
+  $ hg changesetcopies
+  files: j
+  p1copies: 
+  p2copies: 
 
 Test writing only to filelog
 
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -2564,7 +2564,13 @@
         writecopiesto = self.ui.config('experimental', 'copies.write-to')
         writefilecopymeta = writecopiesto != 'changeset-only'
         p1copies, p2copies = None, None
-        if writecopiesto in ('changeset-only', 'compatibility'):
+        # If writing only to changeset extras, use None to indicate that
+        # no entry should be written. If writing to both, write an empty
+        # entry to prevent the reader from falling back to reading filelogs.
+        if writecopiesto == 'changeset-only':
+            p1copies = ctx.p1copies() or None
+            p2copies = ctx.p2copies() or None
+        elif writecopiesto == 'compatibility':
             p1copies = ctx.p1copies()
             p2copies = ctx.p2copies()
         with self.lock(), self.transaction("commit") as tr:
diff --git a/mercurial/changelog.py b/mercurial/changelog.py
--- a/mercurial/changelog.py
+++ b/mercurial/changelog.py
@@ -591,11 +591,11 @@
             elif branch in (".", "null", "tip"):
                 raise error.StorageError(_('the name \'%s\' is reserved')
                                          % branch)
-        if (p1copies or p2copies) and extra is None:
+        if (p1copies is not None or p2copies is not None) and extra is None:
             extra = {}
-        if p1copies:
+        if p1copies is not None:
             extra['p1copies'] = encodecopies(p1copies)
-        if p2copies:
+        if p2copies is not None:
             extra['p2copies'] = encodecopies(p2copies)
 
         if extra:



To: martinvonz, #hg-reviewers, indygreg
Cc: mercurial-devel


More information about the Mercurial-devel mailing list