From c8942a223d41adab336946913f28cf8691ee479a Mon Sep 17 00:00:00 2001 From: Luke Diamand Date: Wed, 11 Apr 2012 17:21:24 +0200 Subject: [PATCH 1/4] git p4: fix-up "import/export of labels to/from p4" The previous one is already in 'next' but was somewhat lacking. The configuration "git-p4.validLabelRegexp" is now called "labelExportRegexp", and its default covers lowercase alphabets as well. Signed-off-by: Luke Diamand Signed-off-by: Junio C Hamano --- Documentation/git-p4.txt | 20 ++++++++++---------- git-p4.py | 24 +++++++++++------------- t/t9811-git-p4-label-import.sh | 4 ++-- 3 files changed, 23 insertions(+), 25 deletions(-) diff --git a/Documentation/git-p4.txt b/Documentation/git-p4.txt index 612d51d4e7..01cc97bb11 100644 --- a/Documentation/git-p4.txt +++ b/Documentation/git-p4.txt @@ -267,7 +267,7 @@ These options can be used to modify 'git p4 submit' behavior. Re-author p4 changes before submitting to p4. This option requires p4 admin privileges. ---export-labels: +--export-labels:: Export tags from git as p4 labels. Tags found in git are applied to the perforce working directory. @@ -442,6 +442,11 @@ git-p4.branchList:: by a colon (:). This example declares that both branchA and branchB were created from main: +------------- +git config git-p4.branchList main:branchA +git config --add git-p4.branchList main:branchB +------------- + git-p4.ignoredP4Labels:: List of p4 labels to ignore. This is built automatically as unimportable labels are discovered. @@ -449,14 +454,9 @@ git-p4.ignoredP4Labels:: git-p4.importLabels:: Import p4 labels into git, as per --import-labels. -git-p4.validLabelRegexp:: +git-p4.labelImportRegexp:: Only p4 labels matching this regular expression will be imported. The - default value is '[A-Z0-9_\-.]+$'. - -------------- -git config git-p4.branchList main:branchA -git config --add git-p4.branchList main:branchB -------------- + default value is '[a-zA-Z0-9_\-.]+$'. git-p4.useClientSpec:: Specify that the p4 client spec should be used to identify p4 @@ -515,9 +515,9 @@ git-p4.attemptRCSCleanup: git-p4.exportLabels:: Export git tags to p4 labels, as per --export-labels. -git-p4.validLabelRegexp:: +git-p4.labelExportRegexp:: Only p4 labels matching this regular expression will be exported. The - default value is '[A-Z0-9_\-.]+$'. + default value is '[a-zA-Z0-9_\-.]+$'. IMPLEMENTATION DETAILS ---------------------- diff --git a/git-p4.py b/git-p4.py index b35223eeb2..0009d733f6 100755 --- a/git-p4.py +++ b/git-p4.py @@ -15,7 +15,7 @@ import re, shutil verbose = False # Only labels/tags matching this will be imported/exported -defaultLabelRegexp = r'[A-Z0-9_\-.]+$' +defaultLabelRegexp = r'[a-zA-Z0-9_\-.]+$' def p4_build_cmd(cmd): """Build a suitable p4 command line. @@ -1255,11 +1255,10 @@ class P4Submit(Command, P4UserMap): # Export git tags as p4 labels. Create a p4 label and then tag # with that. def exportGitTags(self, gitTags): - validTagRegexp = gitConfig("git-p4.validTagRegexp") - if len(validTagRegexp) == 0: - validTagRegexp = defaultLabelRegexp - m = re.compile(validTagRegexp) - commit_re = re.compile(r'\s*\[git-p4:.*change = (\d+)\s*\]') + validLabelRegexp = gitConfig("git-p4.labelExportRegexp") + if len(validLabelRegexp) == 0: + validLabelRegexp = defaultLabelRegexp + m = re.compile(validLabelRegexp) for name in gitTags: @@ -1269,17 +1268,16 @@ class P4Submit(Command, P4UserMap): continue # Get the p4 commit this corresponds to - changelist = None - for l in read_pipe_lines(["git", "log", "--max-count=1", name]): - match = commit_re.match(l) - if match: - changelist = match.group(1) + logMessage = extractLogMessageFromGitCommit(name) + values = extractSettingsGitLog(logMessage) - if not changelist: + if not values.has_key('change'): # a tag pointing to something not sent to p4; ignore if verbose: print "git tag %s does not give a p4 commit" % name continue + else: + changelist = values['change'] # Get the tag details. inHeader = True @@ -2076,7 +2074,7 @@ class P4Sync(Command, P4UserMap): print "import p4 labels: " + ' '.join(p4Labels) ignoredP4Labels = gitConfigList("git-p4.ignoredP4Labels") - validLabelRegexp = gitConfig("git-p4.validLabelRegexp") + validLabelRegexp = gitConfig("git-p4.labelImportRegexp") if len(validLabelRegexp) == 0: validLabelRegexp = defaultLabelRegexp m = re.compile(validLabelRegexp) diff --git a/t/t9811-git-p4-label-import.sh b/t/t9811-git-p4-label-import.sh index 85d60494bf..fb00ffab24 100755 --- a/t/t9811-git-p4-label-import.sh +++ b/t/t9811-git-p4-label-import.sh @@ -30,7 +30,7 @@ test_expect_success 'basic p4 labels' ' p4 tag -l TAG_F1_ONLY main/f1 && p4 tag -l TAG_WITH\$_SHELL_CHAR main/... && - p4 tag -l this_tag_will_be_skipped main/... && + p4 tag -l this_tag_will_be\ skipped main/... && echo f4 >main/f4 && p4 add main/f4 && @@ -50,7 +50,7 @@ test_expect_success 'basic p4 labels' ' git p4 clone --dest="$git" //depot@all && cd "$git" && - git config git-p4.validLabelRegexp ".*TAG.*" && + git config git-p4.labelImportRegexp ".*TAG.*" && git p4 sync --import-labels --verbose && git tag && From 1e3e7180a1bc0c7af7ad8ccaa45467f6ee92f2bd Mon Sep 17 00:00:00 2001 From: Luke Diamand Date: Tue, 24 Apr 2012 09:33:20 +0100 Subject: [PATCH 2/4] git p4: Squash P4EDITOR in test harness If P4EDITOR is set in the environment, test behavior could be unpredictable. Set it explicitly. Signed-off-by: Luke Diamand Signed-off-by: Junio C Hamano --- t/lib-git-p4.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/t/lib-git-p4.sh b/t/lib-git-p4.sh index b90986c2c9..121e38002b 100644 --- a/t/lib-git-p4.sh +++ b/t/lib-git-p4.sh @@ -24,6 +24,7 @@ P4DPORT=$((10669 + ($testid - $git_p4_test_start))) export P4PORT=localhost:$P4DPORT export P4CLIENT=client +export P4EDITOR=: db="$TRASH_DIRECTORY/db" cli="$TRASH_DIRECTORY/cli" From f95ceaf04aa304cff1bf0bc76e8fed3fea5d0484 Mon Sep 17 00:00:00 2001 From: Luke Diamand Date: Tue, 24 Apr 2012 09:33:21 +0100 Subject: [PATCH 3/4] git p4: Ignore P4EDITOR if it is empty p4 itself treats an empty value for P4EDITOR as the same as having P4EDITOR unset. Do the same for "git p4". Signed-off-by: Luke Diamand Signed-off-by: Junio C Hamano --- git-p4.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-p4.py b/git-p4.py index 0009d733f6..6ce88ffb51 100755 --- a/git-p4.py +++ b/git-p4.py @@ -994,7 +994,7 @@ class P4Submit(Command, P4UserMap): mtime = os.stat(template_file).st_mtime # invoke the editor - if os.environ.has_key("P4EDITOR"): + if os.environ.has_key("P4EDITOR") and (os.environ.get("P4EDITOR") != ""): editor = os.environ.get("P4EDITOR") else: editor = read_pipe("git var GIT_EDITOR").strip() From 6a10b6aa1e7b9bb114e525edb67b7650b46f333e Mon Sep 17 00:00:00 2001 From: Luke Diamand Date: Tue, 24 Apr 2012 09:33:23 +0100 Subject: [PATCH 4/4] git p4: move verbose to base class The verbose flag is common to all classes, or at least should be. Make it a member of the base Command class, rather than reimplementing for each class. Make option parsing mirror this. Signed-off-by: Luke Diamand Signed-off-by: Junio C Hamano --- Documentation/git-p4.txt | 11 ++++------- git-p4.py | 31 ++++++++++--------------------- 2 files changed, 14 insertions(+), 28 deletions(-) diff --git a/Documentation/git-p4.txt b/Documentation/git-p4.txt index 01cc97bb11..51955a5f7c 100644 --- a/Documentation/git-p4.txt +++ b/Documentation/git-p4.txt @@ -158,11 +158,14 @@ OPTIONS General options ~~~~~~~~~~~~~~~ -All commands except clone accept this option. +All commands except clone accept these options. --git-dir :: Set the 'GIT_DIR' environment variable. See linkgit:git[1]. +--verbose:: + Provide more progress information. + Sync options ~~~~~~~~~~~~ These options can be used in the initial 'clone' as well as in @@ -193,9 +196,6 @@ git repository: --silent:: Do not print any progress information. ---verbose:: - Provide more progress information. - --detect-labels:: Query p4 for labels associated with the depot paths, and add them as tags in git. Limited usefulness as only imports labels @@ -249,9 +249,6 @@ Submit options ~~~~~~~~~~~~~~ These options can be used to modify 'git p4 submit' behavior. ---verbose:: - Provide more progress information. - --origin :: Upstream location from which commits are identified to submit to p4. By default, this is the most recent p4 commit reachable diff --git a/git-p4.py b/git-p4.py index 6ce88ffb51..eab69590c4 100755 --- a/git-p4.py +++ b/git-p4.py @@ -662,6 +662,7 @@ class Command: def __init__(self): self.usage = "usage: %prog [options]" self.needsGit = True + self.verbose = False class P4UserMap: def __init__(self): @@ -727,13 +728,9 @@ class P4UserMap: class P4Debug(Command): def __init__(self): Command.__init__(self) - self.options = [ - optparse.make_option("--verbose", dest="verbose", action="store_true", - default=False), - ] + self.options = [] self.description = "A tool to debug the output of p4 -G." self.needsGit = False - self.verbose = False def run(self, args): j = 0 @@ -747,11 +744,9 @@ class P4RollBack(Command): def __init__(self): Command.__init__(self) self.options = [ - optparse.make_option("--verbose", dest="verbose", action="store_true"), optparse.make_option("--local", dest="rollbackLocalBranches", action="store_true") ] self.description = "A tool to debug the multi-branch import. Don't use :)" - self.verbose = False self.rollbackLocalBranches = False def run(self, args): @@ -809,7 +804,6 @@ class P4Submit(Command, P4UserMap): Command.__init__(self) P4UserMap.__init__(self) self.options = [ - optparse.make_option("--verbose", dest="verbose", action="store_true"), optparse.make_option("--origin", dest="origin"), optparse.make_option("-M", dest="detectRenames", action="store_true"), # preserve the user, requires relevant p4 permissions @@ -821,7 +815,6 @@ class P4Submit(Command, P4UserMap): self.interactive = True self.origin = "" self.detectRenames = False - self.verbose = False self.preserveUser = gitConfig("git-p4.preserveUser").lower() == "true" self.isWindows = (platform.system() == "Windows") self.exportLabels = False @@ -1644,7 +1637,6 @@ class P4Sync(Command, P4UserMap): optparse.make_option("--silent", dest="silent", action="store_true"), optparse.make_option("--detect-labels", dest="detectLabels", action="store_true"), optparse.make_option("--import-labels", dest="importLabels", action="store_true"), - optparse.make_option("--verbose", dest="verbose", action="store_true"), optparse.make_option("--import-local", dest="importIntoRemotes", action="store_false", help="Import into refs/heads/ , not refs/remotes"), optparse.make_option("--max-changes", dest="maxChanges"), @@ -1671,7 +1663,6 @@ class P4Sync(Command, P4UserMap): self.importLabels = False self.changesFile = "" self.syncWithOrigin = True - self.verbose = False self.importIntoRemotes = True self.maxChanges = "" self.isWindows = (platform.system() == "Windows") @@ -2712,9 +2703,7 @@ class P4Rebase(Command): Command.__init__(self) self.options = [ optparse.make_option("--import-labels", dest="importLabels", action="store_true"), - optparse.make_option("--verbose", dest="verbose", action="store_true"), ] - self.verbose = False self.importLabels = False self.description = ("Fetches the latest revision from perforce and " + "rebases the current work (branch) against it") @@ -2911,16 +2900,16 @@ def main(): args = sys.argv[2:] - if len(options) > 0: - if cmd.needsGit: - options.append(optparse.make_option("--git-dir", dest="gitdir")) + options.append(optparse.make_option("--verbose", dest="verbose", action="store_true")) + if cmd.needsGit: + options.append(optparse.make_option("--git-dir", dest="gitdir")) - parser = optparse.OptionParser(cmd.usage.replace("%prog", "%prog " + cmdName), - options, - description = cmd.description, - formatter = HelpFormatter()) + parser = optparse.OptionParser(cmd.usage.replace("%prog", "%prog " + cmdName), + options, + description = cmd.description, + formatter = HelpFormatter()) - (cmd, args) = parser.parse_args(sys.argv[2:], cmd); + (cmd, args) = parser.parse_args(sys.argv[2:], cmd); global verbose verbose = cmd.verbose if cmd.needsGit: