@matheusbsbs / matheus-bagliano / commits / 900569661b
Fork 0

rerere: remove duplicated functions

Both rerere.c and builtin-rerere.c define the static functions rr_path() and has_resolution() the exact same way. To eliminate this code duplication this patch turns the functions in rerere.c non-static, and makes builtin-rerere.c use them. Also, since this puts these two functions into the global namespace, rename them to rerere_path() and has_rerere_resolution(), respectively, and rename their "name" parameter to "hex", because it better reflects what that parameter actually is. Signed-off-by: SZEDER Gábor <szeder@ira.uka.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

SZEDER Gábor committed Feb 14, 2009 at 23:21 UTC 900569661bbfe5c0e56cf8b9c014a2f594bb174c
3 files changed +20 -29
builtin-rerere.c
+7 -18
@@ -13,28 +13,17 @@ static const char git_rerere_usage[] =
13 static int cutoff_noresolve = 15;
14 static int cutoff_resolve = 60;
15
16 -static const char *rr_path(const char *name, const char *file)
17 -{
18 - return git_path("rr-cache/%s/%s", name, file);
19 -}
20 -
16 static time_t rerere_created_at(const char *name)
17 {
18 struct stat st;
24 - return stat(rr_path(name, "preimage"), &st) ? (time_t) 0 : st.st_mtime;
25 -}
26 -
27 -static int has_resolution(const char *name)
28 -{
29 - struct stat st;
30 - return !stat(rr_path(name, "postimage"), &st);
19 + return stat(rerere_path(name, "preimage"), &st) ? (time_t) 0 : st.st_mtime;
20 }
21
22 static void unlink_rr_item(const char *name)
23 {
35 - unlink(rr_path(name, "thisimage"));
36 - unlink(rr_path(name, "preimage"));
37 - unlink(rr_path(name, "postimage"));
24 + unlink(rerere_path(name, "thisimage"));
25 + unlink(rerere_path(name, "preimage"));
26 + unlink(rerere_path(name, "postimage"));
27 rmdir(git_path("rr-cache/%s", name));
28 }
29
@@ -65,7 +54,7 @@ static void garbage_collect(struct string_list *rr)
54 then = rerere_created_at(e->d_name);
55 if (!then)
56 continue;
68 - cutoff = (has_resolution(e->d_name)
57 + cutoff = (has_rerere_resolution(e->d_name)
58 ? cutoff_resolve : cutoff_noresolve);
59 if (then < now - cutoff * 86400)
60 string_list_append(e->d_name, &to_remove);
@@ -124,7 +113,7 @@ int cmd_rerere(int argc, const char **argv, const char *prefix)
113 if (!strcmp(argv[1], "clear")) {
114 for (i = 0; i < merge_rr.nr; i++) {
115 const char *name = (const char *)merge_rr.items[i].util;
127 - if (!has_resolution(name))
116 + if (!has_rerere_resolution(name))
117 unlink_rr_item(name);
118 }
119 unlink(git_path("rr-cache/MERGE_RR"));
@@ -137,7 +126,7 @@ int cmd_rerere(int argc, const char **argv, const char *prefix)
126 for (i = 0; i < merge_rr.nr; i++) {
127 const char *path = merge_rr.items[i].string;
128 const char *name = (const char *)merge_rr.items[i].util;
140 - diff_two(rr_path(name, "preimage"), path, path, path);
129 + diff_two(rerere_path(name, "preimage"), path, path, path);
130 }
131 else
132 usage(git_rerere_usage);
rerere.c
+11 -11
@@ -12,15 +12,15 @@ static int rerere_autoupdate;
12
13 static char *merge_rr_path;
14
15 -static const char *rr_path(const char *name, const char *file)
15 +const char *rerere_path(const char *hex, const char *file)
16 {
17 - return git_path("rr-cache/%s/%s", name, file);
17 + return git_path("rr-cache/%s/%s", hex, file);
18 }
19
20 -static int has_resolution(const char *name)
20 +int has_rerere_resolution(const char *hex)
21 {
22 struct stat st;
23 - return !stat(rr_path(name, "postimage"), &st);
23 + return !stat(rerere_path(hex, "postimage"), &st);
24 }
25
26 static void read_rr(struct string_list *rr)
@@ -208,12 +208,12 @@ static int merge(const char *name, const char *path)
208 mmbuffer_t result = {NULL, 0};
209 xpparam_t xpp = {XDF_NEED_MINIMAL};
210
211 - if (handle_file(path, NULL, rr_path(name, "thisimage")) < 0)
211 + if (handle_file(path, NULL, rerere_path(name, "thisimage")) < 0)
212 return 1;
213
214 - if (read_mmfile(&cur, rr_path(name, "thisimage")) ||
215 - read_mmfile(&base, rr_path(name, "preimage")) ||
216 - read_mmfile(&other, rr_path(name, "postimage")))
214 + if (read_mmfile(&cur, rerere_path(name, "thisimage")) ||
215 + read_mmfile(&base, rerere_path(name, "preimage")) ||
216 + read_mmfile(&other, rerere_path(name, "postimage")))
217 return 1;
218 ret = xdl_merge(&base, &cur, "", &other, "",
219 &xpp, XDL_MERGE_ZEALOUS, &result);
@@ -291,7 +291,7 @@ static int do_plain_rerere(struct string_list *rr, int fd)
291 string_list_insert(path, rr)->util = hex;
292 if (mkdir(git_path("rr-cache/%s", hex), 0755))
293 continue;
294 - handle_file(path, NULL, rr_path(hex, "preimage"));
294 + handle_file(path, NULL, rerere_path(hex, "preimage"));
295 fprintf(stderr, "Recorded preimage for '%s'\n", path);
296 }
297 }
@@ -307,7 +307,7 @@ static int do_plain_rerere(struct string_list *rr, int fd)
307 const char *path = rr->items[i].string;
308 const char *name = (const char *)rr->items[i].util;
309
310 - if (has_resolution(name)) {
310 + if (has_rerere_resolution(name)) {
311 if (!merge(name, path)) {
312 if (rerere_autoupdate)
313 string_list_insert(path, &update);
@@ -326,7 +326,7 @@ static int do_plain_rerere(struct string_list *rr, int fd)
326 continue;
327
328 fprintf(stderr, "Recorded resolution for '%s'.\n", path);
329 - copy_file(rr_path(name, "postimage"), path, 0666);
329 + copy_file(rerere_path(name, "postimage"), path, 0666);
330 mark_resolved:
331 rr->items[i].util = NULL;
332 }
rerere.h
+2
@@ -5,5 +5,7 @@
5
6 extern int setup_rerere(struct string_list *);
7 extern int rerere(void);
8 +extern const char *rerere_path(const char *hex, const char *file);
9 +extern int has_rerere_resolution(const char *hex);
10
11 #endif