@matheusbsbs / matheus-bagliano / commits / 5834684d51
Fork 0

Added a rollback command for debugging. It sets back the heads of the p4 branches to the specified p4 change number or earlier.

Signed-off-by: Simon Hausmann <shausman@trolltech.com>

Simon Hausmann committed May 21, 2007 at 22:57 UTC 5834684d51ee6e0c21cce8d1b5df06a34a36a4f9
1 file changed +32 -5
contrib/fast-import/git-p4
+32 -5
@@ -7,10 +7,7 @@
7 # 2007 Trolltech ASA
8 # License: MIT <http://www.opensource.org/licenses/mit-license.php>
9 #
10 -# TODO: * implement git-p4 rollback <perforce change number> for debugging
11 -# to roll back all p4 remote branches to a commit older or equal to
12 -# the specified change.
13 -# * Consider making --with-origin the default, assuming that the git
10 +# TODO: * Consider making --with-origin the default, assuming that the git
11 # protocol is always more efficient. (needs manual testing first :)
12 #
13
@@ -135,6 +132,35 @@ class P4Debug(Command):
132 print output
133 return True
134
135 +class P4RollBack(Command):
136 + def __init__(self):
137 + Command.__init__(self)
138 + self.options = [
139 + ]
140 + self.description = "A tool to debug the multi-branch import. Don't use :)"
141 +
142 + def run(self, args):
143 + if len(args) != 1:
144 + return False
145 + maxChange = int(args[0])
146 + for line in mypopen("git rev-parse --symbolic --remotes").readlines():
147 + if line.startswith("p4/") and line != "p4/HEAD\n":
148 + ref = "refs/remotes/" + line[:-1]
149 + log = extractLogMessageFromGitCommit(ref)
150 + depotPath, change = extractDepotPathAndChangeFromGitLog(log)
151 + changed = False
152 + while len(change) > 0 and int(change) > maxChange:
153 + changed = True
154 + print "%s is at %s ; rewinding towards %s" % (ref, change, maxChange)
155 + system("git update-ref %s \"%s^\"" % (ref, ref))
156 + log = extractLogMessageFromGitCommit(ref)
157 + depotPath, change = extractDepotPathAndChangeFromGitLog(log)
158 +
159 + if changed:
160 + print "%s is at %s" % (ref, change)
161 +
162 + return True
163 +
164 class P4Submit(Command):
165 def __init__(self):
166 Command.__init__(self)
@@ -1109,7 +1135,8 @@ commands = {
1135 "submit" : P4Submit(),
1136 "sync" : P4Sync(),
1137 "rebase" : P4Rebase(),
1112 - "clone" : P4Clone()
1138 + "clone" : P4Clone(),
1139 + "rollback" : P4RollBack()
1140 }
1141
1142 if len(sys.argv[1:]) == 0: