21
const char sign_off_header[] = "Signed-off-by: ";
22
static const char cherry_picked_prefix[] = "(cherry picked from commit ";
23
24
+static GIT_PATH_FUNC(git_path_todo_file, SEQ_TODO_FILE)
25
+static GIT_PATH_FUNC(git_path_opts_file, SEQ_OPTS_FILE)
26
+static GIT_PATH_FUNC(git_path_seq_dir, SEQ_DIR)
27
+static GIT_PATH_FUNC(git_path_head_file, SEQ_HEAD_FILE)
28
+
29
static int is_rfc2822_line(const char *buf, int len)
30
{
31
int i;
191
* (typically rebase --interactive) wants to take care
192
* of the commit itself so remove CHERRY_PICK_HEAD
193
*/
189
- unlink(git_path("CHERRY_PICK_HEAD"));
194
+ unlink(git_path_cherry_pick_head());
195
return;
196
}
197
472
struct commit *base, *next, *parent;
473
const char *base_label, *next_label;
474
struct commit_message msg = { NULL, NULL, NULL, NULL };
470
- char *defmsg = NULL;
475
struct strbuf msgbuf = STRBUF_INIT;
476
int res, unborn = 0, allow;
477
541
* reverse of it if we are revert.
542
*/
543
540
- defmsg = git_pathdup("MERGE_MSG");
541
-
544
if (opts->action == REPLAY_REVERT) {
545
base = commit;
546
base_label = msg.label;
587
if (!opts->strategy || !strcmp(opts->strategy, "recursive") || opts->action == REPLAY_REVERT) {
588
res = do_recursive_merge(base, next, base_label, next_label,
589
head, &msgbuf, opts);
588
- write_message(&msgbuf, defmsg);
590
+ write_message(&msgbuf, git_path_merge_msg());
591
} else {
592
struct commit_list *common = NULL;
593
struct commit_list *remotes = NULL;
594
593
- write_message(&msgbuf, defmsg);
595
+ write_message(&msgbuf, git_path_merge_msg());
596
597
commit_list_insert(base, &common);
598
commit_list_insert(next, &remotes);
630
goto leave;
631
}
632
if (!opts->no_commit)
631
- res = run_git_commit(defmsg, opts, allow);
633
+ res = run_git_commit(git_path_merge_msg(), opts, allow);
634
635
leave:
636
free_message(commit, &msg);
635
- free(defmsg);
637
638
return res;
639
}
757
static void read_populate_todo(struct commit_list **todo_list,
758
struct replay_opts *opts)
759
{
759
- const char *todo_file = git_path(SEQ_TODO_FILE);
760
struct strbuf buf = STRBUF_INIT;
761
int fd, res;
762
763
- fd = open(todo_file, O_RDONLY);
763
+ fd = open(git_path_todo_file(), O_RDONLY);
764
if (fd < 0)
765
- die_errno(_("Could not open %s"), todo_file);
765
+ die_errno(_("Could not open %s"), git_path_todo_file());
766
if (strbuf_read(&buf, fd, 0) < 0) {
767
close(fd);
768
strbuf_release(&buf);
769
- die(_("Could not read %s."), todo_file);
769
+ die(_("Could not read %s."), git_path_todo_file());
770
}
771
close(fd);
772
773
res = parse_insn_buffer(buf.buf, todo_list, opts);
774
strbuf_release(&buf);
775
if (res)
776
- die(_("Unusable instruction sheet: %s"), todo_file);
776
+ die(_("Unusable instruction sheet: %s"), git_path_todo_file());
777
}
778
779
static int populate_opts_cb(const char *key, const char *value, void *data)
813
814
static void read_populate_opts(struct replay_opts **opts_ptr)
815
{
816
- const char *opts_file = git_path(SEQ_OPTS_FILE);
817
-
818
- if (!file_exists(opts_file))
816
+ if (!file_exists(git_path_opts_file()))
817
return;
820
- if (git_config_from_file(populate_opts_cb, opts_file, *opts_ptr) < 0)
821
- die(_("Malformed options sheet: %s"), opts_file);
818
+ if (git_config_from_file(populate_opts_cb, git_path_opts_file(), *opts_ptr) < 0)
819
+ die(_("Malformed options sheet: %s"), git_path_opts_file());
820
}
821
822
static void walk_revs_populate_todo(struct commit_list **todo_list,
834
835
static int create_seq_dir(void)
836
{
839
- const char *seq_dir = git_path(SEQ_DIR);
840
-
841
- if (file_exists(seq_dir)) {
837
+ if (file_exists(git_path_seq_dir())) {
838
error(_("a cherry-pick or revert is already in progress"));
839
advise(_("try \"git cherry-pick (--continue | --quit | --abort)\""));
840
return -1;
841
}
846
- else if (mkdir(seq_dir, 0777) < 0)
847
- die_errno(_("Could not create sequencer directory %s"), seq_dir);
842
+ else if (mkdir(git_path_seq_dir(), 0777) < 0)
843
+ die_errno(_("Could not create sequencer directory %s"),
844
+ git_path_seq_dir());
845
return 0;
846
}
847
848
static void save_head(const char *head)
849
{
853
- const char *head_file = git_path(SEQ_HEAD_FILE);
850
static struct lock_file head_lock;
851
struct strbuf buf = STRBUF_INIT;
852
int fd;
853
858
- fd = hold_lock_file_for_update(&head_lock, head_file, LOCK_DIE_ON_ERROR);
854
+ fd = hold_lock_file_for_update(&head_lock, git_path_head_file(), LOCK_DIE_ON_ERROR);
855
strbuf_addf(&buf, "%s\n", head);
856
if (write_in_full(fd, buf.buf, buf.len) < 0)
861
- die_errno(_("Could not write to %s"), head_file);
857
+ die_errno(_("Could not write to %s"), git_path_head_file());
858
if (commit_lock_file(&head_lock) < 0)
863
- die(_("Error wrapping up %s."), head_file);
859
+ die(_("Error wrapping up %s."), git_path_head_file());
860
}
861
862
static int reset_for_rollback(const unsigned char *sha1)
873
{
874
unsigned char head_sha1[20];
875
880
- if (!file_exists(git_path("CHERRY_PICK_HEAD")) &&
881
- !file_exists(git_path("REVERT_HEAD")))
876
+ if (!file_exists(git_path_cherry_pick_head()) &&
877
+ !file_exists(git_path_revert_head()))
878
return error(_("no cherry-pick or revert in progress"));
879
if (read_ref_full("HEAD", 0, head_sha1, NULL))
880
return error(_("cannot resolve HEAD"));
885
886
static int sequencer_rollback(struct replay_opts *opts)
887
{
892
- const char *filename;
888
FILE *f;
889
unsigned char sha1[20];
890
struct strbuf buf = STRBUF_INIT;
891
897
- filename = git_path(SEQ_HEAD_FILE);
898
- f = fopen(filename, "r");
892
+ f = fopen(git_path_head_file(), "r");
893
if (!f && errno == ENOENT) {
894
/*
895
* There is no multiple-cherry-pick in progress.
899
return rollback_single_pick();
900
}
901
if (!f)
908
- return error(_("cannot open %s: %s"), filename,
902
+ return error(_("cannot open %s: %s"), git_path_head_file(),
903
strerror(errno));
904
if (strbuf_getline(&buf, f, '\n')) {
911
- error(_("cannot read %s: %s"), filename, ferror(f) ?
912
- strerror(errno) : _("unexpected end of file"));
905
+ error(_("cannot read %s: %s"), git_path_head_file(),
906
+ ferror(f) ? strerror(errno) : _("unexpected end of file"));
907
fclose(f);
908
goto fail;
909
}
910
fclose(f);
911
if (get_sha1_hex(buf.buf, sha1) || buf.buf[40] != '\0') {
912
error(_("stored pre-cherry-pick HEAD file '%s' is corrupt"),
919
- filename);
913
+ git_path_head_file());
914
goto fail;
915
}
916
if (reset_for_rollback(sha1))
925
926
static void save_todo(struct commit_list *todo_list, struct replay_opts *opts)
927
{
934
- const char *todo_file = git_path(SEQ_TODO_FILE);
928
static struct lock_file todo_lock;
929
struct strbuf buf = STRBUF_INIT;
930
int fd;
931
939
- fd = hold_lock_file_for_update(&todo_lock, todo_file, LOCK_DIE_ON_ERROR);
932
+ fd = hold_lock_file_for_update(&todo_lock, git_path_todo_file(), LOCK_DIE_ON_ERROR);
933
if (format_todo(&buf, todo_list, opts) < 0)
941
- die(_("Could not format %s."), todo_file);
934
+ die(_("Could not format %s."), git_path_todo_file());
935
if (write_in_full(fd, buf.buf, buf.len) < 0) {
936
strbuf_release(&buf);
944
- die_errno(_("Could not write to %s"), todo_file);
937
+ die_errno(_("Could not write to %s"), git_path_todo_file());
938
}
939
if (commit_lock_file(&todo_lock) < 0) {
940
strbuf_release(&buf);
948
- die(_("Error wrapping up %s."), todo_file);
941
+ die(_("Error wrapping up %s."), git_path_todo_file());
942
}
943
strbuf_release(&buf);
944
}
945
946
static void save_opts(struct replay_opts *opts)
947
{
955
- const char *opts_file = git_path(SEQ_OPTS_FILE);
948
+ const char *opts_file = git_path_opts_file();
949
950
if (opts->no_commit)
951
git_config_set_in_file(opts_file, "options.no-commit", "true");
1006
{
1007
const char *argv[] = { "commit", NULL };
1008
1016
- if (!file_exists(git_path("CHERRY_PICK_HEAD")) &&
1017
- !file_exists(git_path("REVERT_HEAD")))
1009
+ if (!file_exists(git_path_cherry_pick_head()) &&
1010
+ !file_exists(git_path_revert_head()))
1011
return error(_("no cherry-pick or revert in progress"));
1012
return run_command_v_opt(argv, RUN_GIT_CMD);
1013
}
1016
{
1017
struct commit_list *todo_list = NULL;
1018
1026
- if (!file_exists(git_path(SEQ_TODO_FILE)))
1019
+ if (!file_exists(git_path_todo_file()))
1020
return continue_single_pick();
1021
read_populate_opts(&opts);
1022
read_populate_todo(&todo_list, opts);
1023
1024
/* Verify that the conflict has been resolved */
1032
- if (file_exists(git_path("CHERRY_PICK_HEAD")) ||
1033
- file_exists(git_path("REVERT_HEAD"))) {
1025
+ if (file_exists(git_path_cherry_pick_head()) ||
1026
+ file_exists(git_path_revert_head())) {
1027
int ret = continue_single_pick();
1028
if (ret)
1029
return ret;