]> git.ipfire.org Git - thirdparty/git.git/commitdiff
commit: encapsulate determine_whence() for sequencer
authorPhillip Wood <phillip.wood@dunelm.org.uk>
Fri, 6 Dec 2019 16:06:11 +0000 (16:06 +0000)
committerJunio C Hamano <gitster@pobox.com>
Fri, 6 Dec 2019 17:32:02 +0000 (09:32 -0800)
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>
builtin/commit.c
sequencer.c
sequencer.h

index f5e354c9f05fc38e6f2acacbebaba07a54c21fa0..8a7c839d57b827d8ba6914506aa82dce27890e61 100644 (file)
@@ -178,10 +178,7 @@ static void determine_whence(struct wt_status *s)
 {
        if (file_exists(git_path_merge_head(the_repository)))
                whence = FROM_MERGE;
-       else if (file_exists(git_path_cherry_pick_head(the_repository)))
-               whence = file_exists(git_path_seq_dir()) ?
-                       FROM_CHERRY_PICK_MULTI : FROM_CHERRY_PICK_SINGLE;
-       else
+       else if (!sequencer_determine_whence(the_repository, &whence))
                whence = FROM_COMMIT;
        if (s)
                s->whence = whence;
index d66856818a00628597115dcc9c4bf16b0aacf4d4..dcc2063d33b9ef898930edae3c561f7da27c63a4 100644 (file)
@@ -40,7 +40,7 @@ static const char cherry_picked_prefix[] = "(cherry picked from commit ";
 
 GIT_PATH_FUNC(git_path_commit_editmsg, "COMMIT_EDITMSG")
 
-GIT_PATH_FUNC(git_path_seq_dir, "sequencer")
+static GIT_PATH_FUNC(git_path_seq_dir, "sequencer")
 
 static GIT_PATH_FUNC(git_path_todo_file, "sequencer/todo")
 static GIT_PATH_FUNC(git_path_opts_file, "sequencer/opts")
@@ -5312,3 +5312,14 @@ int todo_list_rearrange_squash(struct todo_list *todo_list)
 
        return 0;
 }
+
+int sequencer_determine_whence(struct repository *r, enum commit_whence *whence)
+{
+       if (file_exists(git_path_cherry_pick_head(r))) {
+               *whence = file_exists(git_path_seq_dir()) ?
+                       FROM_CHERRY_PICK_MULTI : FROM_CHERRY_PICK_SINGLE;
+               return 1;
+       }
+
+       return 0;
+}
index 9f9ae291e3c4ad8bc30abc3c68e18e413df9b6f6..e56e29ceea26627fc26ae935496e3ce8e6e0ea4a 100644 (file)
@@ -3,12 +3,12 @@
 
 #include "cache.h"
 #include "strbuf.h"
+#include "wt-status.h"
 
 struct commit;
 struct repository;
 
 const char *git_path_commit_editmsg(void);
-const char *git_path_seq_dir(void);
 const char *rebase_path_todo(void);
 const char *rebase_path_todo_backup(void);
 
@@ -208,4 +208,5 @@ int write_basic_state(struct replay_opts *opts, const char *head_name,
 void sequencer_post_commit_cleanup(struct repository *r, int verbose);
 int sequencer_get_last_command(struct repository* r,
                               enum replay_action *action);
+int sequencer_determine_whence(struct repository *r, enum commit_whence *whence);
 #endif /* SEQUENCER_H */