class Command:
def __init__(self):
self.usage = "usage: %prog [options]"
+ self.needsGit = True
class P4Debug(Command):
def __init__(self):
self.options = [
]
self.description = "A tool to debug the output of p4 -G."
+ self.needsGit = False
def run(self, args):
for output in p4CmdList(" ".join(args)):
optparse.make_option("--continue", action="store_false", dest="firstTime"),
optparse.make_option("--origin", dest="origin"),
optparse.make_option("--reset", action="store_true", dest="reset"),
- optparse.make_option("--master", dest="master"),
optparse.make_option("--log-substitutions", dest="substFile"),
optparse.make_option("--noninteractive", action="store_false"),
optparse.make_option("--dry-run", action="store_true"),
optparse.make_option("--apply-as-patch", action="store_true", dest="applyAsPatch")
]
self.description = "Submit changes from git to the perforce depot."
+ self.usage += " [name of git branch to submit into perforce depot]"
self.firstTime = True
self.reset = False
self.interactive = True
self.substFile = ""
self.firstTime = True
self.origin = ""
- self.master = ""
self.applyAsPatch = True
self.logSubstitutions = {}
# make gitdir absolute so we can cd out into the perforce checkout
gitdir = os.path.abspath(gitdir)
os.environ["GIT_DIR"] = gitdir
+
+ if len(args) == 0:
+ self.master = currentGitBranch()
+ if len(self.master) == 0 or not os.path.exists("%s/refs/heads/%s" % (gitdir, self.master)):
+ die("Detecting current git branch failed!")
+ elif len(args) == 1:
+ self.master = args[0]
+ else:
+ return False
+
depotPath = ""
if gitBranchExists("p4"):
[depotPath, dummy] = extractDepotPathAndChangeFromGitLog(extractLogMessageFromGitCommit("p4"))
tokens = line[:-1].split("=")
self.logSubstitutions[tokens[0]] = tokens[1]
- if len(self.master) == 0:
- self.master = currentGitBranch()
- if len(self.master) == 0 or not os.path.exists("%s/refs/heads/%s" % (gitdir, self.master)):
- die("Detecting current git branch failed!")
-
self.check()
self.configFile = gitdir + "/p4-git-sync.cfg"
self.config = shelve.open(self.configFile, writeback=True)
optparse.make_option("--changesfile", dest="changesFile"),
optparse.make_option("--silent", dest="silent", action="store_true"),
optparse.make_option("--known-branches", dest="knownBranches"),
- optparse.make_option("--cache", dest="doCache", action="store_true"),
+ optparse.make_option("--data-cache", dest="dataCache", action="store_true"),
optparse.make_option("--command-cache", dest="commandCache", action="store_true")
]
self.description = """Imports from Perforce into a git repository.\n
if knownBranch:
continue
- for branch in knownBranches:
+ for branch in self.knownBranches:
#if relativePath.startswith(branch):
if self.isSubPathOf(relativePath, branch):
if len(branches) == 0:
self.gitStream.write("\n")
- self.lastChange = int(details["change"])
+ change = int(details["change"])
+
+ self.lastChange = change
+
+ if change in self.labels:
+ label = self.labels[change]
+ labelDetails = label[0]
+ labelRevisions = label[1]
+
+ files = p4CmdList("files %s...@%s" % (branchPrefix, change))
+
+ if len(files) == len(labelRevisions):
+
+ cleanedFiles = {}
+ for info in files:
+ if info["action"] == "delete":
+ continue
+ cleanedFiles[info["depotFile"]] = info["rev"]
+
+ if cleanedFiles == labelRevisions:
+ self.gitStream.write("tag tag_%s\n" % labelDetails["label"])
+ self.gitStream.write("from %s\n" % branch)
+
+ owner = labelDetails["Owner"]
+ tagger = ""
+ if author in self.users:
+ tagger = "%s %s %s" % (self.users[owner], epoch, self.tz)
+ else:
+ tagger = "%s <a@b> %s %s" % (owner, epoch, self.tz)
+ self.gitStream.write("tagger %s\n" % tagger)
+ self.gitStream.write("data <<EOT\n")
+ self.gitStream.write(labelDetails["Description"])
+ self.gitStream.write("EOT\n\n")
+
+ else:
+ if not self.silent:
+ print "Tag %s does not match with change %s: files do not match." % (labelDetails["label"], change)
+
+ else:
+ if not self.silent:
+ print "Tag %s does not match with change %s: file count is different." % (labelDetails["label"], change)
def extractFilesInCommitToBranch(self, files, branchPrefix):
newFiles = []
continue
self.users[output["User"]] = output["FullName"] + " <" + output["Email"] + ">"
+ def getLabels(self):
+ self.labels = {}
+
+ for output in p4CmdList("labels %s..." % self.globalPrefix):
+ label = output["label"]
+ revisions = {}
+ newestChange = 0
+ for file in p4CmdList("files //...@%s" % label):
+ revisions[file["depotFile"]] = file["rev"]
+ change = int(file["change"])
+ if change > newestChange:
+ newestChange = change
+
+ self.labels[newestChange] = [output, revisions]
+
def run(self, args):
self.globalPrefix = ""
self.changeRange = ""
self.globalPrefix += "/"
self.getUserMap()
+ self.getLabels();
if len(self.changeRange) == 0:
try:
(cmd, args) = parser.parse_args(sys.argv[2:], cmd);
-gitdir = cmd.gitdir
-if len(gitdir) == 0:
- gitdir = ".git"
- if not isValidGitDir(gitdir):
- cdup = os.popen("git rev-parse --show-cdup").read()[:-1]
- if isValidGitDir(cdup + "/" + gitdir):
- os.chdir(cdup)
+if cmd.needsGit:
+ gitdir = cmd.gitdir
+ if len(gitdir) == 0:
+ gitdir = ".git"
+ if not isValidGitDir(gitdir):
+ cdup = os.popen("git rev-parse --show-cdup").read()[:-1]
+ if isValidGitDir(cdup + "/" + gitdir):
+ os.chdir(cdup)
-if not isValidGitDir(gitdir):
- if isValidGitDir(gitdir + "/.git"):
- gitdir += "/.git"
- else:
- die("fatal: cannot locate git repository at %s" % gitdir)
+ if not isValidGitDir(gitdir):
+ if isValidGitDir(gitdir + "/.git"):
+ gitdir += "/.git"
+ else:
+ die("fatal: cannot locate git repository at %s" % gitdir)
-os.environ["GIT_DIR"] = gitdir
+ os.environ["GIT_DIR"] = gitdir
if not cmd.run(args):
parser.print_help()