Patchwork [3,of,8] largefiles: restore standins according to restored dirstate

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Aug. 24, 2014, 2:54 p.m.
Message ID <8058bff50a4fe9a76331.1408892089@feefifofum>
Download mbox | patch
Permalink /patch/5567/
State Accepted
Headers show

Comments

Katsunori FUJIWARA - Aug. 24, 2014, 2:54 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1408891645 -32400
#      Sun Aug 24 23:47:25 2014 +0900
# Node ID 8058bff50a4fe9a763317d9bb5c96bba11593783
# Parent  2ced8eedb543131596d13ceb3a47d84f60538c3d
largefiles: restore standins according to restored dirstate

Before this patch, standins are restored from the NEW parent of the
working directory at "hg rollback", and this causes:

  - standinds removed in the rollback-ed revision are restored, and
    become orphan, because they are already marked as "R" in the
    restored dirstate and expected to be unlinked

  - standins added in the rollback-ed revision are left as they are
    before rollback, because they are not included in the new parent
    (this may not be so serious)

This patch replaces "merge.update" invocatino with specific
implementation, to restore standins according to restored dirstate.

This is also the preparation to centralize the logic of updating
largefiles into the function wrapping "merge.update" in the subsequent
patch.

After that patch, "merge.update" will udpate also largefiles in the
working directory and be redundant for restoring standins only.

Patch

diff --git a/hgext/largefiles/overrides.py b/hgext/largefiles/overrides.py
--- a/hgext/largefiles/overrides.py
+++ b/hgext/largefiles/overrides.py
@@ -12,7 +12,7 @@ 
 import copy
 
 from mercurial import hg, commands, util, cmdutil, scmutil, match as match_, \
-        archival, merge, pathutil, revset
+        archival, pathutil, revset
 from mercurial.i18n import _
 from mercurial.node import hex
 from hgext import rebase
@@ -1202,8 +1202,18 @@ 
         if before == after:
             return result # no need to restore standins
 
-        merge.update(repo, node='.', branchmerge=False, force=True,
-                     partial=lfutil.isstandin)
+        pctx = repo['.']
+        for f in repo.dirstate:
+            if lfutil.isstandin(f):
+                if repo.dirstate[f] == 'r':
+                    repo.wvfs.unlinkpath(f, ignoremissing=True)
+                elif f in pctx:
+                    fctx = pctx[f]
+                    repo.wwrite(f, fctx.data(), fctx.flags())
+                else:
+                    # content of standin is not so important in 'a',
+                    # 'm' or 'n' (coming from the 2nd parent) cases
+                    lfutil.writestandin(repo, f, '', False)
 
         lfdirstate = lfutil.openlfdirstate(ui, repo)
         orphans = set(lfdirstate)
diff --git a/tests/test-largefiles-update.t b/tests/test-largefiles-update.t
--- a/tests/test-largefiles-update.t
+++ b/tests/test-largefiles-update.t
@@ -103,9 +103,15 @@ 
 
   $ hg update -C -q
   $ hg remove large1
+  $ test -f .hglf/large1
+  [1]
   $ hg forget large2
+  $ test -f .hglf/large2
+  [1]
   $ echo largeX > largeX
   $ hg add --large largeX
+  $ cat .hglf/largeX
+  
   $ hg commit -m 'will be rollback-ed soon'
   $ echo largeY > largeY
   $ hg add --large largeY
@@ -122,10 +128,16 @@ 
   working directory now based on revision 3
   $ hg status -A large1
   R large1
+  $ test -f .hglf/large1
+  [1]
   $ hg status -A large2
   R large2
+  $ test -f .hglf/large2
+  [1]
   $ hg status -A largeX
   A largeX
+  $ cat .hglf/largeX
+  
   $ hg status -A largeY
   ? largeY