git-p4: Fix import of changesets with file deletions
Commit 3a70cdfa42199e16d2d047c286431c4274d65b1a 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 <simon@lst.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Simon Hausmann committed
Mar 3, 2008 at 11:55 UTC
30b5940bcd3ed7392795f6a27563013f6f806de4
1 file changed
+25
-20
contrib/fast-import/git-p4
+25
-20
@@ -850,29 +850,32 @@ class P4Sync(Command):
850
851
## Should move this out, doesn't use SELF.
852
def readP4Files(self, files):
853
+ filesForCommit = []
854
+ filesToRead = []
855
+
856
for f in files:
857
+ includeFile = True
858
for val in self.clientSpecDirs:
859
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
862
break
863
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)
868
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+')
875
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']));
879
880
j = 0;
881
contents = {}
@@ -896,10 +899,12 @@ class P4Sync(Command):
899
900
contents[stat['depotFile']] = text
901
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
908
909
def commit(self, details, files, branch, branchPrefixes, parent = ""):
910
epoch = details["time"]