893
_gitConfig[key] = []
894
return _gitConfig[key]
895
896
+def fullP4Ref(incomingRef, importIntoRemotes=True):
897
+ """Standardize a given provided p4 ref value to a full git ref:
898
+ refs/foo/bar/branch -> use it exactly
899
+ p4/branch -> prepend refs/remotes/ or refs/heads/
900
+ branch -> prepend refs/remotes/p4/ or refs/heads/p4/"""
901
+ if incomingRef.startswith("refs/"):
902
+ return incomingRef
903
+ if importIntoRemotes:
904
+ prepend = "refs/remotes/"
905
+ else:
906
+ prepend = "refs/heads/"
907
+ if not incomingRef.startswith("p4/"):
908
+ prepend += "p4/"
909
+ return prepend + incomingRef
910
+
911
+def shortP4Ref(incomingRef, importIntoRemotes=True):
912
+ """Standardize to a "short ref" if possible:
913
+ refs/foo/bar/branch -> ignore
914
+ refs/remotes/p4/branch or refs/heads/p4/branch -> shorten
915
+ p4/branch -> shorten"""
916
+ if importIntoRemotes:
917
+ longprefix = "refs/remotes/p4/"
918
+ else:
919
+ longprefix = "refs/heads/p4/"
920
+ if incomingRef.startswith(longprefix):
921
+ return incomingRef[len(longprefix):]
922
+ if incomingRef.startswith("p4/"):
923
+ return incomingRef[3:]
924
+ return incomingRef
925
+
926
def p4BranchesInGit(branchesAreInRemotes=True):
927
"""Find all the branches whose names start with "p4/", looking
928
in remotes or heads as specified by the argument. Return
3780
3781
# restrict to just this one, disabling detect-branches
3782
if branch_arg_given:
3753
- short = self.branch.split("/")[-1]
3783
+ short = shortP4Ref(self.branch, self.importIntoRemotes)
3784
if short in branches:
3785
self.p4BranchesInGit = [ short ]
3786
+ elif self.branch.startswith('refs/') and \
3787
+ branchExists(self.branch) and \
3788
+ '[git-p4:' in extractLogMessageFromGitCommit(self.branch):
3789
+ self.p4BranchesInGit = [ self.branch ]
3790
else:
3791
self.p4BranchesInGit = branches.keys()
3792
3803
3804
p4Change = 0
3805
for branch in self.p4BranchesInGit:
3772
- logMsg = extractLogMessageFromGitCommit(self.refPrefix + branch)
3806
+ logMsg = extractLogMessageFromGitCommit(fullP4Ref(branch,
3807
+ self.importIntoRemotes))
3808
3809
settings = extractSettingsGitLog(logMsg)
3810
3837
if not self.silent and not self.detectBranches:
3838
print("Performing incremental import into %s git branch" % self.branch)
3839
3805
- # accept multiple ref name abbreviations:
3806
- # refs/foo/bar/branch -> use it exactly
3807
- # p4/branch -> prepend refs/remotes/ or refs/heads/
3808
- # branch -> prepend refs/remotes/p4/ or refs/heads/p4/
3809
- if not self.branch.startswith("refs/"):
3810
- if self.importIntoRemotes:
3811
- prepend = "refs/remotes/"
3812
- else:
3813
- prepend = "refs/heads/"
3814
- if not self.branch.startswith("p4/"):
3815
- prepend += "p4/"
3816
- self.branch = prepend + self.branch
3840
+ self.branch = fullP4Ref(self.branch, self.importIntoRemotes)
3841
3842
if len(args) == 0 and self.depotPaths:
3843
if not self.silent: