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

[RFC/PATCH 14/18] revert: move global variable "me" into "struct args_info"

From
Christian Couder <chriscool@tuxfamily.org>
Date
Nov 25, 2010, 21:20 UTC
Message-ID
<20101125212050.5188.49554.chriscool@tuxfamily.org>
In-Reply-To
<20101125210138.5188.13115.chriscool@tuxfamily.org>
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 builtin/revert.c |   19 ++++++++++---------
 1 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/builtin/revert.c b/builtin/revert.c
index 12a2409..7513a00 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -39,8 +39,6 @@ static const char * const cherry_pick_usage[] = {
 	NULL
 };
 
-static const char *me;
-
 struct args_info {
 	enum { REVERT, CHERRY_PICK } action;
 	int edit;
@@ -51,6 +49,7 @@ struct args_info {
 	int allow_ff;
 	int allow_rerere_auto;
 	int continuing;
+	const char *me;
 	const char *strategy;
 	const char **commit_argv;
 	int commit_argc;
@@ -91,6 +90,9 @@ static void parse_args(int argc, const char **argv, struct args_info *info)
 		OPT_END(),
 	};
 
+	info->me = info->action == REVERT ? "revert" : "cherry-pick";
+	setenv(GIT_REFLOG_ACTION, info->me, 0);
+
 	if (info->action == CHERRY_PICK) {
 		struct option cp_extra[] = {
 			OPT_BOOLEAN('x', NULL, &info->no_replay, "append commit name"),
@@ -403,7 +405,8 @@ static int fast_forward_to(const unsigned char *to, const unsigned char *from)
 
 static int do_recursive_merge(struct commit *base, struct commit *next,
 			      const char *base_label, const char *next_label,
-			      unsigned char *head, struct strbuf *msgbuf)
+			      unsigned char *head, const char *me,
+			      struct strbuf *msgbuf)
 {
 	struct merge_options o;
 	struct tree *result, *next_tree, *base_tree, *head_tree;
@@ -507,7 +510,7 @@ static int do_pick_commit(struct args_info *info, struct commit *commit)
 		if (get_sha1("HEAD", head))
 			return error("You do not have a valid HEAD");
 		if (index_differs_from("HEAD", 0))
-			return error_dirty_index(me);
+			return error_dirty_index(info->me);
 	}
 	discard_cache();
 
@@ -543,7 +546,7 @@ static int do_pick_commit(struct args_info *info, struct commit *commit)
 
 	if (parent && parse_commit(parent) < 0)
 		return error("%s: cannot parse parent commit %s",
-			     me, sha1_to_hex(parent->object.sha1));
+			     info->me, sha1_to_hex(parent->object.sha1));
 
 	if (get_message(commit->buffer, commit->object.sha1, &msg) != 0)
 		return error("Cannot get commit message for %s",
@@ -590,7 +593,7 @@ static int do_pick_commit(struct args_info *info, struct commit *commit)
 	if (!info->strategy || !strcmp(info->strategy, "recursive") ||
 	    info->action == REVERT) {
 		res = do_recursive_merge(base, next, base_label, next_label,
-					 head, &msgbuf);
+					 head, info->me, &msgbuf);
 		write_res = write_message(&msgbuf, defmsg);
 		if (write_res)
 			return write_res;
@@ -704,7 +707,7 @@ static int pick_commits(struct args_info *infos, struct commit_list **done_list)
 	     (res = ff_incompatible(infos->edit, "--edit"))))
 		return save_todo_and_done(res, infos, NULL, NULL, done_list);
 
-	if ((res = read_and_refresh_cache(me)) ||
+	if ((res = read_and_refresh_cache(infos->me)) ||
 	    (res = prepare_revs(&revs, infos)))
 		return save_todo_and_done(res, infos, NULL, NULL, done_list);
 
@@ -722,8 +725,6 @@ static int revert_or_cherry_pick(int argc, const char **argv, int revert, int ed
 	int res;
 
 	git_config(git_default_config, NULL);
-	me = revert ? "revert" : "cherry-pick";
-	setenv(GIT_REFLOG_ACTION, me, 0);
 	memset(&infos, 0, sizeof(infos));
 	infos.action = revert ? REVERT : CHERRY_PICK;
 	parse_args(argc, argv, &infos);
-- 
1.7.3.2.504.g59d466
Previous: Christian CouderNext: Christian Couder
Message 22 of 27 in “WIP implement cherry-pick/revert --continue”
  1. 00/18 WIP implement cherry-pick/revert --continueChristian Couder, Nov 25, 2010
  2. 01/18 advice: add error_resolve_conflict() functionChristian Couder, Nov 25, 2010
  3. Jonathan NiederNov 26, 2010
  4. 02/18 revert: change many die() calls into "return error()" callsChristian Couder, Nov 25, 2010
  5. Jonathan NiederNov 26, 2010
  6. 03/18 usage: implement error_errno() the same way as die_errno()Christian Couder, Nov 25, 2010
  7. Jonathan NiederNov 26, 2010
  8. Junio C HamanoNov 26, 2010
  9. 04/18 revert: don't die when write_message() failsChristian Couder, Nov 25, 2010
  10. 05/18 commit: move reverse_commit_list() into commit.{h, c}Christian Couder, Nov 25, 2010
  11. 06/18 revert: remove "commit" global variableChristian Couder, Nov 25, 2010
  12. 07/18 revert: put option information in an option structChristian Couder, Nov 25, 2010
  13. Jonathan NiederNov 26, 2010
  14. Junio C HamanoNov 26, 2010
  15. 08/18 revert: refactor code into a new pick_commits() functionChristian Couder, Nov 25, 2010
  16. Daniel BarkalowNov 27, 2010
  17. 09/18 revert: make pick_commits() return an error on --ff incompatible optionChristian Couder, Nov 25, 2010
  18. 10/18 revert: make read_and_refresh_cache() and prepare_revs() return errorsChristian Couder, Nov 25, 2010
  19. 11/18 revert: add get_todo_content() and create_todo_file()Christian Couder, Nov 25, 2010
  20. 12/18 revert: write TODO and DONE files in case of failureChristian Couder, Nov 25, 2010
  21. 13/18 revert: add option parsing for option --continueChristian Couder, Nov 25, 2010
  22. 14/18 revert: move global variable "me" into "struct args_info"Christian Couder, Nov 25, 2010
  23. 15/18 revert: add NONE action and make parse_args() manage itChristian Couder, Nov 25, 2010
  24. 16/18 revert: implement parsing TODO and DONE filesChristian Couder, Nov 25, 2010
  25. 17/18 revert: add remaining instructions in todo fileChristian Couder, Nov 25, 2010
  26. 18/18 revert: implement --continue processingChristian Couder, Nov 25, 2010
  27. Jonathan NiederNov 26, 2010

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.