@matheusbsbs / matheus-bagliano / commits / e87f37ae42
Fork 0

git-p4: Cleanup; moved the code to import a list of p4 changes using fast-import into a separate member function of P4Sync.

Signed-off-by: Simon Hausmann <simon@lst.de>

Simon Hausmann committed Aug 26, 2007 at 16:00 UTC e87f37ae42dad89b39620c234fc29c94529a4d07
1 file changed +71 -69
contrib/fast-import/git-p4
+71 -69
@@ -1118,6 +1118,76 @@ class P4Sync(Command):
1118 self.keepRepoPath = (d.has_key('options')
1119 and ('keepRepoPath' in d['options']))
1120
1121 + def importChanges(self, changes):
1122 + cnt = 1
1123 + for change in changes:
1124 + description = p4Cmd("describe %s" % change)
1125 + self.updateOptionDict(description)
1126 +
1127 + if not self.silent:
1128 + sys.stdout.write("\rImporting revision %s (%s%%)" % (change, cnt * 100 / len(changes)))
1129 + sys.stdout.flush()
1130 + cnt = cnt + 1
1131 +
1132 + try:
1133 + if self.detectBranches:
1134 + branches = self.splitFilesIntoBranches(description)
1135 + for branch in branches.keys():
1136 + ## HACK --hwn
1137 + branchPrefix = self.depotPaths[0] + branch + "/"
1138 +
1139 + parent = ""
1140 +
1141 + filesForCommit = branches[branch]
1142 +
1143 + if self.verbose:
1144 + print "branch is %s" % branch
1145 +
1146 + self.updatedBranches.add(branch)
1147 +
1148 + if branch not in self.createdBranches:
1149 + self.createdBranches.add(branch)
1150 + parent = self.knownBranches[branch]
1151 + if parent == branch:
1152 + parent = ""
1153 + elif self.verbose:
1154 + print "parent determined through known branches: %s" % parent
1155 +
1156 + # main branch? use master
1157 + if branch == "main":
1158 + branch = "master"
1159 + else:
1160 +
1161 + ## FIXME
1162 + branch = self.projectName + branch
1163 +
1164 + if parent == "main":
1165 + parent = "master"
1166 + elif len(parent) > 0:
1167 + ## FIXME
1168 + parent = self.projectName + parent
1169 +
1170 + branch = self.refPrefix + branch
1171 + if len(parent) > 0:
1172 + parent = self.refPrefix + parent
1173 +
1174 + if self.verbose:
1175 + print "looking for initial parent for %s; current parent is %s" % (branch, parent)
1176 +
1177 + if len(parent) == 0 and branch in self.initialParents:
1178 + parent = self.initialParents[branch]
1179 + del self.initialParents[branch]
1180 +
1181 + self.commit(description, filesForCommit, branch, [branchPrefix], parent)
1182 + else:
1183 + files = self.extractFilesFromCommit(description)
1184 + self.commit(description, files, self.branch, self.depotPaths,
1185 + self.initialParent)
1186 + self.initialParent = ""
1187 + except IOError:
1188 + print self.gitError.read()
1189 + sys.exit(1)
1190 +
1191 def run(self, args):
1192 self.depotPaths = []
1193 self.changeRange = ""
@@ -1350,74 +1420,7 @@ class P4Sync(Command):
1420
1421 self.updatedBranches = set()
1422
1353 - cnt = 1
1354 - for change in changes:
1355 - description = p4Cmd("describe %s" % change)
1356 - self.updateOptionDict(description)
1357 -
1358 - if not self.silent:
1359 - sys.stdout.write("\rImporting revision %s (%s%%)" % (change, cnt * 100 / len(changes)))
1360 - sys.stdout.flush()
1361 - cnt = cnt + 1
1362 -
1363 - try:
1364 - if self.detectBranches:
1365 - branches = self.splitFilesIntoBranches(description)
1366 - for branch in branches.keys():
1367 - ## HACK --hwn
1368 - branchPrefix = self.depotPaths[0] + branch + "/"
1369 -
1370 - parent = ""
1371 -
1372 - filesForCommit = branches[branch]
1373 -
1374 - if self.verbose:
1375 - print "branch is %s" % branch
1376 -
1377 - self.updatedBranches.add(branch)
1378 -
1379 - if branch not in self.createdBranches:
1380 - self.createdBranches.add(branch)
1381 - parent = self.knownBranches[branch]
1382 - if parent == branch:
1383 - parent = ""
1384 - elif self.verbose:
1385 - print "parent determined through known branches: %s" % parent
1386 -
1387 - # main branch? use master
1388 - if branch == "main":
1389 - branch = "master"
1390 - else:
1391 -
1392 - ## FIXME
1393 - branch = self.projectName + branch
1394 -
1395 - if parent == "main":
1396 - parent = "master"
1397 - elif len(parent) > 0:
1398 - ## FIXME
1399 - parent = self.projectName + parent
1400 -
1401 - branch = self.refPrefix + branch
1402 - if len(parent) > 0:
1403 - parent = self.refPrefix + parent
1404 -
1405 - if self.verbose:
1406 - print "looking for initial parent for %s; current parent is %s" % (branch, parent)
1407 -
1408 - if len(parent) == 0 and branch in self.initialParents:
1409 - parent = self.initialParents[branch]
1410 - del self.initialParents[branch]
1411 -
1412 - self.commit(description, filesForCommit, branch, [branchPrefix], parent)
1413 - else:
1414 - files = self.extractFilesFromCommit(description)
1415 - self.commit(description, files, self.branch, self.depotPaths,
1416 - self.initialParent)
1417 - self.initialParent = ""
1418 - except IOError:
1419 - print self.gitError.read()
1420 - sys.exit(1)
1423 + self.importChanges(changes)
1424
1425 if not self.silent:
1426 print ""
@@ -1427,7 +1430,6 @@ class P4Sync(Command):
1430 sys.stdout.write("%s " % b)
1431 sys.stdout.write("\n")
1432
1430 -
1433 self.gitStream.close()
1434 if importProcess.wait() != 0:
1435 die("fast-import failed: %s" % self.gitError.read())