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

Re: [PATCH 5/6] sequencer: Expose API to cherry-picking machinery

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Aug 13, 2011, 17:06 UTC
Message-ID
<20110813170623.GB1494@elie.gateway.2wire.net>
In-Reply-To
<CALkWK0migSRUmhPp0069O_NiRs3gQJbrU8QLdwUJ-kUYAsLz4Q@mail.gmail.com>
Ramkumar Ramachandra wrote:
> Jonathan Nieder writes:
Show 8 quoted lines
>> Another thought.  I wonder if it's possible to leave
>> sequencer_parse_args() private to builtin/revert.c, making the split
>> a little more logical:
>
> Yes, I'd like this too.  However, there are two new issues:
> revert_or_cherry_pick_usage and action_name.  The former has two
> callsites: one in prepare_revs (in sequencer.c) and another in
> parse_args (in builtin/revert.c).

So it sounds like the answer is "no, it's not possible without further changes". Alas. :) Thanks for checking.

(Q. Wait, what further changes?
 A. The above suggests that the setup_revisions call should also be
    the responsibility of the builtin, and that it could communicate
    revs and other rev-list options using a
	struct rev_info *revs;
    instead of
	int commit_argc;
	const char **commit_argv;
    Like this, maybe:
 builtin/revert.c |   52 ++++++++++++++++++++++++++++++----------------------
 1 files changed, 30 insertions(+), 22 deletions(-)
diff --git i/builtin/revert.c w/builtin/revert.c
index 8b452e81..f602ece0 100644
--- i/builtin/revert.c
+++ w/builtin/revert.c
@@ -55,13 +55,14 @@ struct replay_opts {
 	int allow_rerere_auto;
 
 	int mainline;
-	int commit_argc;
-	const char **commit_argv;
 
 	/* Merge strategy */
 	const char *strategy;
 	const char **xopts;
 	size_t xopts_nr, xopts_alloc;
+
+	/* Only used by the default subcommand ("git revert <revs>") */
+	struct rev_info *revs;
 };
 
 #define GIT_REFLOG_ACTION "GIT_REFLOG_ACTION"
@@ -164,7 +165,7 @@ static void parse_args(int argc, const char **argv, struct replay_opts *opts)
 			die(_("program error"));
 	}
 
-	opts->commit_argc = parse_options(argc, argv, NULL, options, usage_str,
+	argc = parse_options(argc, argv, NULL, options, usage_str,
 					PARSE_OPT_KEEP_ARGV0 |
 					PARSE_OPT_KEEP_UNKNOWN);
 
@@ -201,9 +202,6 @@ static void parse_args(int argc, const char **argv, struct replay_opts *opts)
 				NULL);
 	}
 
-	else if (opts->commit_argc < 2)
-		usage_with_options(usage_str, options);
-
 	if (opts->allow_ff)
 		verify_opt_compatible(me, "--ff",
 				"--signoff", opts->signoff,
@@ -211,7 +209,23 @@ static void parse_args(int argc, const char **argv, struct replay_opts *opts)
 				"-x", opts->record_origin,
 				"--edit", opts->edit,
 				NULL);
-	opts->commit_argv = argv;
+
+	if (opts->subcommand != REPLAY_NONE) {
+		opts->revs = NULL;
+		if (argc > 1)
+			usage_with_options(usage_str, options);
+	} else {
+		opts->revs = xmalloc(sizeof(*opts->revs));
+		init_revisions(opts->revs, NULL);
+		opts->revs->no_walk = 1;
+
+		if (argc < 2)
+			usage_with_options(usage_str, options);
+
+		argc = setup_revisions(argc, argv, opts->revs, NULL);
+		if (argc > 1)
+			usage_with_options(usage_str, options);
+	}
 }
 
 struct commit_message {
@@ -612,23 +626,15 @@ static int do_pick_commit(struct commit *commit, struct replay_opts *opts)
 	return res;
 }
 
-static void prepare_revs(struct rev_info *revs, struct replay_opts *opts)
+static void prepare_revs(struct replay_opts *opts)
 {
-	int argc;
-
-	init_revisions(revs, NULL);
-	revs->no_walk = 1;
 	if (opts->action != REVERT)
-		revs->reverse = 1;
+		opts->revs->reverse ^= 1;
 
-	argc = setup_revisions(opts->commit_argc, opts->commit_argv, revs, NULL);
-	if (argc > 1)
-		usage(*revert_or_cherry_pick_usage(opts));
-
-	if (prepare_revision_walk(revs))
+	if (prepare_revision_walk(opts->revs))
 		die(_("revision walk setup failed"));
 
-	if (!revs->commits)
+	if (!opts->revs->commits)
 		die(_("empty commit set passed"));
 }
 
@@ -825,14 +831,13 @@ static void read_populate_opts(struct replay_opts **opts_ptr)
 static void walk_revs_populate_todo(struct commit_list **todo_list,
 				struct replay_opts *opts)
 {
-	struct rev_info revs;
 	struct commit *commit;
 	struct commit_list **next;
 
-	prepare_revs(&revs, opts);
+	prepare_revs(opts);
 
 	next = todo_list;
-	while ((commit = get_revision(&revs)))
+	while ((commit = get_revision(opts->revs)))
 		next = commit_list_append(commit, next);
 }
 
@@ -955,6 +960,9 @@ static int pick_revisions(struct replay_opts *opts)
 	struct commit_list *todo_list = NULL;
 	unsigned char sha1[20];
 
+	if (opts->subcommand == REPLAY_NONE)
+		assert(opts->revs);
+
 	read_and_refresh_cache(opts);
 
 	/*
-- 
)
Previous: Jonathan NiederNext: Ramkumar Ramachandra
Message 23 of 31 in “Towards a generalized sequencer”
  1. 0/6 Towards a generalized sequencerRamkumar Ramachandra, Aug 11, 2011
  2. 1/6 revert: Don't remove the sequencer state on errorRamkumar Ramachandra, Aug 11, 2011
  3. Jonathan NiederAug 11, 2011
  4. Ramkumar RamachandraAug 13, 2011
  5. 2/6 revert: Free memory after get_message callRamkumar Ramachandra, Aug 11, 2011
  6. Jonathan NiederAug 11, 2011
  7. Ramkumar RamachandraAug 12, 2011
  8. 3/6 revert: Parse instruction sheet more cautiouslyRamkumar Ramachandra, Aug 11, 2011
  9. Jonathan NiederAug 11, 2011
  10. 4/6 revert: Allow mixed pick and revert instructionsRamkumar Ramachandra, Aug 11, 2011
  11. Jonathan NiederAug 11, 2011
  12. Ramkumar RamachandraAug 13, 2011
  13. 5/6 sequencer: Expose API to cherry-picking machineryRamkumar Ramachandra, Aug 11, 2011
  14. Jonathan NiederAug 11, 2011
  15. Jonathan NiederAug 11, 2011
  16. Junio C HamanoAug 11, 2011
  17. Ramkumar RamachandraAug 13, 2011
  18. Daniel BarkalowAug 13, 2011
  19. Ramkumar RamachandraAug 13, 2011
  20. Reusing changes after renaming a file (Re: [PATCH 5/6] sequencer: Expose API to cherry-picking machinery)Jonathan Nieder, Aug 13, 2011
  21. Ramkumar RamachandraAug 13, 2011
  22. Jonathan NiederAug 13, 2011
  23. Jonathan NiederAug 13, 2011
  24. Ramkumar RamachandraAug 13, 2011
  25. 6/6 sequencer: Remove sequencer state after final commitRamkumar Ramachandra, Aug 11, 2011
  26. Jonathan NiederAug 11, 2011
  27. Ramkumar RamachandraAug 12, 2011
  28. Jonathan NiederAug 11, 2011
  29. Ramkumar RamachandraAug 12, 2011
  30. Jonathan NiederAug 12, 2011
  31. Ramkumar RamachandraAug 12, 2011

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.