id->variant = variant;
}
-const char *rerere_path(const struct rerere_id *id, const char *file)
+const char *rerere_path(struct strbuf *buf, const struct rerere_id *id, const char *file)
{
if (!file)
- return git_path("rr-cache/%s", rerere_id_hex(id));
+ return repo_git_path_replace(the_repository, buf, "rr-cache/%s",
+ rerere_id_hex(id));
if (id->variant <= 0)
- return git_path("rr-cache/%s/%s", rerere_id_hex(id), file);
+ return repo_git_path_replace(the_repository, buf, "rr-cache/%s/%s",
+ rerere_id_hex(id), file);
- return git_path("rr-cache/%s/%s.%d",
- rerere_id_hex(id), file, id->variant);
+ return repo_git_path_replace(the_repository, buf, "rr-cache/%s/%s.%d",
+ rerere_id_hex(id), file, id->variant);
}
static int is_rr_file(const char *name, const char *filename, int *variant)
{
enum ll_merge_result ret;
mmfile_t base = {NULL, 0}, other = {NULL, 0};
+ struct strbuf buf = STRBUF_INIT;
- if (read_mmfile(&base, rerere_path(id, "preimage")) ||
- read_mmfile(&other, rerere_path(id, "postimage"))) {
+ if (read_mmfile(&base, rerere_path(&buf, id, "preimage")) ||
+ read_mmfile(&other, rerere_path(&buf, id, "postimage"))) {
ret = LL_MERGE_CONFLICT;
} else {
/*
istate, NULL);
}
+ strbuf_release(&buf);
free(base.ptr);
free(other.ptr);
{
FILE *f;
int ret;
+ struct strbuf buf = STRBUF_INIT;
mmfile_t cur = {NULL, 0};
mmbuffer_t result = {NULL, 0};
* Normalize the conflicts in path and write it out to
* "thisimage" temporary file.
*/
- if ((handle_file(istate, path, NULL, rerere_path(id, "thisimage")) < 0) ||
- read_mmfile(&cur, rerere_path(id, "thisimage"))) {
+ if ((handle_file(istate, path, NULL, rerere_path(&buf, id, "thisimage")) < 0) ||
+ read_mmfile(&cur, rerere_path(&buf, id, "thisimage"))) {
ret = 1;
goto out;
}
* A successful replay of recorded resolution.
* Mark that "postimage" was used to help gc.
*/
- if (utime(rerere_path(id, "postimage"), NULL) < 0)
+ if (utime(rerere_path(&buf, id, "postimage"), NULL) < 0)
warning_errno(_("failed utime() on '%s'"),
- rerere_path(id, "postimage"));
+ rerere_path(&buf, id, "postimage"));
/* Update "path" with the resolution */
f = fopen(path, "w");
out:
free(cur.ptr);
free(result.ptr);
+ strbuf_release(&buf);
return ret;
}
static void remove_variant(struct rerere_id *id)
{
- unlink_or_warn(rerere_path(id, "postimage"));
- unlink_or_warn(rerere_path(id, "preimage"));
+ struct strbuf buf = STRBUF_INIT;
+ unlink_or_warn(rerere_path(&buf, id, "postimage"));
+ unlink_or_warn(rerere_path(&buf, id, "preimage"));
id->collection->status[id->variant] = 0;
+ strbuf_release(&buf);
}
/*
const char *path = rr_item->string;
struct rerere_id *id = rr_item->util;
struct rerere_dir *rr_dir = id->collection;
+ struct strbuf buf = STRBUF_INIT;
int variant;
variant = id->variant;
/* Has the user resolved it already? */
if (variant >= 0) {
if (!handle_file(istate, path, NULL, NULL)) {
- copy_file(rerere_path(id, "postimage"), path, 0666);
+ copy_file(rerere_path(&buf, id, "postimage"), path, 0666);
id->collection->status[variant] |= RR_HAS_POSTIMAGE;
fprintf_ln(stderr, _("Recorded resolution for '%s'."), path);
free_rerere_id(rr_item);
rr_item->util = NULL;
- return;
+ goto out;
}
/*
* There may be other variants that can cleanly
path);
free_rerere_id(rr_item);
rr_item->util = NULL;
- return;
+ goto out;
}
/* None of the existing one applies; we need a new variant */
assign_variant(id);
variant = id->variant;
- handle_file(istate, path, NULL, rerere_path(id, "preimage"));
+ handle_file(istate, path, NULL, rerere_path(&buf, id, "preimage"));
if (id->collection->status[variant] & RR_HAS_POSTIMAGE) {
- const char *path = rerere_path(id, "postimage");
+ const char *path = rerere_path(&buf, id, "postimage");
if (unlink(path))
die_errno(_("cannot unlink stray '%s'"), path);
id->collection->status[variant] &= ~RR_HAS_POSTIMAGE;
}
id->collection->status[variant] |= RR_HAS_PREIMAGE;
fprintf_ln(stderr, _("Recorded preimage for '%s'"), path);
+
+out:
+ strbuf_release(&buf);
}
static int do_plain_rerere(struct repository *r,
{
struct string_list conflict = STRING_LIST_INIT_DUP;
struct string_list update = STRING_LIST_INIT_DUP;
+ struct strbuf buf = STRBUF_INIT;
int i;
find_conflict(r, &conflict);
string_list_insert(rr, path)->util = id;
/* Ensure that the directory exists. */
- mkdir_in_gitdir(rerere_path(id, NULL));
+ mkdir_in_gitdir(rerere_path(&buf, id, NULL));
}
for (i = 0; i < rr->nr; i++)
string_list_clear(&conflict, 0);
string_list_clear(&update, 0);
+ strbuf_release(&buf);
return write_rr(rr, fd);
}
struct rerere_id *id;
unsigned char hash[GIT_MAX_RAWSZ];
int ret;
+ struct strbuf buf = STRBUF_INIT;
struct string_list_item *item;
/*
if (!has_rerere_resolution(id))
continue;
- handle_cache(istate, path, hash, rerere_path(id, "thisimage"));
- if (read_mmfile(&cur, rerere_path(id, "thisimage"))) {
+ handle_cache(istate, path, hash, rerere_path(&buf, id, "thisimage"));
+ if (read_mmfile(&cur, rerere_path(&buf, id, "thisimage"))) {
free(cur.ptr);
error(_("failed to update conflicted state in '%s'"), path);
goto fail_exit;
goto fail_exit;
}
- filename = rerere_path(id, "postimage");
+ filename = rerere_path(&buf, id, "postimage");
if (unlink(filename)) {
if (errno == ENOENT)
error(_("no remembered resolution for '%s'"), path);
* conflict in the working tree, run us again to record
* the postimage.
*/
- handle_cache(istate, path, hash, rerere_path(id, "preimage"));
+ handle_cache(istate, path, hash, rerere_path(&buf, id, "preimage"));
fprintf_ln(stderr, _("Updated preimage for '%s'"), path);
/*
free_rerere_id(item);
item->util = id;
fprintf(stderr, _("Forgot resolution for '%s'\n"), path);
+ strbuf_release(&buf);
return 0;
fail_exit:
+ strbuf_release(&buf);
free(id);
return -1;
}
static timestamp_t rerere_created_at(struct rerere_id *id)
{
+ struct strbuf buf = STRBUF_INIT;
struct stat st;
+ timestamp_t ret;
+
+ ret = stat(rerere_path(&buf, id, "preimage"), &st) ? (time_t) 0 : st.st_mtime;
- return stat(rerere_path(id, "preimage"), &st) ? (time_t) 0 : st.st_mtime;
+ strbuf_release(&buf);
+ return ret;
}
static timestamp_t rerere_last_used_at(struct rerere_id *id)
{
+ struct strbuf buf = STRBUF_INIT;
struct stat st;
+ timestamp_t ret;
+
+ ret = stat(rerere_path(&buf, id, "postimage"), &st) ? (time_t) 0 : st.st_mtime;
- return stat(rerere_path(id, "postimage"), &st) ? (time_t) 0 : st.st_mtime;
+ strbuf_release(&buf);
+ return ret;
}
/*
*/
static void unlink_rr_item(struct rerere_id *id)
{
- unlink_or_warn(rerere_path(id, "thisimage"));
+ struct strbuf buf = STRBUF_INIT;
+ unlink_or_warn(rerere_path(&buf, id, "thisimage"));
remove_variant(id);
id->collection->status[id->variant] = 0;
+ strbuf_release(&buf);
}
static void prune_one(struct rerere_id *id,
for (i = 0; i < merge_rr->nr; i++) {
struct rerere_id *id = merge_rr->items[i].util;
+ struct strbuf buf = STRBUF_INIT;
+
if (!has_rerere_resolution(id)) {
unlink_rr_item(id);
- rmdir(rerere_path(id, NULL));
+ rmdir(rerere_path(&buf, id, NULL));
}
+
+ strbuf_release(&buf);
}
unlink_or_warn(git_path_merge_rr(r));
rollback_lock_file(&write_lock);