aboutsummaryrefslogtreecommitdiff
path: root/builtin/revert.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2011-03-09 15:56:17 -0800
committerJunio C Hamano <gitster@pobox.com>2011-03-09 15:56:17 -0800
commit66ecd2d05306fccc65e8d6a5f49100840ea7d3b6 (patch)
tree159eaf1f118e602f3a397ede9dc2b386a96b627a /builtin/revert.c
parent75618f1106b95defafca698d5cfdfd3dfb3a7e3c (diff)
parent37f7a8579363a98efc48dfb6964a519034fc9acc (diff)
downloadgit-66ecd2d05306fccc65e8d6a5f49100840ea7d3b6.tar.gz
git-66ecd2d05306fccc65e8d6a5f49100840ea7d3b6.tar.xz
Merge branch 'js/cherry-pick-usability'
* js/cherry-pick-usability: Teach commit about CHERRY_PICK_HEAD bash: teach __git_ps1 about CHERRY_PICK_HEAD Introduce CHERRY_PICK_HEAD t3507: introduce pristine-detach helper
Diffstat (limited to 'builtin/revert.c')
-rw-r--r--builtin/revert.c75
1 files changed, 22 insertions, 53 deletions
diff --git a/builtin/revert.c b/builtin/revert.c
index dc1b702ed..c57b872fe 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -3,7 +3,6 @@
#include "object.h"
#include "commit.h"
#include "tag.h"
-#include "wt-status.h"
#include "run-command.h"
#include "exec_cmd.h"
#include "utf8.h"
@@ -198,54 +197,20 @@ static void add_message_to_msg(struct strbuf *msgbuf, const char *message)
strbuf_addstr(msgbuf, p);
}
-static void set_author_ident_env(const char *message)
+static void write_cherry_pick_head(void)
{
- const char *p = message;
- if (!p)
- die ("Could not read commit message of %s",
- sha1_to_hex(commit->object.sha1));
- while (*p && *p != '\n') {
- const char *eol;
-
- for (eol = p; *eol && *eol != '\n'; eol++)
- ; /* do nothing */
- if (!prefixcmp(p, "author ")) {
- char *line, *pend, *email, *timestamp;
-
- p += 7;
- line = xmemdupz(p, eol - p);
- email = strchr(line, '<');
- if (!email)
- die ("Could not extract author email from %s",
- sha1_to_hex(commit->object.sha1));
- if (email == line)
- pend = line;
- else
- for (pend = email; pend != line + 1 &&
- isspace(pend[-1]); pend--);
- ; /* do nothing */
- *pend = '\0';
- email++;
- timestamp = strchr(email, '>');
- if (!timestamp)
- die ("Could not extract author time from %s",
- sha1_to_hex(commit->object.sha1));
- *timestamp = '\0';
- for (timestamp++; *timestamp && isspace(*timestamp);
- timestamp++)
- ; /* do nothing */
- setenv("GIT_AUTHOR_NAME", line, 1);
- setenv("GIT_AUTHOR_EMAIL", email, 1);
- setenv("GIT_AUTHOR_DATE", timestamp, 1);
- free(line);
- return;
- }
- p = eol;
- if (*p == '\n')
- p++;
- }
- die ("No author information found in %s",
- sha1_to_hex(commit->object.sha1));
+ int fd;
+ struct strbuf buf = STRBUF_INIT;
+
+ strbuf_addf(&buf, "%s\n", sha1_to_hex(commit->object.sha1));
+
+ fd = open(git_path("CHERRY_PICK_HEAD"), O_WRONLY | O_CREAT, 0666);
+ if (fd < 0)
+ die_errno("Could not open '%s' for writing",
+ git_path("CHERRY_PICK_HEAD"));
+ if (write_in_full(fd, buf.buf, buf.len) != buf.len || close(fd))
+ die_errno("Could not write to '%s'", git_path("CHERRY_PICK_HEAD"));
+ strbuf_release(&buf);
}
static void advise(const char *advice, ...)
@@ -263,15 +228,18 @@ static void print_advice(void)
if (msg) {
fprintf(stderr, "%s\n", msg);
+ /*
+ * A conflict has occured but the porcelain
+ * (typically rebase --interactive) wants to take care
+ * of the commit itself so remove CHERRY_PICK_HEAD
+ */
+ unlink(git_path("CHERRY_PICK_HEAD"));
return;
}
advise("after resolving the conflicts, mark the corrected paths");
advise("with 'git add <paths>' or 'git rm <paths>'");
-
- if (action == CHERRY_PICK)
- advise("and commit the result with 'git commit -c %s'",
- find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV));
+ advise("and commit the result with 'git commit'");
}
static void write_message(struct strbuf *msgbuf, const char *filename)
@@ -497,13 +465,14 @@ 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);
if (no_replay) {
strbuf_addstr(&msgbuf, "(cherry picked from commit ");
strbuf_addstr(&msgbuf, sha1_to_hex(commit->object.sha1));
strbuf_addstr(&msgbuf, ")\n");
}
+ if (!no_commit)
+ write_cherry_pick_head();
}
if (!strategy || !strcmp(strategy, "recursive") || action == REVERT) {