Skip to content

Commit

Permalink
git p4: move verbose to base class
Browse files Browse the repository at this point in the history
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 <luke@diamand.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Luke Diamand authored and Junio C Hamano committed Apr 24, 2012
1 parent f95ceaf commit 6a10b6a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 28 deletions.
11 changes: 4 additions & 7 deletions Documentation/git-p4.txt
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,14 @@ OPTIONS

General options
~~~~~~~~~~~~~~~
All commands except clone accept this option.
All commands except clone accept these options.

--git-dir <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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -249,9 +249,6 @@ Submit options
~~~~~~~~~~~~~~
These options can be used to modify 'git p4 submit' behavior.

--verbose::
Provide more progress information.

--origin <commit>::
Upstream location from which commits are identified to submit to
p4. By default, this is the most recent p4 commit reachable
Expand Down
31 changes: 10 additions & 21 deletions git-p4.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -727,13 +728,9 @@ def loadUserMapFromCache(self):
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
Expand All @@ -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):
Expand Down Expand Up @@ -809,7 +804,6 @@ def __init__(self):
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
Expand All @@ -821,7 +815,6 @@ def __init__(self):
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
Expand Down Expand Up @@ -1644,7 +1637,6 @@ def __init__(self):
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"),
Expand All @@ -1671,7 +1663,6 @@ def __init__(self):
self.importLabels = False
self.changesFile = ""
self.syncWithOrigin = True
self.verbose = False
self.importIntoRemotes = True
self.maxChanges = ""
self.isWindows = (platform.system() == "Windows")
Expand Down Expand Up @@ -2712,9 +2703,7 @@ def __init__(self):
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")
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 6a10b6a

Please sign in to comment.