Skip to content

Commit

Permalink
Merge branch 'sg/rerere-cleanup'
Browse files Browse the repository at this point in the history
* sg/rerere-cleanup:
  rerere: remove duplicated functions
  • Loading branch information
Junio C Hamano committed Mar 5, 2009
2 parents db22557 + 9005696 commit c067e1e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 29 deletions.
25 changes: 7 additions & 18 deletions builtin-rerere.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,17 @@ static const char git_rerere_usage[] =
static int cutoff_noresolve = 15;
static int cutoff_resolve = 60;

static const char *rr_path(const char *name, const char *file)
{
return git_path("rr-cache/%s/%s", name, file);
}

static time_t rerere_created_at(const char *name)
{
struct stat st;
return stat(rr_path(name, "preimage"), &st) ? (time_t) 0 : st.st_mtime;
}

static int has_resolution(const char *name)
{
struct stat st;
return !stat(rr_path(name, "postimage"), &st);
return stat(rerere_path(name, "preimage"), &st) ? (time_t) 0 : st.st_mtime;
}

static void unlink_rr_item(const char *name)
{
unlink(rr_path(name, "thisimage"));
unlink(rr_path(name, "preimage"));
unlink(rr_path(name, "postimage"));
unlink(rerere_path(name, "thisimage"));
unlink(rerere_path(name, "preimage"));
unlink(rerere_path(name, "postimage"));
rmdir(git_path("rr-cache/%s", name));
}

Expand Down Expand Up @@ -65,7 +54,7 @@ static void garbage_collect(struct string_list *rr)
then = rerere_created_at(e->d_name);
if (!then)
continue;
cutoff = (has_resolution(e->d_name)
cutoff = (has_rerere_resolution(e->d_name)
? cutoff_resolve : cutoff_noresolve);
if (then < now - cutoff * 86400)
string_list_append(e->d_name, &to_remove);
Expand Down Expand Up @@ -124,7 +113,7 @@ int cmd_rerere(int argc, const char **argv, const char *prefix)
if (!strcmp(argv[1], "clear")) {
for (i = 0; i < merge_rr.nr; i++) {
const char *name = (const char *)merge_rr.items[i].util;
if (!has_resolution(name))
if (!has_rerere_resolution(name))
unlink_rr_item(name);
}
unlink(git_path("rr-cache/MERGE_RR"));
Expand All @@ -137,7 +126,7 @@ int cmd_rerere(int argc, const char **argv, const char *prefix)
for (i = 0; i < merge_rr.nr; i++) {
const char *path = merge_rr.items[i].string;
const char *name = (const char *)merge_rr.items[i].util;
diff_two(rr_path(name, "preimage"), path, path, path);
diff_two(rerere_path(name, "preimage"), path, path, path);
}
else
usage(git_rerere_usage);
Expand Down
22 changes: 11 additions & 11 deletions rerere.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ static int rerere_autoupdate;

static char *merge_rr_path;

static const char *rr_path(const char *name, const char *file)
const char *rerere_path(const char *hex, const char *file)
{
return git_path("rr-cache/%s/%s", name, file);
return git_path("rr-cache/%s/%s", hex, file);
}

static int has_resolution(const char *name)
int has_rerere_resolution(const char *hex)
{
struct stat st;
return !stat(rr_path(name, "postimage"), &st);
return !stat(rerere_path(hex, "postimage"), &st);
}

static void read_rr(struct string_list *rr)
Expand Down Expand Up @@ -208,12 +208,12 @@ static int merge(const char *name, const char *path)
mmbuffer_t result = {NULL, 0};
xpparam_t xpp = {XDF_NEED_MINIMAL};

if (handle_file(path, NULL, rr_path(name, "thisimage")) < 0)
if (handle_file(path, NULL, rerere_path(name, "thisimage")) < 0)
return 1;

if (read_mmfile(&cur, rr_path(name, "thisimage")) ||
read_mmfile(&base, rr_path(name, "preimage")) ||
read_mmfile(&other, rr_path(name, "postimage")))
if (read_mmfile(&cur, rerere_path(name, "thisimage")) ||
read_mmfile(&base, rerere_path(name, "preimage")) ||
read_mmfile(&other, rerere_path(name, "postimage")))
return 1;
ret = xdl_merge(&base, &cur, "", &other, "",
&xpp, XDL_MERGE_ZEALOUS, &result);
Expand Down Expand Up @@ -291,7 +291,7 @@ static int do_plain_rerere(struct string_list *rr, int fd)
string_list_insert(path, rr)->util = hex;
if (mkdir(git_path("rr-cache/%s", hex), 0755))
continue;
handle_file(path, NULL, rr_path(hex, "preimage"));
handle_file(path, NULL, rerere_path(hex, "preimage"));
fprintf(stderr, "Recorded preimage for '%s'\n", path);
}
}
Expand All @@ -307,7 +307,7 @@ static int do_plain_rerere(struct string_list *rr, int fd)
const char *path = rr->items[i].string;
const char *name = (const char *)rr->items[i].util;

if (has_resolution(name)) {
if (has_rerere_resolution(name)) {
if (!merge(name, path)) {
if (rerere_autoupdate)
string_list_insert(path, &update);
Expand All @@ -326,7 +326,7 @@ static int do_plain_rerere(struct string_list *rr, int fd)
continue;

fprintf(stderr, "Recorded resolution for '%s'.\n", path);
copy_file(rr_path(name, "postimage"), path, 0666);
copy_file(rerere_path(name, "postimage"), path, 0666);
mark_resolved:
rr->items[i].util = NULL;
}
Expand Down
2 changes: 2 additions & 0 deletions rerere.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@

extern int setup_rerere(struct string_list *);
extern int rerere(void);
extern const char *rerere_path(const char *hex, const char *file);
extern int has_rerere_resolution(const char *hex);

#endif

0 comments on commit c067e1e

Please sign in to comment.