@@ -1188,6 +1188,50 @@ class P4Sync(Command):
11881188 print self .gitError .read ()
11891189 sys .exit (1 )
11901190
1191+ def importHeadRevision (self , revision ):
1192+ print "Doing initial import of %s from revision %s into %s" % (' ' .join (self .depotPaths ), revision , self .branch )
1193+
1194+ details = { "user" : "git perforce import user" , "time" : int (time .time ()) }
1195+ details ["desc" ] = ("Initial import of %s from the state at revision %s"
1196+ % (' ' .join (self .depotPaths ), revision ))
1197+ details ["change" ] = revision
1198+ newestRevision = 0
1199+
1200+ fileCnt = 0
1201+ for info in p4CmdList ("files "
1202+ + ' ' .join (["%s...%s"
1203+ % (p , revision )
1204+ for p in self .depotPaths ])):
1205+
1206+ if info ['code' ] == 'error' :
1207+ sys .stderr .write ("p4 returned an error: %s\n "
1208+ % info ['data' ])
1209+ sys .exit (1 )
1210+
1211+
1212+ change = int (info ["change" ])
1213+ if change > newestRevision :
1214+ newestRevision = change
1215+
1216+ if info ["action" ] == "delete" :
1217+ # don't increase the file cnt, otherwise details["depotFile123"] will have gaps!
1218+ #fileCnt = fileCnt + 1
1219+ continue
1220+
1221+ for prop in ["depotFile" , "rev" , "action" , "type" ]:
1222+ details ["%s%s" % (prop , fileCnt )] = info [prop ]
1223+
1224+ fileCnt = fileCnt + 1
1225+
1226+ details ["change" ] = newestRevision
1227+ self .updateOptionDict (details )
1228+ try :
1229+ self .commit (details , self .extractFilesFromCommit (details ), self .branch , self .depotPaths )
1230+ except IOError :
1231+ print "IO error with git fast-import. Is your git version recent enough?"
1232+ print self .gitError .read ()
1233+
1234+
11911235 def run (self , args ):
11921236 self .depotPaths = []
11931237 self .changeRange = ""
@@ -1346,48 +1390,7 @@ class P4Sync(Command):
13461390 self .gitError = importProcess .stderr
13471391
13481392 if revision :
1349- print "Doing initial import of %s from revision %s into %s" % (' ' .join (self .depotPaths ), revision , self .branch )
1350-
1351- details = { "user" : "git perforce import user" , "time" : int (time .time ()) }
1352- details ["desc" ] = ("Initial import of %s from the state at revision %s"
1353- % (' ' .join (self .depotPaths ), revision ))
1354- details ["change" ] = revision
1355- newestRevision = 0
1356-
1357- fileCnt = 0
1358- for info in p4CmdList ("files "
1359- + ' ' .join (["%s...%s"
1360- % (p , revision )
1361- for p in self .depotPaths ])):
1362-
1363- if info ['code' ] == 'error' :
1364- sys .stderr .write ("p4 returned an error: %s\n "
1365- % info ['data' ])
1366- sys .exit (1 )
1367-
1368-
1369- change = int (info ["change" ])
1370- if change > newestRevision :
1371- newestRevision = change
1372-
1373- if info ["action" ] == "delete" :
1374- # don't increase the file cnt, otherwise details["depotFile123"] will have gaps!
1375- #fileCnt = fileCnt + 1
1376- continue
1377-
1378- for prop in ["depotFile" , "rev" , "action" , "type" ]:
1379- details ["%s%s" % (prop , fileCnt )] = info [prop ]
1380-
1381- fileCnt = fileCnt + 1
1382-
1383- details ["change" ] = newestRevision
1384- self .updateOptionDict (details )
1385- try :
1386- self .commit (details , self .extractFilesFromCommit (details ), self .branch , self .depotPaths )
1387- except IOError :
1388- print "IO error with git fast-import. Is your git version recent enough?"
1389- print self .gitError .read ()
1390-
1393+ self .importHeadRevision (revision )
13911394 else :
13921395 changes = []
13931396
0 commit comments