From: Phillip Wood <[email protected]>
Signed-off-by: Phillip Wood <[email protected]>
---
builtin/commit.c | 42 +-----------------------------------------
sequencer.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
sequencer.h | 2 ++
3 files changed, 49 insertions(+), 41 deletions(-)
diff --git a/builtin/commit.c b/builtin/commit.c
index
497778ba2c02afdd4a337969a27ca781e8389040..9d621098823d196643180226491e43c806154c13
100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -31,9 +31,7 @@
#include "gpg-interface.h"
#include "column.h"
#include "sequencer.h"
-#include "notes-utils.h"
#include "mailmap.h"
-#include "sigchain.h"
static const char * const builtin_commit_usage[] = {
N_("git commit [<options>] [--] <pathspec>..."),
@@ -1465,37 +1463,6 @@ static int git_commit_config(const char *k, const char
*v, void *cb)
return git_status_config(k, v, s);
}
-static int run_rewrite_hook(const struct object_id *oldoid,
- const struct object_id *newoid)
-{
- struct child_process proc = CHILD_PROCESS_INIT;
- const char *argv[3];
- int code;
- struct strbuf sb = STRBUF_INIT;
-
- argv[0] = find_hook("post-rewrite");
- if (!argv[0])
- return 0;
-
- argv[1] = "amend";
- argv[2] = NULL;
-
- proc.argv = argv;
- proc.in = -1;
- proc.stdout_to_stderr = 1;
-
- code = start_command(&proc);
- if (code)
- return code;
- strbuf_addf(&sb, "%s %s\n", oid_to_hex(oldoid), oid_to_hex(newoid));
- sigchain_push(SIGPIPE, SIG_IGN);
- write_in_full(proc.in, sb.buf, sb.len);
- close(proc.in);
- strbuf_release(&sb);
- sigchain_pop(SIGPIPE);
- return finish_command(&proc);
-}
-
int run_commit_hook(int editor_is_used, const char *index_file, const char
*name, ...)
{
struct argv_array hook_env = ARGV_ARRAY_INIT;
@@ -1725,14 +1692,7 @@ int cmd_commit(int argc, const char **argv, const char
*prefix)
rerere(0);
run_commit_hook(use_editor, get_index_file(), "post-commit", NULL);
if (amend && !no_post_rewrite) {
- struct notes_rewrite_cfg *cfg;
- cfg = init_copy_notes_for_rewrite("amend");
- if (cfg) {
- /* we are amending, so current_head is not NULL */
- copy_note_for_rewrite(cfg, ¤t_head->object.oid,
&oid);
- finish_copy_notes_for_rewrite(cfg, "Notes added by 'git
commit --amend'");
- }
- run_rewrite_hook(¤t_head->object.oid, &oid);
+ commit_post_rewrite(current_head, &oid);
}
if (!quiet)
print_summary(prefix, &oid, !current_head);
diff --git a/sequencer.c b/sequencer.c
index
1795a4df2a0021b2419d941c6083e49cd6647314..81bd0810df6bcf2e078abc220bb8984345bf467f
100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -20,6 +20,8 @@
#include "trailer.h"
#include "log-tree.h"
#include "wt-status.h"
+#include "notes-utils.h"
+#include "sigchain.h"
#define GIT_REFLOG_ACTION "GIT_REFLOG_ACTION"
@@ -786,6 +788,50 @@ int update_head(const struct commit *old_head, const
struct object_id *new_head,
return ret;
}
+static int run_rewrite_hook(const struct object_id *oldoid,
+ const struct object_id *newoid)
+{
+ struct child_process proc = CHILD_PROCESS_INIT;
+ const char *argv[3];
+ int code;
+ struct strbuf sb = STRBUF_INIT;
+
+ argv[0] = find_hook("post-rewrite");
+ if (!argv[0])
+ return 0;
+
+ argv[1] = "amend";
+ argv[2] = NULL;
+
+ proc.argv = argv;
+ proc.in = -1;
+ proc.stdout_to_stderr = 1;
+
+ code = start_command(&proc);
+ if (code)
+ return code;
+ strbuf_addf(&sb, "%s %s\n", oid_to_hex(oldoid), oid_to_hex(newoid));
+ sigchain_push(SIGPIPE, SIG_IGN);
+ write_in_full(proc.in, sb.buf, sb.len);
+ close(proc.in);
+ strbuf_release(&sb);
+ sigchain_pop(SIGPIPE);
+ return finish_command(&proc);
+}
+
+void commit_post_rewrite(const struct commit *old_head,
+ const struct object_id *new_head)
+{
+ struct notes_rewrite_cfg *cfg;
+ cfg = init_copy_notes_for_rewrite("amend");
+ if (cfg) {
+ /* we are amending, so current_head is not NULL */
+ copy_note_for_rewrite(cfg, &old_head->object.oid, new_head);
+ finish_copy_notes_for_rewrite(cfg, "Notes added by 'git commit
--amend'");
+ }
+ run_rewrite_hook(&old_head->object.oid, new_head);
+}
+
static int is_original_commit_empty(struct commit *commit)
{
const struct object_id *ptree_oid;
diff --git a/sequencer.h b/sequencer.h
index
87edf40e5274d59f48d5af57678100ea220d2c8a..45def684ad751d0b8dc62b6cfdfb819ddf183c89
100644
--- a/sequencer.h
+++ b/sequencer.h
@@ -62,4 +62,6 @@ int template_untouched(const struct strbuf *sb, const char
*template_file,
enum cleanup_mode cleanup_mode);
int update_head(const struct commit *old_head, const struct object_id
*new_head,
const struct strbuf *msg, struct strbuf *err);
+void commit_post_rewrite(const struct commit *current_head,
+ const struct object_id *new_head);
#endif
--
2.14.1