From: "Karl Hasselström" <kha@treskal.com>
To: Catalin Marinas <catalin.marinas@gmail.com>
Cc: git@vger.kernel.org, Petr Baudis <pasky@suse.cz>
Subject: [StGIT PATCH 5/5] Uncommit to a named commit
Date: Fri, 11 May 2007 03:40:27 +0200 [thread overview]
Message-ID: <20070511014027.13161.869.stgit@yoghurt> (raw)
In-Reply-To: <20070511013400.13161.9160.stgit@yoghurt>
From: Karl Hasselström <kha@treskal.com>
Add a new flag to "stg uncommit": --to. This flag takes a committish
parameter, and uncommits everything up until that commit.
Signed-off-by: Karl Hasselström <kha@treskal.com>
---
stgit/commands/uncommit.py | 49 +++++++++++++++++++++++++++++++-------------
t/t1300-uncommit.sh | 8 +++++++
2 files changed, 42 insertions(+), 15 deletions(-)
diff --git a/stgit/commands/uncommit.py b/stgit/commands/uncommit.py
index f86af57..de6a37c 100644
--- a/stgit/commands/uncommit.py
+++ b/stgit/commands/uncommit.py
@@ -25,7 +25,7 @@ from stgit.utils import *
from stgit import stack, git
help = 'turn regular GIT commits into StGIT patches'
-usage = """%prog [<patchname1> [<patchname2> ... ] | -n [<prefix>]]
+usage = """%prog [<patchnames>] | -n NUM [<prefix>]] | -t <committish>
Take one or more git commits at the base of the current stack and turn
them into StGIT patches. The new patches are created as applied patches
@@ -35,24 +35,34 @@ By default, the number of patches to uncommit is determined by the
number of patch names provided on the command line. First name is used
for the first patch to uncommit, i.e. for the newest patch.
-The --number option specifies the number of patches to uncommit. In
+The -n/--number option specifies the number of patches to uncommit. In
this case, at most one patch name may be specified. It is used as
-prefix to which the patch number is appended.
+prefix to which the patch number is appended. If no patch names are
+provided on the command line, StGIT automatically generates them based
+on the first line of the patch description.
-If no patch names are provided on the command line, StGIT
-automatically generates them based on the first line of the patch
-description.
+The -t/--to option specifies that all commits up to and including the
+given commit should be uncommitted.
Only commits with exactly one parent can be uncommitted; in other
words, you can't uncommit a merge."""
options = [make_option('-n', '--number', type = 'int',
- help = 'uncommit the specified number of commits')]
+ help = 'uncommit the specified number of commits'),
+ make_option('-t', '--to',
+ help = 'uncommit to the specified commit')]
def func(parser, options, args):
"""Uncommit a number of patches.
"""
- if options.number:
+ if options.to:
+ if options.number:
+ parser.error('cannot give both --to and --number')
+ if len(args) != 0:
+ parser.error('cannot specify patch name with --to')
+ patch_nr = patchnames = None
+ to_commit = git.rev_parse(options.to)
+ elif options.number:
if options.number <= 0:
parser.error('invalid value passed to --number')
@@ -77,9 +87,6 @@ def func(parser, options, args):
raise CmdException, \
'This branch is protected. Uncommit is not permitted'
- print 'Uncommitting %d patches...' % patch_nr,
- sys.stdout.flush()
-
def get_commit(commit_id):
commit = git.Commit(commit_id)
try:
@@ -91,11 +98,23 @@ def func(parser, options, args):
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
+ if patch_nr:
+ print 'Uncommitting %d patches...' % patch_nr,
+ for i in xrange(patch_nr):
+ commit, commit_id, parent = get_commit(next_commit)
+ commits.append((commit, commit_id, parent))
+ next_commit = parent
+ else:
+ print 'Uncommitting to %s...' % to_commit
+ while True:
+ commit, commit_id, parent = get_commit(next_commit)
+ commits.append((commit, commit_id, parent))
+ if commit_id == to_commit:
+ break
+ next_commit = parent
+ patch_nr = len(commits)
+ sys.stdout.flush()
for (commit, commit_id, parent), patchname in \
zip(commits, patchnames or (None for i in xrange(len(commits)))):
author_name, author_email, author_date = \
diff --git a/t/t1300-uncommit.sh b/t/t1300-uncommit.sh
index 519234e..2e7ff21 100755
--- a/t/t1300-uncommit.sh
+++ b/t/t1300-uncommit.sh
@@ -70,4 +70,12 @@ test_expect_success \
[ "$(stg id foo-patch//top)" = "$(stg id bar-patch//bottom)" ] &&
stg commit
'
+
+test_expect_success \
+ 'Uncommit the patches with --to' '
+ stg uncommit --to HEAD^ &&
+ [ "$(stg id foo-patch//top)" = "$(stg id bar-patch//bottom)" ] &&
+ stg commit
+'
+
test_done
prev parent reply other threads:[~2007-05-11 1:47 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-11 1:39 [StGIT PATCH 0/5] Some tweaks and enhancements Karl Hasselström
2007-05-11 1:40 ` [StGIT PATCH 1/5] Make the "name" argument to "stg new" optional Karl Hasselström
2007-05-11 1:40 ` [StGIT PATCH 2/5] Generate patch names of more uniform length Karl Hasselström
2007-05-11 1:40 ` [StGIT PATCH 3/5] Remove an unnecessary parameter to make_patch_name Karl Hasselström
2007-05-11 1:40 ` [StGIT PATCH 4/5] If any uncommit would fail, don't uncommit anything Karl Hasselström
2007-05-11 1:40 ` Karl Hasselström [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070511014027.13161.869.stgit@yoghurt \
--to=kha@treskal.com \
--cc=catalin.marinas@gmail.com \
--cc=git@vger.kernel.org \
--cc=pasky@suse.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).