Skip to content

Commit 30b5940

Browse files
tronicalgitster
authored andcommitted
git-p4: Fix import of changesets with file deletions
Commit 3a70cdf made readP4Files abort quickly when the changeset only contains files that are marked for deletion with an empty return value, which caused the commit to not do anything. This commit changes readP4Files to distinguish between files that need to be passed to p4 print and files that have no content ("deleted") and merge them in the returned list. Signed-off-by: Simon Hausmann <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a798b2c commit 30b5940

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

contrib/fast-import/git-p4

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -850,29 +850,32 @@ class P4Sync(Command):
850850

851851
## Should move this out, doesn't use SELF.
852852
def readP4Files(self, files):
853+
filesForCommit = []
854+
filesToRead = []
855+
853856
for f in files:
857+
includeFile = True
854858
for val in self.clientSpecDirs:
855859
if f['path'].startswith(val[0]):
856-
if val[1] > 0:
857-
f['include'] = True
858-
else:
859-
f['include'] = False
860+
if val[1] <= 0:
861+
includeFile = False
860862
break
861863

862-
files = [f for f in files
863-
if f['action'] != 'delete' and
864-
(f.has_key('include') == False or f['include'] == True)]
864+
if includeFile:
865+
filesForCommit.append(f)
866+
if f['action'] != 'delete':
867+
filesToRead.append(f)
865868

866-
if not files:
867-
return []
869+
filedata = []
870+
if len(filesToRead) > 0:
871+
filedata = p4CmdList('-x - print',
872+
stdin='\n'.join(['%s#%s' % (f['path'], f['rev'])
873+
for f in filesToRead]),
874+
stdin_mode='w+')
868875

869-
filedata = p4CmdList('-x - print',
870-
stdin='\n'.join(['%s#%s' % (f['path'], f['rev'])
871-
for f in files]),
872-
stdin_mode='w+')
873-
if "p4ExitCode" in filedata[0]:
874-
die("Problems executing p4. Error: [%d]."
875-
% (filedata[0]['p4ExitCode']));
876+
if "p4ExitCode" in filedata[0]:
877+
die("Problems executing p4. Error: [%d]."
878+
% (filedata[0]['p4ExitCode']));
876879

877880
j = 0;
878881
contents = {}
@@ -896,10 +899,12 @@ class P4Sync(Command):
896899

897900
contents[stat['depotFile']] = text
898901

899-
for f in files:
900-
assert not f.has_key('data')
901-
f['data'] = contents[f['path']]
902-
return files
902+
for f in filesForCommit:
903+
path = f['path']
904+
if contents.has_key(path):
905+
f['data'] = contents[path]
906+
907+
return filesForCommit
903908

904909
def commit(self, details, files, branch, branchPrefixes, parent = ""):
905910
epoch = details["time"]

0 commit comments

Comments
 (0)