Skip to content

Commit 901ba7b

Browse files
phillipwoodgitster
authored andcommitted
commit: encapsulate determine_whence() for sequencer
Working out which command wants to create a commit requires detailed knowledge of the sequencer internals and that knowledge is going to increase in subsequent commits. With that in mind lets encapsulate that knowledge in sequencer.c rather than spreading it into builtin/commit.c. Signed-off-by: Phillip Wood <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8d57f75 commit 901ba7b

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

builtin/commit.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,7 @@ static void determine_whence(struct wt_status *s)
178178
{
179179
if (file_exists(git_path_merge_head(the_repository)))
180180
whence = FROM_MERGE;
181-
else if (file_exists(git_path_cherry_pick_head(the_repository)))
182-
whence = file_exists(git_path_seq_dir()) ?
183-
FROM_CHERRY_PICK_MULTI : FROM_CHERRY_PICK_SINGLE;
184-
else
181+
else if (!sequencer_determine_whence(the_repository, &whence))
185182
whence = FROM_COMMIT;
186183
if (s)
187184
s->whence = whence;

sequencer.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static const char cherry_picked_prefix[] = "(cherry picked from commit ";
4040

4141
GIT_PATH_FUNC(git_path_commit_editmsg, "COMMIT_EDITMSG")
4242

43-
GIT_PATH_FUNC(git_path_seq_dir, "sequencer")
43+
static GIT_PATH_FUNC(git_path_seq_dir, "sequencer")
4444

4545
static GIT_PATH_FUNC(git_path_todo_file, "sequencer/todo")
4646
static GIT_PATH_FUNC(git_path_opts_file, "sequencer/opts")
@@ -5312,3 +5312,14 @@ int todo_list_rearrange_squash(struct todo_list *todo_list)
53125312

53135313
return 0;
53145314
}
5315+
5316+
int sequencer_determine_whence(struct repository *r, enum commit_whence *whence)
5317+
{
5318+
if (file_exists(git_path_cherry_pick_head(r))) {
5319+
*whence = file_exists(git_path_seq_dir()) ?
5320+
FROM_CHERRY_PICK_MULTI : FROM_CHERRY_PICK_SINGLE;
5321+
return 1;
5322+
}
5323+
5324+
return 0;
5325+
}

sequencer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33

44
#include "cache.h"
55
#include "strbuf.h"
6+
#include "wt-status.h"
67

78
struct commit;
89
struct repository;
910

1011
const char *git_path_commit_editmsg(void);
11-
const char *git_path_seq_dir(void);
1212
const char *rebase_path_todo(void);
1313
const char *rebase_path_todo_backup(void);
1414

@@ -208,4 +208,5 @@ int write_basic_state(struct replay_opts *opts, const char *head_name,
208208
void sequencer_post_commit_cleanup(struct repository *r, int verbose);
209209
int sequencer_get_last_command(struct repository* r,
210210
enum replay_action *action);
211+
int sequencer_determine_whence(struct repository *r, enum commit_whence *whence);
211212
#endif /* SEQUENCER_H */

0 commit comments

Comments
 (0)