use p4CmdList() to get file contents in Python dicts. This is more robust.
Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
Han-Wen Nienhuys committed
May 23, 2007 at 18:49 UTC
d2c6dd30eff648aef30d003ef327ab9415f86db0
1 file changed
+21
-35
contrib/fast-import/git-p4
+21
-35
@@ -580,7 +580,8 @@ class P4Sync(Command):
580
optparse.make_option("--silent", dest="silent", action="store_true"),
581
optparse.make_option("--detect-labels", dest="detectLabels", action="store_true"),
582
optparse.make_option("--verbose", dest="verbose", action="store_true"),
583
- optparse.make_option("--import-local", dest="importIntoRemotes", action="store_false"),
583
+ optparse.make_option("--import-local", dest="importIntoRemotes", action="store_false",
584
+ help="Import into refs/heads/ , not refs/remotes"),
585
optparse.make_option("--max-changes", dest="maxChanges"),
586
optparse.make_option("--keep-path", dest="keepRepoPath", action='store_true')
587
]
@@ -680,41 +681,22 @@ class P4Sync(Command):
681
if not specs:
682
return
683
683
- data = read_pipe('p4 print %s' % ' '.join(['"%s"' % path
684
- for (path, info) in specs]))
684
+ filedata = p4CmdList('print %s' % ' '.join(['"%s"' % path
685
+ for (path, info) in specs]))
686
686
- idx = 0
687
- for j in range(0, len(specs)):
688
- (pathrev, info) = specs[j]
687
+ j = 0;
688
+ contents = {}
689
+ while filedata[j:]:
690
+ stat = filedata[j]
691
+ text = filedata[j+1]
692
+ j += 2
693
690
- assert idx < len(data)
691
- if data[idx:idx + len(pathrev)] != pathrev:
692
- assert False
693
- idx = data.find ('\n', idx)
694
- assert idx > 0
695
- idx += 1
694
+ assert stat['code'] == 'stat' and text['code'] == 'text'
695
+ contents[stat['depotFile']] = text['data']
696
697
- start = idx
698
-
699
- end = -1
700
- if j < len(specs)-1:
701
- (next_pathrev, next_info) = specs[j+1]
702
- end = data.find(next_pathrev, start)
703
-
704
- if end < 0:
705
- print 'j'
706
- print 'PATHREV', pathrev, specs[j]
707
- print 'nextpathrev', next_pathrev, specs[j+1]
708
- print 'start', start, len(data)
709
- print 'end', end
710
-
711
- assert end >= 0
712
- else:
713
- end = len(data)
714
-
715
- info['data'] = data[start:end]
716
- idx = end
717
- assert idx == len(data)
697
+ for f in files:
698
+ assert not f.has_key('data')
699
+ f['data'] = contents[f['path']]
700
701
def commit(self, details, files, branch, branchPrefixes, parent = ""):
702
epoch = details["time"]
@@ -1158,8 +1140,12 @@ class P4Sync(Command):
1140
% (p, self.revision)
1141
for p in self.depotPaths])):
1142
1161
- if not info.has_key("change"):
1162
- print info
1143
+ if info['code'] == 'error':
1144
+ sys.stderr.write("p4 returned an error: %s\n"
1145
+ % info['data'])
1146
+ sys.exit(1)
1147
+
1148
+
1149
change = int(info["change"])
1150
if change > newestRevision:
1151
newestRevision = change