Re: [PATCH v3 5/9] sequencer: run post-rewrite hook

2013-06-09 Thread Felipe Contreras
On Thu, Jun 6, 2013 at 1:40 PM, Junio C Hamano gits...@pobox.com wrote:

 It probably is worth inserting a commit before 4/9 that adds
 rewrite.[ch], and

  - introduces struct rewritten_list[_item];

  - moves run_rewrite_hook() in builtin/commit.c to rewrite.c;

  - changes its function signature so that it takes char
*action_name and struct rewritten * as parameters; and

  - adjust its sole call site in cmd_commit() to feed a single-item
rewritten_list to it.

 Then 4/9 can teach cherry-pick to prepare the rewritten-list and
 probably this commit can be part of that to call run_rewrite_hook().

Done. I'll send the patches in a moment.

-- 
Felipe Contreras
--
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


[PATCH v3 5/9] sequencer: run post-rewrite hook

2013-06-06 Thread Felipe Contreras
As we should.

Signed-off-by: Felipe Contreras felipe.contre...@gmail.com
---
 sequencer.c | 42 +-
 1 file changed, 41 insertions(+), 1 deletion(-)

diff --git a/sequencer.c b/sequencer.c
index 76ff2ff..74480d7 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -127,6 +127,37 @@ static void add_rewritten(unsigned char *from, unsigned 
char *to)
rewritten.nr++;
 }
 
+static void run_rewrite_hook(const char *name)
+{
+   struct strbuf buf = STRBUF_INIT;
+   struct child_process proc;
+   const char *argv[3];
+   int code, i;
+
+   argv[0] = find_hook(post-rewrite);
+   if (!argv[0])
+   return;
+
+   argv[1] = name;
+   argv[2] = NULL;
+
+   memset(proc, 0, sizeof(proc));
+   proc.argv = argv;
+   proc.in = -1;
+   proc.stdout_to_stderr = 1;
+
+   code = start_command(proc);
+   if (code)
+   return;
+   for (i = 0; i  rewritten.nr; i++) {
+   struct rewritten_list_item *item = rewritten.items[i];
+   strbuf_addf(buf, %s %s\n, sha1_to_hex(item-from), 
sha1_to_hex(item-to));
+   }
+   write_in_full(proc.in, buf.buf, buf.len);
+   close(proc.in);
+   finish_command(proc);
+}
+
 static void remove_sequencer_state(void)
 {
struct strbuf seq_dir = STRBUF_INIT;
@@ -1100,6 +1131,9 @@ static int pick_commits(struct commit_list *todo_list, 
struct replay_opts *opts)
}
}
 
+   if (opts-action == REPLAY_PICK)
+   run_rewrite_hook(cherry-pick);
+
/*
 * Sequence of picks finished successfully; cleanup by
 * removing the .git/sequencer directory
@@ -1149,8 +1183,14 @@ static int sequencer_continue(struct replay_opts *opts)
 
 static int single_pick(struct commit *cmit, struct replay_opts *opts)
 {
+   int ret;
setenv(GIT_REFLOG_ACTION, action_name(opts), 0);
-   return do_pick_commit(cmit, opts);
+   ret = do_pick_commit(cmit, opts);
+   if (ret)
+   return ret;
+   if (opts-action == REPLAY_PICK)
+   run_rewrite_hook(cherry-pick);
+   return 0;
 }
 
 int sequencer_pick_revisions(struct replay_opts *opts)
-- 
1.8.3.698.g079b096

--
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


Re: [PATCH v3 5/9] sequencer: run post-rewrite hook

2013-06-06 Thread Junio C Hamano
Felipe Contreras felipe.contre...@gmail.com writes:

 As we should.

 Signed-off-by: Felipe Contreras felipe.contre...@gmail.com
 ---
  sequencer.c | 42 +-
  1 file changed, 41 insertions(+), 1 deletion(-)

 diff --git a/sequencer.c b/sequencer.c
 index 76ff2ff..74480d7 100644
 --- a/sequencer.c
 +++ b/sequencer.c
 @@ -127,6 +127,37 @@ static void add_rewritten(unsigned char *from, unsigned 
 char *to)
   rewritten.nr++;
  }
  
 +static void run_rewrite_hook(const char *name)
 +{
 + struct strbuf buf = STRBUF_INIT;
 + struct child_process proc;
 + const char *argv[3];
 + int code, i;
 +
 + argv[0] = find_hook(post-rewrite);
 + if (!argv[0])
 + return;
 +
 + argv[1] = name;
 + argv[2] = NULL;
 +
 + memset(proc, 0, sizeof(proc));
 + proc.argv = argv;
 + proc.in = -1;
 + proc.stdout_to_stderr = 1;
 +
 + code = start_command(proc);
 + if (code)
 + return;
 + for (i = 0; i  rewritten.nr; i++) {
 + struct rewritten_list_item *item = rewritten.items[i];
 + strbuf_addf(buf, %s %s\n, sha1_to_hex(item-from), 
 sha1_to_hex(item-to));
 + }
 + write_in_full(proc.in, buf.buf, buf.len);
 + close(proc.in);
 + finish_command(proc);
 +}

It probably is worth inserting a commit before 4/9 that adds
rewrite.[ch], and

 - introduces struct rewritten_list[_item];

 - moves run_rewrite_hook() in builtin/commit.c to rewrite.c;

 - changes its function signature so that it takes char
   *action_name and struct rewritten * as parameters; and

 - adjust its sole call site in cmd_commit() to feed a single-item
   rewritten_list to it.

Then 4/9 can teach cherry-pick to prepare the rewritten-list and
probably this commit can be part of that to call run_rewrite_hook().
--
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