localrepo: reorder remove operations so they happen before add

Summary:
The Rust Manifests prevent having both a file and a directory with the same
name. This is a problem for the localrepo commit logic which will first add
the new entry, be that file or directory, and then remove the old one.

Reviewed By: quark-zju

Differential Revision: D16775350

fbshipit-source-id: 4515e42f9d2b1b2bc4861c16a39d291225cddc2a
This commit is contained in:
Stefan Filip 2019-08-26 10:45:58 -07:00 committed by Facebook Github Bot
parent 8a402cc939
commit 4be6f11ab5
6 changed files with 45 additions and 32 deletions

View File

@ -2259,19 +2259,34 @@ class localrepository(object):
# check in files
added = []
changed = []
removed = list(ctx.removed())
removed = []
drop = []
def handleremove(f):
if f in m1 or f in m2:
removed.append(f)
if f in m:
del m[f]
drop.append(f)
for f in ctx.removed():
handleremove(f)
for f in sorted(ctx.modified() + ctx.added()):
if ctx[f] is None:
# in memctx this means removal
handleremove(f)
else:
added.append(f)
linkrev = len(self)
self.ui.note(_("committing files:\n"))
for f in sorted(ctx.modified() + ctx.added()):
for f in added:
self.ui.note(f + "\n")
try:
fctx = ctx[f]
if fctx is None:
removed.append(f)
else:
added.append(f)
m[f] = self._filecommit(fctx, m1, m2, linkrev, trp, changed)
m.setflag(f, fctx.flags())
m[f] = self._filecommit(fctx, m1, m2, linkrev, trp, changed)
m.setflag(f, fctx.flags())
except OSError:
self.ui.warn(_("trouble committing %s!\n") % f)
raise
@ -2283,10 +2298,8 @@ class localrepository(object):
# update manifest
self.ui.note(_("committing manifest\n"))
removed = [f for f in sorted(removed) if f in m1 or f in m2]
drop = [f for f in removed if f in m]
for f in drop:
del m[f]
removed = sorted(removed)
drop = sorted(drop)
if added or drop:
mn = mctx.write(
trp, linkrev, p1.manifestnode(), p2.manifestnode(), added, drop

View File

@ -64,11 +64,11 @@ Convert while testing all possible outputs
progress: scanning paths: /trunk/\xc3\xa0/e\xcc\x81 1/3 paths (33.33%) (esc)
progress: scanning paths: /trunk/\xc3\xa9 2/3 paths (66.67%) (esc)
progress: scanning paths (end)
progress: getting files: \xc3\xa0/e\xcc\x81 1/2 files (50.00%) (esc)
progress: getting files: \xc3\xa9 2/2 files (100.00%) (esc)
committing files:
\xc3\xa0/e\xcc\x81 (esc)
progress: getting files: \xc3\xa0/e\xcc\x81 1/2 files (50.00%) (esc)
\xc3\xa9 (esc)
progress: getting files: \xc3\xa9 2/2 files (100.00%) (esc)
committing manifest
committing changelog
progress: getting files (end)
@ -90,12 +90,12 @@ Convert while testing all possible outputs
progress: scanning paths (end)
progress: getting files: \xc3\xa0/e\xcc\x81 1/4 files (25.00%) (esc)
progress: getting files: \xc3\xa9 2/4 files (50.00%) (esc)
progress: getting files: \xc3\xa8 3/4 files (75.00%) (esc)
progress: getting files: \xc3\xb9/e\xcc\x81 4/4 files (100.00%) (esc)
committing files:
\xc3\xa8 (esc)
progress: getting files: \xc3\xa8 3/4 files (75.00%) (esc)
\xc3\xa8: copy \xc3\xa9:6b67ccefd5ce6de77e7ead4f5292843a0255329f (esc)
\xc3\xb9/e\xcc\x81 (esc)
progress: getting files: \xc3\xb9/e\xcc\x81 4/4 files (100.00%) (esc)
\xc3\xb9/e\xcc\x81: copy \xc3\xa0/e\xcc\x81:a9092a3d84a37b9993b5c73576f6de29b7ea50f6 (esc)
committing manifest
committing changelog

View File

@ -52,11 +52,11 @@ Sync Commit
loading changelist numbers.
2 changelists to import.
importing CL1
file: //depot/Main/a, src: * (glob)
file: //depot/Main/largefile, src: * (glob)
committing files:
Main/a
file: //depot/Main/a, src: * (glob)
Main/largefile
file: //depot/Main/largefile, src: * (glob)
committing manifest
committing changelog
largefile: Main/largefile, oid: 37a7b43abd9e105a0e6b22088b140735a02f288767fe7a6f4f436cb46b064ca9
@ -94,11 +94,11 @@ Sync Commit
latest change list number 3
2 added files
0 removed files
file: //depot/Outside/anotherlargefile, src: * (glob)
file: //depot/Outside/b, src: * (glob)
committing files:
Outside/anotherlargefile
file: //depot/Outside/anotherlargefile, src: * (glob)
Outside/b
file: //depot/Outside/b, src: * (glob)
committing manifest
committing changelog
largefile: Outside/anotherlargefile, oid: 9703972eff7a4df07317eda436ab7ef827ed16ea28c62abdcd7de269745c610c

View File

@ -81,9 +81,9 @@ Sync Import
latest change list number 4
1 added files
0 removed files
file: //depot/Main/Outside/a, src: * (glob)
committing files:
Main/Outside/a
file: //depot/Main/Outside/a, src: * (glob)
committing manifest
committing changelog

View File

@ -57,15 +57,15 @@ it cannot be used as source for move operation)
loading changelist numbers.
2 changelists to import.
importing CL1
file: //depot/foo/a, src: * (glob)
committing files:
a
file: //depot/foo/a, src: * (glob)
committing manifest
committing changelog
importing CL3
file: //depot/foo/b, src: * (glob)
committing files:
b
file: //depot/foo/b, src: * (glob)
committing manifest
committing changelog

View File

@ -102,19 +102,19 @@ Run seqimport limiting to one changelist
3 changelists to import.
importing 1 only because of --limit.
importing CL1
file: //depot/Main/a, src: * (glob)
file: //depot/Main/b, src: * (glob)
file: //depot/Main/kw, src: * (glob)
file: //depot/Main/symlink, src: * (glob)
file: //depot/Main/symlinktosymlink, src: * (glob)
file: //depot/Main/x, src: * (glob)
committing files:
Main/a
file: //depot/Main/a, src: * (glob)
Main/b
file: //depot/Main/b, src: * (glob)
Main/kw
file: //depot/Main/kw, src: * (glob)
Main/symlink
file: //depot/Main/symlink, src: * (glob)
Main/symlinktosymlink
file: //depot/Main/symlinktosymlink, src: * (glob)
Main/x
file: //depot/Main/x, src: * (glob)
committing manifest
committing changelog
writing metadata to sqlite
@ -154,22 +154,22 @@ Run seqimport again for up to 50 changelists
2 changelists to import.
importing CL2
file: //depot/Main/b, src: * (glob)
file: //depot/Main/amove, src: * (glob)
file: //depot/Main/c, src: * (glob)
committing files:
Main/amove
file: //depot/Main/amove, src: * (glob)
Main/amove: copy Main/a:* (glob)
Main/b
Main/c
file: //depot/Main/c, src: * (glob)
committing manifest
committing changelog
writing metadata to sqlite
importing CL3
file: //depot/Main/symlink, src: * (glob)
file: //depot/Main/x, src: * (glob)
file: //depot/Main/largefile, src: * (glob)
committing files:
Main/largefile
file: //depot/Main/largefile, src: * (glob)
Main/symlink
Main/x
committing manifest