From: Christian Couder <chriscool@tuxfamily.org>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
Johannes Schindelin <Johannes.Schindelin@gmx.de>,
Stephan Beyer <s-beyer@gmx.net>,
Daniel Barkalow <barkalow@iabervon.org>,
Jonathan Nieder <jrnieder@gmail.com>, Jeff King <peff@peff.net>,
Linus Torvalds <torvalds@linux-foundation.org>
Subject: [RFC/PATCH 06/18] revert: remove "commit" global variable
Date: Thu, 25 Nov 2010 22:20:37 +0100 [thread overview]
Message-ID: <20101125212050.5188.99356.chriscool@tuxfamily.org> (raw)
In-Reply-To: <20101125210138.5188.13115.chriscool@tuxfamily.org>
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
builtin/revert.c | 49 ++++++++++++++++++++++++-------------------------
1 files changed, 24 insertions(+), 25 deletions(-)
diff --git a/builtin/revert.c b/builtin/revert.c
index 947e666..e3dea19 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -38,7 +38,6 @@ static const char * const cherry_pick_usage[] = {
static int edit, no_replay, no_commit, mainline, signoff, allow_ff;
static enum { REVERT, CHERRY_PICK } action;
-static struct commit *commit;
static int commit_argc;
static const char **commit_argv;
static int allow_rerere_auto;
@@ -48,7 +47,7 @@ static const char *strategy;
#define GIT_REFLOG_ACTION "GIT_REFLOG_ACTION"
-static char *get_encoding(const char *message);
+static char *get_encoding(const char *message, const unsigned char *sha1);
static const char * const *revert_or_cherry_pick_usage(void)
{
@@ -99,7 +98,8 @@ struct commit_message {
const char *message;
};
-static int get_message(const char *raw_message, struct commit_message *out)
+static int get_message(const char *raw_message, const unsigned char *sha1,
+ struct commit_message *out)
{
const char *encoding;
const char *abbrev, *subject;
@@ -108,7 +108,7 @@ static int get_message(const char *raw_message, struct commit_message *out)
if (!raw_message)
return -1;
- encoding = get_encoding(raw_message);
+ encoding = get_encoding(raw_message, sha1);
if (!encoding)
encoding = "UTF-8";
if (!git_commit_encoding)
@@ -122,7 +122,7 @@ static int get_message(const char *raw_message, struct commit_message *out)
if (out->reencoded_message)
out->message = out->reencoded_message;
- abbrev = find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV);
+ abbrev = find_unique_abbrev(sha1, DEFAULT_ABBREV);
abbrev_len = strlen(abbrev);
subject_len = find_commit_subject(out->message, &subject);
@@ -146,13 +146,12 @@ static void free_message(struct commit_message *msg)
free(msg->reencoded_message);
}
-static char *get_encoding(const char *message)
+static char *get_encoding(const char *message, const unsigned char *sha1)
{
const char *p = message, *eol;
if (!p)
- die ("Could not read commit message of %s",
- sha1_to_hex(commit->object.sha1));
+ die ("Could not read commit message of %s", sha1_to_hex(sha1));
while (*p && *p != '\n') {
for (eol = p + 1; *eol && *eol != '\n'; eol++)
; /* do nothing */
@@ -168,25 +167,25 @@ static char *get_encoding(const char *message)
return NULL;
}
-static void add_message_to_msg(struct strbuf *msgbuf, const char *message)
+static void add_message_to_msg(struct strbuf *msgbuf, const char *message,
+ const unsigned char *sha1)
{
const char *p = message;
while (*p && (*p != '\n' || p[1] != '\n'))
p++;
if (!*p)
- strbuf_addstr(msgbuf, sha1_to_hex(commit->object.sha1));
+ strbuf_addstr(msgbuf, sha1_to_hex(sha1));
p += 2;
strbuf_addstr(msgbuf, p);
}
-static void set_author_ident_env(const char *message)
+static void set_author_ident_env(const char *message, const unsigned char *sha1)
{
const char *p = message;
if (!p)
- die ("Could not read commit message of %s",
- sha1_to_hex(commit->object.sha1));
+ die ("Could not read commit message of %s", sha1_to_hex(sha1));
while (*p && *p != '\n') {
const char *eol;
@@ -200,7 +199,7 @@ static void set_author_ident_env(const char *message)
email = strchr(line, '<');
if (!email)
die ("Could not extract author email from %s",
- sha1_to_hex(commit->object.sha1));
+ sha1_to_hex(sha1));
if (email == line)
pend = line;
else
@@ -212,7 +211,7 @@ static void set_author_ident_env(const char *message)
timestamp = strchr(email, '>');
if (!timestamp)
die ("Could not extract author time from %s",
- sha1_to_hex(commit->object.sha1));
+ sha1_to_hex(sha1));
*timestamp = '\0';
for (timestamp++; *timestamp && isspace(*timestamp);
timestamp++)
@@ -227,8 +226,7 @@ static void set_author_ident_env(const char *message)
if (*p == '\n')
p++;
}
- die ("No author information found in %s",
- sha1_to_hex(commit->object.sha1));
+ die ("No author information found in %s", sha1_to_hex(sha1));
}
static void advise(const char *advice, ...)
@@ -240,7 +238,7 @@ static void advise(const char *advice, ...)
va_end(params);
}
-static void print_advice(void)
+static void print_advice(const unsigned char *sha1)
{
char *msg = getenv("GIT_CHERRY_PICK_HELP");
@@ -254,7 +252,7 @@ static void print_advice(void)
if (action == CHERRY_PICK)
advise("and commit the result with 'git commit -c %s'",
- find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV));
+ find_unique_abbrev(sha1, DEFAULT_ABBREV));
}
static int write_message(struct strbuf *msgbuf, const char *filename)
@@ -391,7 +389,7 @@ static int run_git_commit(const char *defmsg)
return run_command_v_opt(args, RUN_GIT_CMD);
}
-static int do_pick_commit(void)
+static int do_pick_commit(struct commit *commit)
{
unsigned char head[20];
struct commit *base, *next, *parent;
@@ -452,7 +450,7 @@ static int do_pick_commit(void)
return error("%s: cannot parse parent commit %s",
me, sha1_to_hex(parent->object.sha1));
- if (get_message(commit->buffer, &msg) != 0)
+ if (get_message(commit->buffer, commit->object.sha1, &msg) != 0)
return error("Cannot get commit message for %s",
sha1_to_hex(commit->object.sha1));
@@ -485,8 +483,8 @@ static int do_pick_commit(void)
base_label = msg.parent_label;
next = commit;
next_label = msg.label;
- set_author_ident_env(msg.message);
- add_message_to_msg(&msgbuf, msg.message);
+ set_author_ident_env(msg.message, commit->object.sha1);
+ add_message_to_msg(&msgbuf, msg.message, commit->object.sha1);
if (no_replay) {
strbuf_addstr(&msgbuf, "(cherry picked from commit ");
strbuf_addstr(&msgbuf, sha1_to_hex(commit->object.sha1));
@@ -521,7 +519,7 @@ static int do_pick_commit(void)
action == REVERT ? "revert" : "apply",
find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV),
msg.subject);
- print_advice();
+ print_advice(commit->object.sha1);
rerere(allow_rerere_auto);
} else {
if (!no_commit)
@@ -572,6 +570,7 @@ static void read_and_refresh_cache(const char *me)
static int revert_or_cherry_pick(int argc, const char **argv)
{
struct rev_info revs;
+ struct commit *commit;
git_config(git_default_config, NULL);
me = action == REVERT ? "revert" : "cherry-pick";
@@ -594,7 +593,7 @@ static int revert_or_cherry_pick(int argc, const char **argv)
prepare_revs(&revs);
while ((commit = get_revision(&revs))) {
- int res = do_pick_commit();
+ int res = do_pick_commit(commit);
if (res)
return res;
}
--
1.7.3.2.504.g59d466
next prev parent reply other threads:[~2010-11-26 5:54 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-25 21:20 [RFC/PATCH 00/18] WIP implement cherry-pick/revert --continue Christian Couder
2010-11-25 21:20 ` [RFC/PATCH 01/18] advice: add error_resolve_conflict() function Christian Couder
2010-11-26 5:56 ` Jonathan Nieder
2010-11-25 21:20 ` [RFC/PATCH 02/18] revert: change many die() calls into "return error()" calls Christian Couder
2010-11-26 6:05 ` Jonathan Nieder
2010-11-25 21:20 ` [RFC/PATCH 03/18] usage: implement error_errno() the same way as die_errno() Christian Couder
2010-11-26 6:07 ` Jonathan Nieder
2010-11-26 18:35 ` Junio C Hamano
2010-11-25 21:20 ` [RFC/PATCH 04/18] revert: don't die when write_message() fails Christian Couder
2010-11-25 21:20 ` [RFC/PATCH 05/18] commit: move reverse_commit_list() into commit.{h, c} Christian Couder
2010-11-25 21:20 ` Christian Couder [this message]
2010-11-25 21:20 ` [RFC/PATCH 07/18] revert: put option information in an option struct Christian Couder
2010-11-26 6:18 ` Jonathan Nieder
2010-11-26 18:42 ` Junio C Hamano
2010-11-25 21:20 ` [RFC/PATCH 08/18] revert: refactor code into a new pick_commits() function Christian Couder
2010-11-27 3:50 ` Daniel Barkalow
2010-11-25 21:20 ` [RFC/PATCH 09/18] revert: make pick_commits() return an error on --ff incompatible option Christian Couder
2010-11-25 21:20 ` [RFC/PATCH 10/18] revert: make read_and_refresh_cache() and prepare_revs() return errors Christian Couder
2010-11-25 21:20 ` [RFC/PATCH 11/18] revert: add get_todo_content() and create_todo_file() Christian Couder
2010-11-25 21:20 ` [RFC/PATCH 12/18] revert: write TODO and DONE files in case of failure Christian Couder
2010-11-25 21:20 ` [RFC/PATCH 13/18] revert: add option parsing for option --continue Christian Couder
2010-11-25 21:20 ` [RFC/PATCH 14/18] revert: move global variable "me" into "struct args_info" Christian Couder
2010-11-25 21:20 ` [RFC/PATCH 15/18] revert: add NONE action and make parse_args() manage it Christian Couder
2010-11-25 21:20 ` [RFC/PATCH 16/18] revert: implement parsing TODO and DONE files Christian Couder
2010-11-25 21:20 ` [RFC/PATCH 17/18] revert: add remaining instructions in todo file Christian Couder
2010-11-25 21:20 ` [RFC/PATCH 18/18] revert: implement --continue processing Christian Couder
2010-11-26 6:28 ` [RFC/PATCH 00/18] WIP implement cherry-pick/revert --continue Jonathan Nieder
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=20101125212050.5188.99356.chriscool@tuxfamily.org \
--to=chriscool@tuxfamily.org \
--cc=Johannes.Schindelin@gmx.de \
--cc=barkalow@iabervon.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jrnieder@gmail.com \
--cc=peff@peff.net \
--cc=s-beyer@gmx.net \
--cc=torvalds@linux-foundation.org \
/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).