Skip to content

Commit 79d7e88

Browse files
agrngitster
authored andcommitted
rebase--interactive: move rearrange_squash_in_todo_file()
As rearrange_squash_in_todo_file() is only needed inside of rebase--interactive.c for `rebase -p', it is moved there from sequencer.c. The parameter r (repository) is dropped along the way, and the error handling is slightly improved. Signed-off-by: Alban Gruin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1ba204d commit 79d7e88

File tree

3 files changed

+29
-29
lines changed

3 files changed

+29
-29
lines changed

builtin/rebase--interactive.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,32 @@ static int add_exec_commands(struct string_list *commands)
3838
return 0;
3939
}
4040

41+
static int rearrange_squash_in_todo_file(void)
42+
{
43+
const char *todo_file = rebase_path_todo();
44+
struct todo_list todo_list = TODO_LIST_INIT;
45+
int res = 0;
46+
47+
if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0)
48+
return error_errno(_("could not read '%s'."), todo_file);
49+
if (todo_list_parse_insn_buffer(the_repository, todo_list.buf.buf,
50+
&todo_list)) {
51+
todo_list_release(&todo_list);
52+
return error(_("unusable todo list: '%s'"), todo_file);
53+
}
54+
55+
res = todo_list_rearrange_squash(&todo_list);
56+
if (!res)
57+
res = todo_list_write_to_file(the_repository, &todo_list,
58+
todo_file, NULL, NULL, -1, 0);
59+
60+
todo_list_release(&todo_list);
61+
62+
if (res)
63+
return error_errno(_("could not write '%s'."), todo_file);
64+
return 0;
65+
}
66+
4167
static int get_revision_ranges(const char *upstream, const char *onto,
4268
const char **head_hash,
4369
char **revisions, char **shortrevisions)
@@ -288,7 +314,7 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
288314
ret = check_todo_list_from_file(the_repository);
289315
break;
290316
case REARRANGE_SQUASH:
291-
ret = rearrange_squash_in_todo_file(the_repository);
317+
ret = rearrange_squash_in_todo_file();
292318
break;
293319
case ADD_EXEC:
294320
ret = add_exec_commands(&commands);

sequencer.c

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4793,8 +4793,6 @@ static int skip_unnecessary_picks(struct repository *r, struct object_id *output
47934793
return 0;
47944794
}
47954795

4796-
static int todo_list_rearrange_squash(struct todo_list *todo_list);
4797-
47984796
int complete_action(struct repository *r, struct replay_opts *opts, unsigned flags,
47994797
const char *shortrevisions, const char *onto_name,
48004798
const char *onto, const char *orig_head, struct string_list *commands,
@@ -4906,7 +4904,7 @@ define_commit_slab(commit_todo_item, struct todo_item *);
49064904
* message will have to be retrieved from the commit (as the oneline in the
49074905
* script cannot be trusted) in order to normalize the autosquash arrangement.
49084906
*/
4909-
static int todo_list_rearrange_squash(struct todo_list *todo_list)
4907+
int todo_list_rearrange_squash(struct todo_list *todo_list)
49104908
{
49114909
struct hashmap subject2item;
49124910
int rearranged = 0, *next, *tail, i, nr = 0, alloc = 0;
@@ -5044,27 +5042,3 @@ static int todo_list_rearrange_squash(struct todo_list *todo_list)
50445042

50455043
return 0;
50465044
}
5047-
5048-
int rearrange_squash_in_todo_file(struct repository *r)
5049-
{
5050-
const char *todo_file = rebase_path_todo();
5051-
struct todo_list todo_list = TODO_LIST_INIT;
5052-
int res = 0;
5053-
5054-
if (strbuf_read_file_or_whine(&todo_list.buf, todo_file) < 0)
5055-
return -1;
5056-
if (todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list) < 0) {
5057-
todo_list_release(&todo_list);
5058-
return -1;
5059-
}
5060-
5061-
res = todo_list_rearrange_squash(&todo_list);
5062-
if (!res)
5063-
res = todo_list_write_to_file(r, &todo_list, todo_file, NULL, NULL, -1, 0);
5064-
5065-
todo_list_release(&todo_list);
5066-
5067-
if (res)
5068-
return error_errno(_("could not write '%s'."), todo_file);
5069-
return 0;
5070-
}

sequencer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla
153153
const char *shortrevisions, const char *onto_name,
154154
const char *onto, const char *orig_head, struct string_list *commands,
155155
unsigned autosquash, struct todo_list *todo_list);
156-
int rearrange_squash_in_todo_file(struct repository *r);
156+
int todo_list_rearrange_squash(struct todo_list *todo_list);
157157

158158
extern const char sign_off_header[];
159159

0 commit comments

Comments
 (0)