And use it on commit.c.

Signed-off-by: Felipe Contreras <felipe.contre...@gmail.com>
---
 builtin/commit.c |  8 +-------
 rewrite.c        | 18 ++++++++++++++++++
 rewrite.h        |  1 +
 3 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/builtin/commit.c b/builtin/commit.c
index 7bfe9d0..cc589d5 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1621,16 +1621,10 @@ int cmd_commit(int argc, const char **argv, const char 
*prefix)
        rerere(0);
        run_hook(get_index_file(), "post-commit", NULL);
        if (amend && !no_post_rewrite) {
-               struct notes_rewrite_cfg *cfg;
                struct rewritten rewrite;
                memset(&rewrite, 0, sizeof(rewrite));
-               cfg = init_copy_notes_for_rewrite("amend");
-               if (cfg) {
-                       /* we are amending, so current_head is not NULL */
-                       copy_note_for_rewrite(cfg, current_head->object.sha1, 
sha1);
-                       finish_copy_notes_for_rewrite(cfg, "Notes added by 'git 
commit --amend'");
-               }
                add_rewritten(&rewrite, current_head->object.sha1, sha1);
+               copy_rewrite_notes(&rewrite, "amend", "Notes added by 'git 
commit --amend'");
                run_rewrite_hook(&rewrite, "amend");
        }
        if (!quiet)
diff --git a/rewrite.c b/rewrite.c
index c8efaa8..4dddcd9 100644
--- a/rewrite.c
+++ b/rewrite.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "rewrite.h"
 #include "run-command.h"
+#include "notes-utils.h"
 
 void add_rewritten(struct rewritten *list, unsigned char *from, unsigned char 
*to)
 {
@@ -101,3 +102,20 @@ int run_rewrite_hook(struct rewritten *list, const char 
*name)
        close(proc.in);
        return finish_command(&proc);
 }
+
+void copy_rewrite_notes(struct rewritten *list, const char *name, const char 
*msg)
+{
+       struct notes_rewrite_cfg *cfg;
+       int i;
+
+       cfg = init_copy_notes_for_rewrite(name);
+       if (!cfg)
+               return;
+
+       for (i = 0; i < list->nr; i++) {
+               struct rewritten_item *item = &list->items[i];
+               copy_note_for_rewrite(cfg, item->from, item->to);
+       }
+
+       finish_copy_notes_for_rewrite(cfg, msg);
+}
diff --git a/rewrite.h b/rewrite.h
index fd00e66..fdc7055 100644
--- a/rewrite.h
+++ b/rewrite.h
@@ -15,5 +15,6 @@ void add_rewritten(struct rewritten *list, unsigned char 
*from, unsigned char *t
 int store_rewritten(struct rewritten *list, const char *file);
 void load_rewritten(struct rewritten *list, const char *file);
 int run_rewrite_hook(struct rewritten *list, const char *name);
+void copy_rewrite_notes(struct rewritten *list, const char *name, const char 
*msg);
 
 #endif
-- 
1.8.4-fc

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to