#include "ll-merge.h"
#include "attr.h"
#include "pathspec.h"
+#include "object-store.h"
#include "sha1-lookup.h"
#define RESOLVED 0
ALLOC_GROW(rerere_dir, rerere_dir_nr + 1, rerere_dir_alloc);
/* ... and add it in. */
rerere_dir_nr++;
- memmove(rerere_dir + pos + 1, rerere_dir + pos,
- (rerere_dir_nr - pos - 1) * sizeof(*rerere_dir));
+ MOVE_ARRAY(rerere_dir + pos + 1, rerere_dir + pos,
+ rerere_dir_nr - pos - 1);
rerere_dir[pos] = rr_dir;
scan_rerere_dir(rr_dir);
}
static void read_rr(struct string_list *rr)
{
struct strbuf buf = STRBUF_INIT;
- FILE *in = fopen_or_warn(git_path_merge_rr(), "r");
+ FILE *in = fopen_or_warn(git_path_merge_rr(the_repository), "r");
if (!in)
return;
return ret;
}
-static struct lock_file index_lock;
-
static void update_paths(struct string_list *update)
{
+ struct lock_file index_lock = LOCK_INIT;
int i;
hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);
item->string);
}
- if (active_cache_changed) {
- if (write_locked_index(&the_index, &index_lock, COMMIT_LOCK))
- die("Unable to write new index file");
- } else
- rollback_lock_file(&index_lock);
+ if (write_locked_index(&the_index, &index_lock,
+ COMMIT_LOCK | SKIP_IF_UNCHANGED))
+ die("Unable to write new index file");
}
static void remove_variant(struct rerere_id *id)
if (flags & RERERE_READONLY)
fd = 0;
else
- fd = hold_lock_file_for_update(&write_lock, git_path_merge_rr(),
+ fd = hold_lock_file_for_update(&write_lock,
+ git_path_merge_rr(the_repository),
LOCK_DIE_ON_ERROR);
read_rr(merge_rr);
return fd;
break;
i = ce_stage(ce) - 1;
if (!mmfile[i].ptr) {
- mmfile[i].ptr = read_sha1_file(ce->oid.hash, &type,
- &size);
+ mmfile[i].ptr = read_object_file(&ce->oid, &type,
+ &size);
mmfile[i].size = size;
}
}
* Garbage collection support
*/
-static time_t rerere_created_at(struct rerere_id *id)
+static timestamp_t rerere_created_at(struct rerere_id *id)
{
struct stat st;
return stat(rerere_path(id, "preimage"), &st) ? (time_t) 0 : st.st_mtime;
}
-static time_t rerere_last_used_at(struct rerere_id *id)
+static timestamp_t rerere_last_used_at(struct rerere_id *id)
{
struct stat st;
id->collection->status[id->variant] = 0;
}
-static void prune_one(struct rerere_id *id, time_t now,
- int cutoff_resolve, int cutoff_noresolve)
+static void prune_one(struct rerere_id *id,
+ timestamp_t cutoff_resolve, timestamp_t cutoff_noresolve)
{
- time_t then;
- int cutoff;
+ timestamp_t then;
+ timestamp_t cutoff;
then = rerere_last_used_at(id);
if (then)
return;
cutoff = cutoff_noresolve;
}
- if (then < now - cutoff * 86400)
+ if (then < cutoff)
unlink_rr_item(id);
}
DIR *dir;
struct dirent *e;
int i;
- time_t now = time(NULL);
- int cutoff_noresolve = 15;
- int cutoff_resolve = 60;
+ timestamp_t now = time(NULL);
+ timestamp_t cutoff_noresolve = now - 15 * 86400;
+ timestamp_t cutoff_resolve = now - 60 * 86400;
if (setup_rerere(rr, 0) < 0)
return;
- git_config_get_int("gc.rerereresolved", &cutoff_resolve);
- git_config_get_int("gc.rerereunresolved", &cutoff_noresolve);
+ git_config_get_expiry_in_days("gc.rerereresolved", &cutoff_resolve, now);
+ git_config_get_expiry_in_days("gc.rerereunresolved", &cutoff_noresolve, now);
git_config(git_default_config, NULL);
dir = opendir(git_path("rr-cache"));
if (!dir)
for (id.variant = 0, id.collection = rr_dir;
id.variant < id.collection->status_nr;
id.variant++) {
- prune_one(&id, now, cutoff_resolve, cutoff_noresolve);
+ prune_one(&id, cutoff_resolve, cutoff_noresolve);
if (id.collection->status[id.variant])
now_empty = 0;
}
rmdir(rerere_path(id, NULL));
}
}
- unlink_or_warn(git_path_merge_rr());
+ unlink_or_warn(git_path_merge_rr(the_repository));
rollback_lock_file(&write_lock);
}