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:

  - standins 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 were
    before rollback, because they are not included in the new parent
    (this may not be so serious)

This patch replaces the "merge.update" invocation with a 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 also update largefiles in the
working directory and be redundant for restoring standins only.
This commit is contained in:
FUJIWARA Katsunori 2014-08-24 23:47:25 +09:00
parent 1b49e33c21
commit 4bfc24bc88
2 changed files with 25 additions and 3 deletions

View File

@ -12,7 +12,7 @@ import os
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 @@ def overriderollback(orig, ui, repo, **opts):
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)

View File

@ -103,9 +103,15 @@ Test that "hg rollback" restores status of largefiles correctly
$ 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 @@ Test that "hg rollback" restores status of largefiles correctly
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