From: Christian Couder <chriscool@tuxfamily.org>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org,
Johannes Schindelin <Johannes.Schindelin@gmx.de>,
Sverre Rabbelier <srabbelier@gmail.com>,
Ramkumar Ramachandra <artagnon@gmail.com>,
Jonathan Nieder <jrnieder@gmail.com>, Jeff King <peff@peff.net>
Subject: [PATCH] revert: add --stdin option to read commits from stdin
Date: Mon, 14 Jun 2010 05:22:50 +0200 [thread overview]
Message-ID: <20100614032251.20121.83253.chriscool@tuxfamily.org> (raw)
This can be useful to do something like:
git rev-list --reverse master -- README | git cherry-pick -n --stdin
without using xargs.
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
This applies on top of pu as it is related to my cherry-pick
many commits series.
Documentation/git-cherry-pick.txt | 14 +++++++++++++-
Documentation/git-revert.txt | 6 +++++-
builtin/revert.c | 9 ++++++---
t/t3508-cherry-pick-many-commits.sh | 10 ++++++++++
4 files changed, 34 insertions(+), 5 deletions(-)
diff --git a/Documentation/git-cherry-pick.txt b/Documentation/git-cherry-pick.txt
index bcb4c75..54e6833 100644
--- a/Documentation/git-cherry-pick.txt
+++ b/Documentation/git-cherry-pick.txt
@@ -7,7 +7,8 @@ git-cherry-pick - Apply the changes introduced by some existing commits
SYNOPSIS
--------
-'git cherry-pick' [--edit] [-n] [-m parent-number] [-s] [-x] [--ff] <commit>...
+'git cherry-pick' [--edit] [-n] [-m parent-number] [-s] [-x] [--ff] [--stdin]
+ <commit>...
DESCRIPTION
-----------
@@ -79,6 +80,10 @@ effect to your index in a row.
cherry-pick'ed commit, then a fast forward to this commit will
be performed.
+--stdin::
+ In addition to the '<commit>' listed on the command
+ line, read them from the standard input.
+
EXAMPLES
--------
git cherry-pick master::
@@ -113,6 +118,13 @@ git cherry-pick --ff ..next::
are in next but not HEAD to the current branch, creating a new
commit for each new change.
+git rev-list --reverse master -- README | git cherry-pick -n --stdin::
+
+ Apply the changes introduced by all commits on the master
+ branch that touched README to the working tree and index,
+ so the result can be inspected and made into a single new
+ commit if suitable.
+
Author
------
Written by Junio C Hamano <gitster@pobox.com>
diff --git a/Documentation/git-revert.txt b/Documentation/git-revert.txt
index dea4f53..84b4a68 100644
--- a/Documentation/git-revert.txt
+++ b/Documentation/git-revert.txt
@@ -7,7 +7,7 @@ git-revert - Revert some existing commits
SYNOPSIS
--------
-'git revert' [--edit | --no-edit] [-n] [-m parent-number] [-s] <commit>...
+'git revert' [--edit | --no-edit] [-n] [-m parent-number] [-s] [--stdin] <commit>...
DESCRIPTION
-----------
@@ -80,6 +80,10 @@ effect to your index in a row.
--signoff::
Add Signed-off-by line at the end of the commit message.
+--stdin::
+ In addition to the '<commit>' listed on the command
+ line, read them from the standard input.
+
EXAMPLES
--------
git revert HEAD~3::
diff --git a/builtin/revert.c b/builtin/revert.c
index 853e9e4..2b3d5a5 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -41,7 +41,7 @@ static enum { REVERT, CHERRY_PICK } action;
static struct commit *commit;
static int commit_argc;
static const char **commit_argv;
-static int allow_rerere_auto;
+static int allow_rerere_auto, read_stdin;
static const char *me;
static const char *strategy;
@@ -63,6 +63,7 @@ static void parse_args(int argc, const char **argv)
OPT_INTEGER('m', "mainline", &mainline, "parent number"),
OPT_RERERE_AUTOUPDATE(&allow_rerere_auto),
OPT_STRING(0, "strategy", &strategy, "strategy", "merge strategy"),
+ OPT_BOOLEAN(0, "stdin", &read_stdin, "read commits from stdin"),
OPT_END(),
OPT_END(),
OPT_END(),
@@ -79,7 +80,7 @@ static void parse_args(int argc, const char **argv)
}
commit_argc = parse_options(argc, argv, NULL, options, usage_str, 0);
- if (commit_argc < 1)
+ if (commit_argc < 1 && !read_stdin)
usage_with_options(usage_str, options);
commit_argv = argv;
@@ -527,10 +528,12 @@ static void prepare_revs(struct rev_info *revs)
{
int argc = 0;
int i;
- const char **argv = xmalloc((commit_argc + 4) * sizeof(*argv));
+ const char **argv = xmalloc((commit_argc + 5) * sizeof(*argv));
argv[argc++] = NULL;
argv[argc++] = "--no-walk";
+ if (read_stdin)
+ argv[argc++] = "--stdin";
if (action != REVERT)
argv[argc++] = "--reverse";
for (i = 0; i < commit_argc; i++)
diff --git a/t/t3508-cherry-pick-many-commits.sh b/t/t3508-cherry-pick-many-commits.sh
index 3b87efe..27096f1 100755
--- a/t/t3508-cherry-pick-many-commits.sh
+++ b/t/t3508-cherry-pick-many-commits.sh
@@ -92,4 +92,14 @@ test_expect_failure 'cherry-pick -3 fourth works' '
test "$(git rev-parse --verify HEAD)" != "$(git rev-parse --verify fourth)"
'
+test_expect_success 'cherry-pick --stdin works' '
+ git checkout master &&
+ git reset --hard first &&
+ test_tick &&
+ git rev-list --reverse first..fourth | git cherry-pick --stdin &&
+ git diff --quiet other &&
+ git diff --quiet HEAD other &&
+ test "$(git rev-parse --verify HEAD)" != "$(git rev-parse --verify fourth)"
+'
+
test_done
--
1.7.1.468.g77401.dirty
next reply other threads:[~2010-06-14 3:33 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-14 3:22 Christian Couder [this message]
2010-06-14 5:20 ` [PATCH] revert: add --stdin option to read commits from stdin Jonathan Nieder
2010-06-14 5:28 ` [PATCH 1/3] t3508 (cherry-pick): futureproof against unmerged files Jonathan Nieder
2010-06-14 5:29 ` [PATCH 2/3] revert: accept arbitrary rev-list options Jonathan Nieder
2010-06-14 5:32 ` [PATCH 3/3] revert: do not rebuild argv on heap Jonathan Nieder
2010-06-15 3:28 ` [PATCH] revert: add --stdin option to read commits from stdin Christian Couder
2010-06-14 6:20 ` Johannes Sixt
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=20100614032251.20121.83253.chriscool@tuxfamily.org \
--to=chriscool@tuxfamily.org \
--cc=Johannes.Schindelin@gmx.de \
--cc=artagnon@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jrnieder@gmail.com \
--cc=peff@peff.net \
--cc=srabbelier@gmail.com \
/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).