Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/merge.py @ 23971:6becb9dbca25 stable
merge: mark .hgsubstate as possibly dirty before submerge for consistency
Before this patch, failure of updating subrepos may cause inconsistent
".hgsubstate". For example:
1. dirstate entry for ".hgsubstate" of the parent repo is filled
with valid size/date (via "hg state" or so)
2. "hg update" is invoked at the parent repo
3. ".hgsubstate" of the parent repo is updated on the filesystem as
a part of "g"(et) action in "merge.applyupdates"
4. it is assumed that size/date of ".hgsubstate" on the filesystem
aren't changed from ones at (1)
this is not so difficult condition, because just changing hash
ids (every ids are same in length) in ".hgsubstate" doesn't
change the file size of it
5. "subrepo.submerge()" is invoked to update subrepos
6. failure of updating in one of subrepos raises exception
(e.g. "untracked file differs")
7. "hg update" is aborted without updating dirstate of the parent repo
dirstate entry for ".hgsubstate" still holds size/date at (1)
Then, ".hgsubstate" of the parent repo is treated as "CLEAN"
unexpectedly, because updating ".hgsubstate" at (3) doesn't change
size/date of it on the filesystem: see assumption at (4).
This inconsistent ".hgsubstate" status causes unexpected behavior, for
example:
- "hg revert" forgets to revert ".hgsubstate"
- "hg update" misunderstands that (not yet updated) subrepos diverge
(then, it shows the prompt to confirm user's decision)
To avoid inconsistent ".hgsubstate" status above, this patch marks
".hgsubstate" as possibly dirty before "submerge" invocation.
"normallookup"-ed (= dirty) dirstate should be written out, even if
processing is aborted by failure.
This patch marks ".hgsubstate" as possibly dirty before "submerge",
also when it is removed or merged while merging, for safety. This
should prevent Mercurial from misunderstanding inconsistent
".hgsubstate" as clean.
To satisfy conditions at (1) and (4) above, this patch uses "hg status
--config debug.dirstate.delaywrite=2" (to fill valid size/date into
dirstate) and "touch" (to fix date of the file).
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Fri, 30 Jan 2015 04:59:05 +0900 |
parents | b88278a308c6 |
children | 1ff35d76421c |
comparison
equal
deleted
inserted
replaced
23970:8a544fb645bb | 23971:6becb9dbca25 |
---|---|
739 audit(f) | 739 audit(f) |
740 util.unlinkpath(repo.wjoin(f)) | 740 util.unlinkpath(repo.wjoin(f)) |
741 | 741 |
742 numupdates = sum(len(l) for m, l in actions.items() if m != 'k') | 742 numupdates = sum(len(l) for m, l in actions.items() if m != 'k') |
743 | 743 |
744 def dirtysubstate(): | |
745 # mark '.hgsubstate' as possibly dirty forcibly, because | |
746 # modified '.hgsubstate' is misunderstood as clean, | |
747 # when both st_size/st_mtime of '.hgsubstate' aren't changed, | |
748 # even if "submerge" fails and '.hgsubstate' is inconsistent | |
749 repo.dirstate.normallookup('.hgsubstate') | |
750 | |
744 if [a for a in actions['r'] if a[0] == '.hgsubstate']: | 751 if [a for a in actions['r'] if a[0] == '.hgsubstate']: |
752 dirtysubstate() | |
745 subrepo.submerge(repo, wctx, mctx, wctx, overwrite) | 753 subrepo.submerge(repo, wctx, mctx, wctx, overwrite) |
746 | 754 |
747 # remove in parallel (must come first) | 755 # remove in parallel (must come first) |
748 z = 0 | 756 z = 0 |
749 prog = worker.worker(repo.ui, 0.001, batchremove, (repo,), actions['r']) | 757 prog = worker.worker(repo.ui, 0.001, batchremove, (repo,), actions['r']) |
758 z += i | 766 z += i |
759 progress(_updating, z, item=item, total=numupdates, unit=_files) | 767 progress(_updating, z, item=item, total=numupdates, unit=_files) |
760 updated = len(actions['g']) | 768 updated = len(actions['g']) |
761 | 769 |
762 if [a for a in actions['g'] if a[0] == '.hgsubstate']: | 770 if [a for a in actions['g'] if a[0] == '.hgsubstate']: |
771 dirtysubstate() | |
763 subrepo.submerge(repo, wctx, mctx, wctx, overwrite) | 772 subrepo.submerge(repo, wctx, mctx, wctx, overwrite) |
764 | 773 |
765 # forget (manifest only, just log it) (must come first) | 774 # forget (manifest only, just log it) (must come first) |
766 for f, args, msg in actions['f']: | 775 for f, args, msg in actions['f']: |
767 repo.ui.debug(" %s: %s -> f\n" % (f, msg)) | 776 repo.ui.debug(" %s: %s -> f\n" % (f, msg)) |
783 for f, args, msg in actions['m']: | 792 for f, args, msg in actions['m']: |
784 repo.ui.debug(" %s: %s -> m\n" % (f, msg)) | 793 repo.ui.debug(" %s: %s -> m\n" % (f, msg)) |
785 z += 1 | 794 z += 1 |
786 progress(_updating, z, item=f, total=numupdates, unit=_files) | 795 progress(_updating, z, item=f, total=numupdates, unit=_files) |
787 if f == '.hgsubstate': # subrepo states need updating | 796 if f == '.hgsubstate': # subrepo states need updating |
797 dirtysubstate() | |
788 subrepo.submerge(repo, wctx, mctx, wctx.ancestor(mctx), | 798 subrepo.submerge(repo, wctx, mctx, wctx.ancestor(mctx), |
789 overwrite) | 799 overwrite) |
790 continue | 800 continue |
791 audit(f) | 801 audit(f) |
792 r = ms.resolve(f, wctx, labels=labels) | 802 r = ms.resolve(f, wctx, labels=labels) |