git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] revert: add --stdin option to read commits from stdin
@ 2010-06-14  3:22 Christian Couder
  2010-06-14  5:20 ` Jonathan Nieder
  2010-06-14  6:20 ` Johannes Sixt
  0 siblings, 2 replies; 7+ messages in thread
From: Christian Couder @ 2010-06-14  3:22 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: git, Johannes Schindelin, Sverre Rabbelier, Ramkumar Ramachandra,
	Jonathan Nieder, Jeff King

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

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2010-06-15  3:36 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-14  3:22 [PATCH] revert: add --stdin option to read commits from stdin Christian Couder
2010-06-14  5:20 ` 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

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).