rerere: call conflict-ids IDs
Most places we call conflict IDs "name" and some others we call them "hex"; update all of them to "id". Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Jul 6, 2015 at 14:45 UTC
18bb99342fdb4b612ae45be3fef084ceebd498a0
3 files changed
+41
-41
builtin/rerere.c
+2
-2
@@ -103,8 +103,8 @@ int cmd_rerere(int argc, const char **argv, const char *prefix)
103
} else if (!strcmp(argv[0], "diff"))
104
for (i = 0; i < merge_rr.nr; i++) {
105
const char *path = merge_rr.items[i].string;
106
- const char *name = (const char *)merge_rr.items[i].util;
107
- diff_two(rerere_path(name, "preimage"), path, path, path);
106
+ const char *id = (const char *)merge_rr.items[i].util;
107
+ diff_two(rerere_path(id, "preimage"), path, path, path);
108
}
109
else
110
usage_with_options(rerere_usage, options);
rerere.c
+38
-38
@@ -22,15 +22,15 @@ static int rerere_autoupdate;
22
23
static char *merge_rr_path;
24
25
-const char *rerere_path(const char *hex, const char *file)
25
+const char *rerere_path(const char *id, const char *file)
26
{
27
- return git_path("rr-cache/%s/%s", hex, file);
27
+ return git_path("rr-cache/%s/%s", id, file);
28
}
29
30
-static int has_rerere_resolution(const char *hex)
30
+static int has_rerere_resolution(const char *id)
31
{
32
struct stat st;
33
- return !stat(rerere_path(hex, "postimage"), &st);
33
+ return !stat(rerere_path(id, "postimage"), &st);
34
}
35
36
/*
@@ -539,7 +539,7 @@ int rerere_remaining(struct string_list *merge_rr)
539
}
540
541
/*
542
- * Find the conflict identified by "name"; the change between its
542
+ * Find the conflict identified by "id"; the change between its
543
* "preimage" (i.e. a previous contents with conflict markers) and its
544
* "postimage" (i.e. the corresponding contents with conflicts
545
* resolved) may apply cleanly to the contents stored in "path", i.e.
@@ -548,7 +548,7 @@ int rerere_remaining(struct string_list *merge_rr)
548
* Returns 0 for successful replay of recorded resolution, or non-zero
549
* for failure.
550
*/
551
-static int merge(const char *name, const char *path)
551
+static int merge(const char *id, const char *path)
552
{
553
int ret;
554
mmfile_t cur = {NULL, 0}, base = {NULL, 0}, other = {NULL, 0};
@@ -558,12 +558,12 @@ static int merge(const char *name, const char *path)
558
* Normalize the conflicts in path and write it out to
559
* "thisimage" temporary file.
560
*/
561
- if (handle_file(path, NULL, rerere_path(name, "thisimage")) < 0)
561
+ if (handle_file(path, NULL, rerere_path(id, "thisimage")) < 0)
562
return 1;
563
564
- if (read_mmfile(&cur, rerere_path(name, "thisimage")) ||
565
- read_mmfile(&base, rerere_path(name, "preimage")) ||
566
- read_mmfile(&other, rerere_path(name, "postimage"))) {
564
+ if (read_mmfile(&cur, rerere_path(id, "thisimage")) ||
565
+ read_mmfile(&base, rerere_path(id, "preimage")) ||
566
+ read_mmfile(&other, rerere_path(id, "postimage"))) {
567
ret = 1;
568
goto out;
569
}
@@ -580,9 +580,9 @@ static int merge(const char *name, const char *path)
580
* A successful replay of recorded resolution.
581
* Mark that "postimage" was used to help gc.
582
*/
583
- if (utime(rerere_path(name, "postimage"), NULL) < 0)
583
+ if (utime(rerere_path(id, "postimage"), NULL) < 0)
584
warning("failed utime() on %s: %s",
585
- rerere_path(name, "postimage"),
585
+ rerere_path(id, "postimage"),
586
strerror(errno));
587
588
/* Update "path" with the resolution */
@@ -640,11 +640,11 @@ static void do_rerere_one_path(struct string_list_item *rr_item,
640
struct string_list *update)
641
{
642
const char *path = rr_item->string;
643
- const char *name = (const char *)rr_item->util;
643
+ const char *id = (const char *)rr_item->util;
644
645
/* Is there a recorded resolution we could attempt to apply? */
646
- if (has_rerere_resolution(name)) {
647
- if (merge(name, path))
646
+ if (has_rerere_resolution(id)) {
647
+ if (merge(id, path))
648
return; /* failed to replay */
649
650
if (rerere_autoupdate)
@@ -655,7 +655,7 @@ static void do_rerere_one_path(struct string_list_item *rr_item,
655
path);
656
} else if (!handle_file(path, NULL, NULL)) {
657
/* The user has resolved it. */
658
- copy_file(rerere_path(name, "postimage"), path, 0666);
658
+ copy_file(rerere_path(id, "postimage"), path, 0666);
659
fprintf(stderr, "Recorded resolution for '%s'.\n", path);
660
} else {
661
return;
@@ -680,7 +680,7 @@ static int do_plain_rerere(struct string_list *rr, int fd)
680
*/
681
for (i = 0; i < conflict.nr; i++) {
682
unsigned char sha1[20];
683
- char *hex;
683
+ char *id;
684
int ret;
685
const char *path = conflict.items[i].string;
686
@@ -695,8 +695,8 @@ static int do_plain_rerere(struct string_list *rr, int fd)
695
ret = handle_file(path, sha1, NULL);
696
if (ret < 1)
697
continue;
698
- hex = xstrdup(sha1_to_hex(sha1));
699
- string_list_insert(rr, path)->util = hex;
698
+ id = xstrdup(sha1_to_hex(sha1));
699
+ string_list_insert(rr, path)->util = id;
700
701
/*
702
* If the directory does not exist, create
@@ -706,7 +706,7 @@ static int do_plain_rerere(struct string_list *rr, int fd)
706
* NEEDSWORK: make sure "gc" does not remove
707
* preimage without removing the directory.
708
*/
709
- if (mkdir_in_gitdir(git_path("rr-cache/%s", hex)))
709
+ if (mkdir_in_gitdir(git_path("rr-cache/%s", id)))
710
continue;
711
712
/*
@@ -714,7 +714,7 @@ static int do_plain_rerere(struct string_list *rr, int fd)
714
* conflict. Ask handle_file() to write the
715
* normalized contents to the "preimage" file.
716
*/
717
- handle_file(path, NULL, rerere_path(hex, "preimage"));
717
+ handle_file(path, NULL, rerere_path(id, "preimage"));
718
fprintf(stderr, "Recorded preimage for '%s'\n", path);
719
}
720
@@ -788,7 +788,7 @@ int rerere(int flags)
788
static int rerere_forget_one_path(const char *path, struct string_list *rr)
789
{
790
const char *filename;
791
- char *hex;
791
+ char *id;
792
unsigned char sha1[20];
793
int ret;
794
struct string_list_item *item;
@@ -802,8 +802,8 @@ static int rerere_forget_one_path(const char *path, struct string_list *rr)
802
return error("Could not parse conflict hunks in '%s'", path);
803
804
/* Nuke the recorded resolution for the conflict */
805
- hex = xstrdup(sha1_to_hex(sha1));
806
- filename = rerere_path(hex, "postimage");
805
+ id = xstrdup(sha1_to_hex(sha1));
806
+ filename = rerere_path(id, "postimage");
807
if (unlink(filename))
808
return (errno == ENOENT
809
? error("no remembered resolution for %s", path)
@@ -814,7 +814,7 @@ static int rerere_forget_one_path(const char *path, struct string_list *rr)
814
* conflict in the working tree, run us again to record
815
* the postimage.
816
*/
817
- handle_cache(path, sha1, rerere_path(hex, "preimage"));
817
+ handle_cache(path, sha1, rerere_path(id, "preimage"));
818
fprintf(stderr, "Updated preimage for '%s'\n", path);
819
820
/*
@@ -823,7 +823,7 @@ static int rerere_forget_one_path(const char *path, struct string_list *rr)
823
*/
824
item = string_list_insert(rr, path);
825
free(item->util);
826
- item->util = hex;
826
+ item->util = id;
827
fprintf(stderr, "Forgot resolution for %s\n", path);
828
return 0;
829
}
@@ -859,32 +859,32 @@ int rerere_forget(struct pathspec *pathspec)
859
/*
860
* Garbage collection support
861
*/
862
-static time_t rerere_created_at(const char *name)
862
+static time_t rerere_created_at(const char *id)
863
{
864
struct stat st;
865
- return stat(rerere_path(name, "preimage"), &st) ? (time_t) 0 : st.st_mtime;
865
+ return stat(rerere_path(id, "preimage"), &st) ? (time_t) 0 : st.st_mtime;
866
}
867
868
-static time_t rerere_last_used_at(const char *name)
868
+static time_t rerere_last_used_at(const char *id)
869
{
870
struct stat st;
871
- return stat(rerere_path(name, "postimage"), &st) ? (time_t) 0 : st.st_mtime;
871
+ return stat(rerere_path(id, "postimage"), &st) ? (time_t) 0 : st.st_mtime;
872
}
873
874
/*
875
* Remove the recorded resolution for a given conflict ID
876
*/
877
-static void unlink_rr_item(const char *name)
877
+static void unlink_rr_item(const char *id)
878
{
879
- unlink(rerere_path(name, "thisimage"));
880
- unlink(rerere_path(name, "preimage"));
881
- unlink(rerere_path(name, "postimage"));
879
+ unlink(rerere_path(id, "thisimage"));
880
+ unlink(rerere_path(id, "preimage"));
881
+ unlink(rerere_path(id, "postimage"));
882
/*
883
* NEEDSWORK: what if this rmdir() fails? Wouldn't we then
884
* assume that we already have preimage recorded in
885
* do_plain_rerere()?
886
*/
887
- rmdir(git_path("rr-cache/%s", name));
887
+ rmdir(git_path("rr-cache/%s", id));
888
}
889
890
void rerere_gc(struct string_list *rr)
@@ -939,9 +939,9 @@ void rerere_clear(struct string_list *merge_rr)
939
int i;
940
941
for (i = 0; i < merge_rr->nr; i++) {
942
- const char *name = (const char *)merge_rr->items[i].util;
943
- if (!has_rerere_resolution(name))
944
- unlink_rr_item(name);
942
+ const char *id = (const char *)merge_rr->items[i].util;
943
+ if (!has_rerere_resolution(id))
944
+ unlink_rr_item(id);
945
}
946
unlink_or_warn(git_path("MERGE_RR"));
947
}
rerere.h
+1
-1
@@ -17,7 +17,7 @@ extern void *RERERE_RESOLVED;
17
18
extern int setup_rerere(struct string_list *, int);
19
extern int rerere(int);
20
-extern const char *rerere_path(const char *hex, const char *file);
20
+extern const char *rerere_path(const char *id, const char *file);
21
extern int rerere_forget(struct pathspec *);
22
extern int rerere_remaining(struct string_list *);
23
extern void rerere_clear(struct string_list *);