sequencer: change the way skip_unnecessary_picks() returns its result

Instead of skip_unnecessary_picks() printing its result to stdout, it returns it into a struct object_id, as the rewrite of complete_action() (to come in the next commit) will need it. rebase--helper then is modified to fit this change. Signed-off-by: Alban Gruin <alban.gruin@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Alban Gruin committed Aug 10, 2018 at 18:51 UTC d4ed5d7713c779487a52d30e83185a056c4bf023
3 files changed +15 -10
builtin/rebase--helper.c
+8 -2
@@ -90,8 +90,14 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
90 return !!transform_todos(flags);
91 if (command == CHECK_TODO_LIST && argc == 1)
92 return !!check_todo_list();
93 - if (command == SKIP_UNNECESSARY_PICKS && argc == 1)
94 - return !!skip_unnecessary_picks();
93 + if (command == SKIP_UNNECESSARY_PICKS && argc == 1) {
94 + struct object_id oid;
95 + int ret = skip_unnecessary_picks(&oid);
96 +
97 + if (!ret)
98 + puts(oid_to_hex(&oid));
99 + return !!ret;
100 + }
101 if (command == REARRANGE_SQUASH && argc == 1)
102 return !!rearrange_squash();
103 if (command == ADD_EXEC && argc == 2)
sequencer.c
+6 -7
@@ -4416,17 +4416,17 @@ static int rewrite_file(const char *path, const char *buf, size_t len)
4416 }
4417
4418 /* skip picking commits whose parents are unchanged */
4419 -int skip_unnecessary_picks(void)
4419 +int skip_unnecessary_picks(struct object_id *output_oid)
4420 {
4421 const char *todo_file = rebase_path_todo();
4422 struct strbuf buf = STRBUF_INIT;
4423 struct todo_list todo_list = TODO_LIST_INIT;
4424 - struct object_id onto_oid, *oid = &onto_oid, *parent_oid;
4424 + struct object_id *parent_oid;
4425 int fd, i;
4426
4427 if (!read_oneliner(&buf, rebase_path_onto(), 0))
4428 return error(_("could not read 'onto'"));
4429 - if (get_oid(buf.buf, &onto_oid)) {
4429 + if (get_oid(buf.buf, output_oid)) {
4430 strbuf_release(&buf);
4431 return error(_("need a HEAD to fixup"));
4432 }
@@ -4456,9 +4456,9 @@ int skip_unnecessary_picks(void)
4456 if (item->commit->parents->next)
4457 break; /* merge commit */
4458 parent_oid = &item->commit->parents->item->object.oid;
4459 - if (hashcmp(parent_oid->hash, oid->hash))
4459 + if (hashcmp(parent_oid->hash, output_oid->hash))
4460 break;
4461 - oid = &item->commit->object.oid;
4461 + oidcpy(output_oid, &item->commit->object.oid);
4462 }
4463 if (i > 0) {
4464 int offset = get_item_line_offset(&todo_list, i);
@@ -4487,11 +4487,10 @@ int skip_unnecessary_picks(void)
4487
4488 todo_list.current = i;
4489 if (is_fixup(peek_command(&todo_list, 0)))
4490 - record_in_rewritten(oid, peek_command(&todo_list, 0));
4490 + record_in_rewritten(output_oid, peek_command(&todo_list, 0));
4491 }
4492
4493 todo_list_release(&todo_list);
4494 - printf("%s\n", oid_to_hex(oid));
4494
4495 return 0;
4496 }
sequencer.h
+1 -1
@@ -91,7 +91,7 @@ int sequencer_add_exec_commands(const char *command);
91 int transform_todos(unsigned flags);
92 enum missing_commit_check_level get_missing_commit_check_level(void);
93 int check_todo_list(void);
94 -int skip_unnecessary_picks(void);
94 +int skip_unnecessary_picks(struct object_id *output_oid);
95 int rearrange_squash(void);
96
97 extern const char sign_off_header[];