Added support for importing multiple branches into refs/heads instead of just refs/remotes using --import-local. Needs some further microfix but seems to work otherwise.
Added support for importing multiple branches into refs/heads instead of just refs/remotes using --import-local. Needs some further microfix but seems to work otherwise. Signed-off-by: Simon Hausmann <shausman@trolltech.com>
Simon Hausmann committed
May 23, 2007 at 00:03 UTC
a028a98e9ae83231f0657fdb112f7d9c0cf0b98c
1 file changed
+25
-12
contrib/fast-import/git-p4
+25
-12
@@ -498,7 +498,8 @@ class P4Sync(Command):
498
optparse.make_option("--silent", dest="silent", action="store_true"),
499
optparse.make_option("--detect-labels", dest="detectLabels", action="store_true"),
500
optparse.make_option("--with-origin", dest="syncWithOrigin", action="store_true"),
501
- optparse.make_option("--verbose", dest="verbose", action="store_true")
501
+ optparse.make_option("--verbose", dest="verbose", action="store_true"),
502
+ optparse.make_option("--import-local", dest="importIntoRemotes", action="store_false")
503
]
504
self.description = """Imports from Perforce into a git repository.\n
505
example:
@@ -519,6 +520,7 @@ class P4Sync(Command):
520
self.changesFile = ""
521
self.syncWithOrigin = False
522
self.verbose = False
523
+ self.importIntoRemotes = True
524
525
def p4File(self, depotPath):
526
return os.popen("p4 print -q \"%s\"" % depotPath, "rb").read()
@@ -749,11 +751,17 @@ class P4Sync(Command):
751
def listExistingP4GitBranches(self):
752
self.p4BranchesInGit = []
753
752
- for line in mypopen("git rev-parse --symbolic --remotes").readlines():
754
+ cmdline = "git rev-parse --symbolic "
755
+ if self.importIntoRemotes:
756
+ cmdline += " --remotes"
757
+ else:
758
+ cmdline += " --branches"
759
+
760
+ for line in mypopen(cmdline).readlines():
761
if line.startswith("p4/") and line != "p4/HEAD\n":
762
branch = line[3:-1]
763
self.p4BranchesInGit.append(branch)
756
- self.initialParents["refs/remotes/p4/" + branch] = parseRevision(line[:-1])
764
+ self.initialParents[self.refPrefix + branch] = parseRevision(line[:-1])
765
766
def run(self, args):
767
self.depotPath = ""
@@ -764,9 +772,14 @@ class P4Sync(Command):
772
self.knownBranches = {}
773
self.initialParents = {}
774
775
+ if self.importIntoRemotes:
776
+ self.refPrefix = "refs/remotes/p4/"
777
+ else:
778
+ self.refPrefix = "refs/heads/p4/"
779
+
780
createP4HeadRef = False;
781
769
- if self.syncWithOrigin and gitBranchExists("origin") and gitBranchExists("refs/remotes/p4/master") and not self.detectBranches:
782
+ if self.syncWithOrigin and gitBranchExists("origin") and gitBranchExists(self.refPrefix + "master") and not self.detectBranches:
783
### needs to be ported to multi branch import
784
785
print "Syncing with origin first as requested by calling git fetch origin"
@@ -779,17 +792,17 @@ class P4Sync(Command):
792
p4Change = int(p4Change)
793
if originP4Change > p4Change:
794
print "origin (%s) is newer than p4 (%s). Updating p4 branch from origin." % (originP4Change, p4Change)
782
- system("git update-ref refs/remotes/p4/master origin");
795
+ system("git update-ref " + self.refPrefix + "master origin");
796
else:
797
print "Cannot sync with origin. It was imported from %s while remotes/p4 was imported from %s" % (originPreviousDepotPath, p4PreviousDepotPath)
798
799
if len(self.branch) == 0:
787
- self.branch = "refs/remotes/p4/master"
788
- if gitBranchExists("refs/heads/p4"):
800
+ self.branch = self.refPrefix + "master"
801
+ if gitBranchExists("refs/heads/p4") and self.importIntoRemotes:
802
system("git update-ref %s refs/heads/p4" % self.branch)
803
system("git branch -D p4");
804
# create it /after/ importing, when master exists
792
- if not gitBranchExists("refs/remotes/p4/HEAD"):
805
+ if not gitBranchExists(self.refPrefix + "HEAD") and self.importIntoRemotes:
806
createP4HeadRef = True
807
808
# this needs to be called after the conversion from heads/p4 to remotes/p4/master
@@ -813,7 +826,7 @@ class P4Sync(Command):
826
827
p4Change = 0
828
for branch in self.p4BranchesInGit:
816
- depotPath, change = extractDepotPathAndChangeFromGitLog(extractLogMessageFromGitCommit("refs/remotes/p4/" + branch))
829
+ depotPath, change = extractDepotPathAndChangeFromGitLog(extractLogMessageFromGitCommit(self.refPrefix + branch))
830
831
if self.verbose:
832
print "path %s change %s" % (depotPath, change)
@@ -1008,9 +1021,9 @@ class P4Sync(Command):
1021
elif len(parent) > 0:
1022
parent = self.projectName + parent
1023
1011
- branch = "refs/remotes/p4/" + branch
1024
+ branch = self.refPrefix + branch
1025
if len(parent) > 0:
1013
- parent = "refs/remotes/p4/" + parent
1026
+ parent = self.refPrefix + parent
1027
1028
if self.verbose:
1029
print "looking for initial parent for %s; current parent is %s" % (branch, parent)
@@ -1044,7 +1057,7 @@ class P4Sync(Command):
1057
self.gitError.close()
1058
1059
if createP4HeadRef:
1047
- system("git symbolic-ref refs/remotes/p4/HEAD %s" % self.branch)
1060
+ system("git symbolic-ref %s/HEAD %s" % (self.refPrefix, self.branch))
1061
1062
return True
1063