summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 73f0362)
raw | patch | inline | side by side (parent: 73f0362)
author | Junio C Hamano <gitster@pobox.com> | |
Sun, 22 Jun 2008 06:28:58 +0000 (23:28 -0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Sun, 22 Jun 2008 07:44:26 +0000 (00:44 -0700) |
There were too many places in the code how an entry in the rerere database
looks like, and the garbage_collect() function that iterates over
subdirectories of the rr-cache directory was the worse offender.
Introduce two helper functions, rerere_created_at() and has_resolution(),
to abstract out the logic a bit better.
Incidentally this fixes a small memory leak in garbage_collect()
function. The path list to collect the entries to be pruned were defined
to strdup the paths but the caller was feeding a path after doing an extra
copy. Because the list does not have to be sorted by conflict signature
hash, we use path_list_append() instead of path_list_insert().
While we are at it, make a conflicted hunk comparision in handle_file() a
bit easier to read.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
looks like, and the garbage_collect() function that iterates over
subdirectories of the rr-cache directory was the worse offender.
Introduce two helper functions, rerere_created_at() and has_resolution(),
to abstract out the logic a bit better.
Incidentally this fixes a small memory leak in garbage_collect()
function. The path list to collect the entries to be pruned were defined
to strdup the paths but the caller was feeding a path after doing an extra
copy. Because the list does not have to be sorted by conflict signature
hash, we use path_list_append() instead of path_list_insert().
While we are at it, make a conflicted hunk comparision in handle_file() a
bit easier to read.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin-rerere.c | patch | blob | history |
diff --git a/builtin-rerere.c b/builtin-rerere.c
index 85222d9bc591e0b603bf6f33c32d6bb1bad479ee..610b96a1202cdbf17c1b930d8b432e2262f5ffd3 100644 (file)
--- a/builtin-rerere.c
+++ b/builtin-rerere.c
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);
+}
+
static void read_rr(struct path_list *rr)
{
unsigned char sha1[20];
else if (!prefixcmp(buf, "======="))
hunk = 2;
else if (!prefixcmp(buf, ">>>>>>> ")) {
- int cmp = strbuf_cmp(&one, &two);
-
+ if (strbuf_cmp(&one, &two) > 0)
+ strbuf_swap(&one, &two);
hunk_no++;
hunk = 0;
- if (cmp > 0) {
- strbuf_swap(&one, &two);
- }
if (out) {
fputs("<<<<<<<\n", out);
fwrite(one.buf, one.len, 1, out);
static void garbage_collect(struct path_list *rr)
{
struct path_list to_remove = { NULL, 0, 0, 1 };
- char buf[1024];
DIR *dir;
struct dirent *e;
- int len, i, cutoff;
+ int i, cutoff;
time_t now = time(NULL), then;
- strlcpy(buf, git_path("rr-cache"), sizeof(buf));
- len = strlen(buf);
- dir = opendir(buf);
- strcpy(buf + len++, "/");
+ dir = opendir(git_path("rr-cache"));
while ((e = readdir(dir))) {
const char *name = e->d_name;
- struct stat st;
- if (name[0] == '.' && (name[1] == '\0' ||
- (name[1] == '.' && name[2] == '\0')))
+ if (name[0] == '.' &&
+ (name[1] == '\0' || (name[1] == '.' && name[2] == '\0')))
continue;
- i = snprintf(buf + len, sizeof(buf) - len, "%s", name);
- strlcpy(buf + len + i, "/preimage", sizeof(buf) - len - i);
- if (stat(buf, &st))
+ then = rerere_created_at(name);
+ if (!then)
continue;
- then = st.st_mtime;
- strlcpy(buf + len + i, "/postimage", sizeof(buf) - len - i);
- cutoff = stat(buf, &st) ? cutoff_noresolve : cutoff_resolve;
- if (then < now - cutoff * 86400) {
- buf[len + i] = '\0';
- path_list_insert(xstrdup(name), &to_remove);
- }
+ cutoff = (has_resolution(name)
+ ? cutoff_resolve : cutoff_noresolve);
+ if (then < now - cutoff * 86400)
+ path_list_append(name, &to_remove);
}
for (i = 0; i < to_remove.nr; i++)
unlink_rr_item(to_remove.items[i].path);
*/
for (i = 0; i < rr->nr; i++) {
- struct stat st;
int ret;
const char *path = rr->items[i].path;
const char *name = (const char *)rr->items[i].util;
- if (!stat(rr_path(name, "preimage"), &st) &&
- !stat(rr_path(name, "postimage"), &st)) {
+ if (has_resolution(name)) {
if (!merge(name, path)) {
fprintf(stderr, "Resolved '%s' using "
"previous resolution.\n", path);
return do_plain_rerere(&merge_rr, fd);
else if (!strcmp(argv[1], "clear")) {
for (i = 0; i < merge_rr.nr; i++) {
- struct stat st;
const char *name = (const char *)merge_rr.items[i].util;
- if (!stat(git_path("rr-cache/%s", name), &st) &&
- S_ISDIR(st.st_mode) &&
- stat(rr_path(name, "postimage"), &st))
+ if (!has_resolution(name))
unlink_rr_item(name);
}
unlink(merge_rr_path);