git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[StGIT PATCH 4/5] If any uncommit would fail, don't uncommit anything

From
Karl Hasselström <kha@treskal.com>
Date
May 11, 2007, 01:40 UTC
Message-ID
<20070511014021.13161.60939.stgit@yoghurt>
In-Reply-To
<20070511013400.13161.9160.stgit@yoghurt>
From: Karl Hasselström <kha@treskal.com>
Signed-off-by: Karl Hasselström <kha@treskal.com>
---
 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'
Previous: Karl HasselströmNext: Karl Hasselström
Message 5 of 6 in “Some tweaks and enhancements”
  1. 0/5 Some tweaks and enhancementsKarl Hasselström, May 11, 2007
  2. 1/5 Make the "name" argument to "stg new" optionalKarl Hasselström, May 11, 2007
  3. 2/5 Generate patch names of more uniform lengthKarl Hasselström, May 11, 2007
  4. 3/5 Remove an unnecessary parameter to make_patch_nameKarl Hasselström, May 11, 2007
  5. 4/5 If any uncommit would fail, don't uncommit anythingKarl Hasselström, May 11, 2007
  6. 5/5 Uncommit to a named commitKarl Hasselström, May 11, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.