[StGIT PATCH 4/5] If any uncommit would fail, don't uncommit anything
From: Karl Hasselström <hidden>
Date: 2016-06-15 22:43:09
Subsystem:
the rest · Maintainer:
Linus Torvalds
From: Karl Hasselström <redacted> Signed-off-by: Karl Hasselström <redacted> --- stgit/commands/uncommit.py | 26 +++++++++++++++----------- 1 files changed, 15 insertions(+), 11 deletions(-)
diff --git a/stgit/commands/uncommit.py b/stgit/commands/uncommit.py
index 04c7e52..f86af57 100644
--- a/stgit/commands/uncommit.py
+++ b/stgit/commands/uncommit.py@@ -80,23 +80,26 @@ def func(parser, options, args): print 'Uncommitting %d patches...' % patch_nr, sys.stdout.flush() - for n in xrange(0, patch_nr): - # retrieve the commit (only commits with a single parent are allowed) - commit_id = crt_series.get_base() + def get_commit(commit_id): commit = git.Commit(commit_id) try: parent, = commit.get_parents() except ValueError: - raise CmdException, 'Commit %s does not have exactly one parent' \ - % commit_id + raise CmdException('Commit %s does not have exactly one parent' + % commit_id) + return (commit, commit_id, parent) + + commits = [] + next_commit = crt_series.get_base() + for i in xrange(patch_nr): + commit, commit_id, parent = get_commit(next_commit) + commits.append((commit, commit_id, parent)) + next_commit = parent + + for (commit, commit_id, parent), patchname in \ + zip(commits, patchnames or (None for i in xrange(len(commits)))): author_name, author_email, author_date = \ name_email_date(commit.get_author()) - - if patchnames: - patchname = patchnames[n] - else: - patchname = None - crt_series.new_patch(patchname, can_edit = False, before_existing = True, top = commit_id, bottom = parent,
@@ -105,4 +108,5 @@ def func(parser, options, args): author_email = author_email, author_date = author_date) + print 'done'