Merge branch 'jk/am-rerere-lock-fix'

Recent "git am" introduced a double-locking failure when used with
the "--3way" option that invokes rerere machinery.

* jk/am-rerere-lock-fix:
  rerere: release lockfile in non-writing functions
This commit is contained in:
Junio C Hamano 2015-09-03 14:14:01 -07:00
commit 7662973ea3
5 changed files with 61 additions and 16 deletions

View File

@ -2057,11 +2057,6 @@ static int clean_index(const unsigned char *head, const unsigned char *remote)
static void am_rerere_clear(void)
{
struct string_list merge_rr = STRING_LIST_INIT_DUP;
int fd = setup_rerere(&merge_rr, 0);
if (fd < 0)
return;
rerere_clear(&merge_rr);
string_list_clear(&merge_rr, 1);
}

View File

@ -50,7 +50,7 @@ static int diff_two(const char *file1, const char *label1,
int cmd_rerere(int argc, const char **argv, const char *prefix)
{
struct string_list merge_rr = STRING_LIST_INIT_DUP;
int i, fd, autoupdate = -1, flags = 0;
int i, autoupdate = -1, flags = 0;
struct option options[] = {
OPT_SET_INT(0, "rerere-autoupdate", &autoupdate,
@ -79,18 +79,16 @@ int cmd_rerere(int argc, const char **argv, const char *prefix)
return rerere_forget(&pathspec);
}
fd = setup_rerere(&merge_rr, flags);
if (fd < 0)
return 0;
if (!strcmp(argv[0], "clear")) {
rerere_clear(&merge_rr);
} else if (!strcmp(argv[0], "gc"))
rerere_gc(&merge_rr);
else if (!strcmp(argv[0], "status"))
else if (!strcmp(argv[0], "status")) {
if (setup_rerere(&merge_rr, flags | RERERE_READONLY) < 0)
return 0;
for (i = 0; i < merge_rr.nr; i++)
printf("%s\n", merge_rr.items[i].string);
else if (!strcmp(argv[0], "remaining")) {
} else if (!strcmp(argv[0], "remaining")) {
rerere_remaining(&merge_rr);
for (i = 0; i < merge_rr.nr; i++) {
if (merge_rr.items[i].util != RERERE_RESOLVED)
@ -100,13 +98,15 @@ int cmd_rerere(int argc, const char **argv, const char *prefix)
* string_list_clear() */
merge_rr.items[i].util = NULL;
}
} else if (!strcmp(argv[0], "diff"))
} else if (!strcmp(argv[0], "diff")) {
if (setup_rerere(&merge_rr, flags | RERERE_READONLY) < 0)
return 0;
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(rerere_path(name, "preimage"), path, path, path);
}
else
} else
usage_with_options(rerere_usage, options);
string_list_clear(&merge_rr, 1);

View File

@ -409,6 +409,8 @@ static int find_conflict(struct string_list *conflict)
int rerere_remaining(struct string_list *merge_rr)
{
int i;
if (setup_rerere(merge_rr, RERERE_READONLY))
return 0;
if (read_cache() < 0)
return error("Could not read index");
@ -603,8 +605,11 @@ int setup_rerere(struct string_list *merge_rr, int flags)
if (flags & (RERERE_AUTOUPDATE|RERERE_NOAUTOUPDATE))
rerere_autoupdate = !!(flags & RERERE_AUTOUPDATE);
fd = hold_lock_file_for_update(&write_lock, git_path_merge_rr(),
LOCK_DIE_ON_ERROR);
if (flags & RERERE_READONLY)
fd = 0;
else
fd = hold_lock_file_for_update(&write_lock, git_path_merge_rr(),
LOCK_DIE_ON_ERROR);
read_rr(merge_rr);
return fd;
}
@ -701,6 +706,9 @@ void rerere_gc(struct string_list *rr)
int cutoff_noresolve = 15;
int cutoff_resolve = 60;
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(git_default_config, NULL);
@ -727,16 +735,21 @@ void rerere_gc(struct string_list *rr)
for (i = 0; i < to_remove.nr; i++)
unlink_rr_item(to_remove.items[i].string);
string_list_clear(&to_remove, 0);
rollback_lock_file(&write_lock);
}
void rerere_clear(struct string_list *merge_rr)
{
int i;
if (setup_rerere(merge_rr, 0) < 0)
return;
for (i = 0; i < merge_rr->nr; i++) {
const char *name = (const char *)merge_rr->items[i].util;
if (!has_rerere_resolution(name))
unlink_rr_item(name);
}
unlink_or_warn(git_path_merge_rr());
rollback_lock_file(&write_lock);
}

View File

@ -7,6 +7,7 @@ struct pathspec;
#define RERERE_AUTOUPDATE 01
#define RERERE_NOAUTOUPDATE 02
#define RERERE_READONLY 04
/*
* Marks paths that have been hand-resolved and added to the

View File

@ -873,4 +873,40 @@ test_expect_success 'am --message-id -s signs off after the message id' '
test_cmp expected actual
'
test_expect_success 'am -3 works with rerere' '
rm -fr .git/rebase-apply &&
git reset --hard &&
# make patches one->two and two->three...
test_commit one file &&
test_commit two file &&
test_commit three file &&
git format-patch -2 --stdout >seq.patch &&
# and create a situation that conflicts...
git reset --hard one &&
test_commit other file &&
# enable rerere...
test_config rerere.enabled true &&
test_when_finished "rm -rf .git/rr-cache" &&
# ...and apply. Our resolution is to skip the first
# patch, and the rerere the second one.
test_must_fail git am -3 seq.patch &&
test_must_fail git am --skip &&
echo resolved >file &&
git add file &&
git am --resolved &&
# now apply again, and confirm that rerere engaged (we still
# expect failure from am because rerere does not auto-commit
# for us).
git reset --hard other &&
test_must_fail git am -3 seq.patch &&
test_must_fail git am --skip &&
echo resolved >expect &&
test_cmp expect file
'
test_done