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 <luke@diamand.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Luke Diamand committed Apr 24, 2012 at 09:33 UTC 6a10b6aa1e7b9bb114e525edb67b7650b46f333e
2 files changed +14 -28
Documentation/git-p4.txt
+4 -7
@@ -158,11 +158,14 @@ OPTIONS
158
159 General options
160 ~~~~~~~~~~~~~~~
161 -All commands except clone accept this option.
161 +All commands except clone accept these options.
162
163 --git-dir <dir>::
164 Set the 'GIT_DIR' environment variable. See linkgit:git[1].
165
166 +--verbose::
167 + Provide more progress information.
168 +
169 Sync options
170 ~~~~~~~~~~~~
171 These options can be used in the initial 'clone' as well as in
@@ -193,9 +196,6 @@ git repository:
196 --silent::
197 Do not print any progress information.
198
196 ---verbose::
197 - Provide more progress information.
198 -
199 --detect-labels::
200 Query p4 for labels associated with the depot paths, and add
201 them as tags in git. Limited usefulness as only imports labels
@@ -249,9 +249,6 @@ Submit options
249 ~~~~~~~~~~~~~~
250 These options can be used to modify 'git p4 submit' behavior.
251
252 ---verbose::
253 - Provide more progress information.
254 -
252 --origin <commit>::
253 Upstream location from which commits are identified to submit to
254 p4. By default, this is the most recent p4 commit reachable
git-p4.py
+10 -21
@@ -662,6 +662,7 @@ class Command:
662 def __init__(self):
663 self.usage = "usage: %prog [options]"
664 self.needsGit = True
665 + self.verbose = False
666
667 class P4UserMap:
668 def __init__(self):
@@ -727,13 +728,9 @@ class P4UserMap:
728 class P4Debug(Command):
729 def __init__(self):
730 Command.__init__(self)
730 - self.options = [
731 - optparse.make_option("--verbose", dest="verbose", action="store_true",
732 - default=False),
733 - ]
731 + self.options = []
732 self.description = "A tool to debug the output of p4 -G."
733 self.needsGit = False
736 - self.verbose = False
734
735 def run(self, args):
736 j = 0
@@ -747,11 +744,9 @@ class P4RollBack(Command):
744 def __init__(self):
745 Command.__init__(self)
746 self.options = [
750 - optparse.make_option("--verbose", dest="verbose", action="store_true"),
747 optparse.make_option("--local", dest="rollbackLocalBranches", action="store_true")
748 ]
749 self.description = "A tool to debug the multi-branch import. Don't use :)"
754 - self.verbose = False
750 self.rollbackLocalBranches = False
751
752 def run(self, args):
@@ -809,7 +804,6 @@ class P4Submit(Command, P4UserMap):
804 Command.__init__(self)
805 P4UserMap.__init__(self)
806 self.options = [
812 - optparse.make_option("--verbose", dest="verbose", action="store_true"),
807 optparse.make_option("--origin", dest="origin"),
808 optparse.make_option("-M", dest="detectRenames", action="store_true"),
809 # preserve the user, requires relevant p4 permissions
@@ -821,7 +815,6 @@ class P4Submit(Command, P4UserMap):
815 self.interactive = True
816 self.origin = ""
817 self.detectRenames = False
824 - self.verbose = False
818 self.preserveUser = gitConfig("git-p4.preserveUser").lower() == "true"
819 self.isWindows = (platform.system() == "Windows")
820 self.exportLabels = False
@@ -1644,7 +1637,6 @@ class P4Sync(Command, P4UserMap):
1637 optparse.make_option("--silent", dest="silent", action="store_true"),
1638 optparse.make_option("--detect-labels", dest="detectLabels", action="store_true"),
1639 optparse.make_option("--import-labels", dest="importLabels", action="store_true"),
1647 - optparse.make_option("--verbose", dest="verbose", action="store_true"),
1640 optparse.make_option("--import-local", dest="importIntoRemotes", action="store_false",
1641 help="Import into refs/heads/ , not refs/remotes"),
1642 optparse.make_option("--max-changes", dest="maxChanges"),
@@ -1671,7 +1663,6 @@ class P4Sync(Command, P4UserMap):
1663 self.importLabels = False
1664 self.changesFile = ""
1665 self.syncWithOrigin = True
1674 - self.verbose = False
1666 self.importIntoRemotes = True
1667 self.maxChanges = ""
1668 self.isWindows = (platform.system() == "Windows")
@@ -2712,9 +2703,7 @@ class P4Rebase(Command):
2703 Command.__init__(self)
2704 self.options = [
2705 optparse.make_option("--import-labels", dest="importLabels", action="store_true"),
2715 - optparse.make_option("--verbose", dest="verbose", action="store_true"),
2706 ]
2717 - self.verbose = False
2707 self.importLabels = False
2708 self.description = ("Fetches the latest revision from perforce and "
2709 + "rebases the current work (branch) against it")
@@ -2911,16 +2900,16 @@ def main():
2900
2901 args = sys.argv[2:]
2902
2914 - if len(options) > 0:
2915 - if cmd.needsGit:
2916 - options.append(optparse.make_option("--git-dir", dest="gitdir"))
2903 + options.append(optparse.make_option("--verbose", dest="verbose", action="store_true"))
2904 + if cmd.needsGit:
2905 + options.append(optparse.make_option("--git-dir", dest="gitdir"))
2906
2918 - parser = optparse.OptionParser(cmd.usage.replace("%prog", "%prog " + cmdName),
2919 - options,
2920 - description = cmd.description,
2921 - formatter = HelpFormatter())
2907 + parser = optparse.OptionParser(cmd.usage.replace("%prog", "%prog " + cmdName),
2908 + options,
2909 + description = cmd.description,
2910 + formatter = HelpFormatter())
2911
2923 - (cmd, args) = parser.parse_args(sys.argv[2:], cmd);
2912 + (cmd, args) = parser.parse_args(sys.argv[2:], cmd);
2913 global verbose
2914 verbose = cmd.verbose
2915 if cmd.needsGit: