git-p4: remove "rollback" verb

The "rollback" verb implements a simple algorithm which takes the set of remote perforce tracker branches, or optionally, the complete collection of local branches in a git repository, and deletes commits from these branches until there are no commits left with a perforce change number greater than than a user-specified change number. If the base of a git branch has a newer change number than the user-specified maximum, then the branch is deleted. In future, there might be an argument for the addition of some kind of "reset this branch back to a given perforce change number" verb for git-p4. However, in its current form it is unlikely to be useful to users for the following reasons: * The verb is completely undocumented. The only description provided contains the following text: "A tool to debug the multi-branch import. Don't use :)". * The verb has a very narrow purpose in that it applies the rollback operation to fixed sets of branches - either all remote p4 branches, or all local branches. There is no way for users to specify branches with more granularity, for example, allowing users to specify a single branch or a set of branches. The utility of the current implementation is therefore a niche within a niche. Given these shortcomings, this patch removes the verb from git-p4. Signed-off-by: Joel Holdsworth <jholdsworth@nvidia.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Joel Holdsworth committed Dec 22, 2021 at 14:55 UTC 0fe3df45f2818d15ec5d542948f08eb035846d08
1 file changed -60
git-p4.py
-60
@@ -1532,65 +1532,6 @@ class P4UserMap:
1532 except IOError:
1533 self.getUserMapFromPerforceServer()
1534
1535 -class P4RollBack(Command):
1536 - def __init__(self):
1537 - Command.__init__(self)
1538 - self.options = [
1539 - optparse.make_option("--local", dest="rollbackLocalBranches", action="store_true")
1540 - ]
1541 - self.description = "A tool to debug the multi-branch import. Don't use :)"
1542 - self.rollbackLocalBranches = False
1543 -
1544 - def run(self, args):
1545 - if len(args) != 1:
1546 - return False
1547 - maxChange = int(args[0])
1548 -
1549 - if "p4ExitCode" in p4Cmd("changes -m 1"):
1550 - die("Problems executing p4");
1551 -
1552 - if self.rollbackLocalBranches:
1553 - refPrefix = "refs/heads/"
1554 - lines = read_pipe_lines("git rev-parse --symbolic --branches")
1555 - else:
1556 - refPrefix = "refs/remotes/"
1557 - lines = read_pipe_lines("git rev-parse --symbolic --remotes")
1558 -
1559 - for line in lines:
1560 - if self.rollbackLocalBranches or (line.startswith("p4/") and line != "p4/HEAD\n"):
1561 - line = line.strip()
1562 - ref = refPrefix + line
1563 - log = extractLogMessageFromGitCommit(ref)
1564 - settings = extractSettingsGitLog(log)
1565 -
1566 - depotPaths = settings['depot-paths']
1567 - change = settings['change']
1568 -
1569 - changed = False
1570 -
1571 - if len(p4Cmd("changes -m 1 " + ' '.join (['%s...@%s' % (p, maxChange)
1572 - for p in depotPaths]))) == 0:
1573 - print("Branch %s did not exist at change %s, deleting." % (ref, maxChange))
1574 - system("git update-ref -d %s `git rev-parse %s`" % (ref, ref))
1575 - continue
1576 -
1577 - while change and int(change) > maxChange:
1578 - changed = True
1579 - if self.verbose:
1580 - print("%s is at %s ; rewinding towards %s" % (ref, change, maxChange))
1581 - system("git update-ref %s \"%s^\"" % (ref, ref))
1582 - log = extractLogMessageFromGitCommit(ref)
1583 - settings = extractSettingsGitLog(log)
1584 -
1585 -
1586 - depotPaths = settings['depot-paths']
1587 - change = settings['change']
1588 -
1589 - if changed:
1590 - print("%s rewound to %s" % (ref, change))
1591 -
1592 - return True
1593 -
1535 class P4Submit(Command, P4UserMap):
1536
1537 conflict_behavior_choices = ("ask", "skip", "quit")
@@ -4353,7 +4294,6 @@ commands = {
4294 "sync" : P4Sync,
4295 "rebase" : P4Rebase,
4296 "clone" : P4Clone,
4356 - "rollback" : P4RollBack,
4297 "branches" : P4Branches,
4298 "unshelve" : P4Unshelve,
4299 }