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 <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Phillip Wood committed
Dec 6, 2019 at 16:06 UTC
901ba7b1efe8ba9464aac528ecd46e8dd4f01003
3 files changed
+15
-6
builtin/commit.c
+1
-4
@@ -178,10 +178,7 @@ static void determine_whence(struct wt_status *s)
178
{
179
if (file_exists(git_path_merge_head(the_repository)))
180
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))
182
whence = FROM_COMMIT;
183
if (s)
184
s->whence = whence;
sequencer.c
+12
-1
@@ -40,7 +40,7 @@ static const char cherry_picked_prefix[] = "(cherry picked from commit ";
40
41
GIT_PATH_FUNC(git_path_commit_editmsg, "COMMIT_EDITMSG")
42
43
-GIT_PATH_FUNC(git_path_seq_dir, "sequencer")
43
+static GIT_PATH_FUNC(git_path_seq_dir, "sequencer")
44
45
static GIT_PATH_FUNC(git_path_todo_file, "sequencer/todo")
46
static GIT_PATH_FUNC(git_path_opts_file, "sequencer/opts")
@@ -5312,3 +5312,14 @@ int todo_list_rearrange_squash(struct todo_list *todo_list)
5312
5313
return 0;
5314
}
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
+2
-1
@@ -3,12 +3,12 @@
3
4
#include "cache.h"
5
#include "strbuf.h"
6
+#include "wt-status.h"
7
8
struct commit;
9
struct repository;
10
11
const char *git_path_commit_editmsg(void);
11
-const char *git_path_seq_dir(void);
12
const char *rebase_path_todo(void);
13
const char *rebase_path_todo_backup(void);
14
@@ -208,4 +208,5 @@ int write_basic_state(struct replay_opts *opts, const char *head_name,
208
void sequencer_post_commit_cleanup(struct repository *r, int verbose);
209
int sequencer_get_last_command(struct repository* r,
210
enum replay_action *action);
211
+int sequencer_determine_whence(struct repository *r, enum commit_whence *whence);
212
#endif /* SEQUENCER_H */