Merge branch 'tb/rerere-wait-for-merge-rr-lock'
Instead of failing to record conflicts to be resolved immediately, wait while "rerere gc" is ongoing. * tb/rerere-wait-for-merge-rr-lock: rerere: add "gc --skip-locked" for auto maintenance rerere: wait for MERGE_RR.lock before giving up
This commit is contained in:
commit
8814f276c0
7 files changed
+156
-11
No files matched your search
@@ -10,3 +10,12 @@ rerere.enabled::
|
||||
enabled if there is an `rr-cache` directory under the
|
||||
`$GIT_DIR`, e.g. if "rerere" was previously used in the
|
||||
repository.
|
||||
|
||||
rerere.lockTimeout::
|
||||
The length of time, in milliseconds, to wait for the rerere
|
||||
lock when another process holds it, typically a background
|
||||
`git rerere gc`. Value 0 means not to wait at all; -1 means
|
||||
to wait indefinitely. Default is 1000 (i.e., wait for 1
|
||||
second). A `git rerere gc` run by `git maintenance run --auto`
|
||||
or `git gc --auto` does not wait and does nothing while the
|
||||
lock is held.
|
||||
+3
-1
@@ -385,12 +385,14 @@ out:
|
||||
return should_prune;
|
||||
}
|
||||
|
||||
static int maintenance_task_rerere_gc(struct maintenance_run_opts *opts UNUSED,
|
||||
static int maintenance_task_rerere_gc(struct maintenance_run_opts *opts,
|
||||
struct gc_config *cfg UNUSED)
|
||||
{
|
||||
struct child_process rerere_cmd = CHILD_PROCESS_INIT;
|
||||
rerere_cmd.git_cmd = 1;
|
||||
strvec_pushl(&rerere_cmd.args, "rerere", "gc", NULL);
|
||||
if (opts->auto_flag)
|
||||
strvec_push(&rerere_cmd.args, "--skip-locked");
|
||||
return run_command(&rerere_cmd);
|
||||
}
|
||||
|
||||
|
||||
+8
-2
@@ -60,16 +60,21 @@ int cmd_rerere(int argc,
|
||||
struct repository *repo UNUSED)
|
||||
{
|
||||
struct string_list merge_rr = STRING_LIST_INIT_DUP;
|
||||
int autoupdate = -1, flags = 0;
|
||||
int autoupdate = -1, skip_locked = 0, flags = 0;
|
||||
|
||||
struct option options[] = {
|
||||
OPT_SET_INT(0, "rerere-autoupdate", &autoupdate,
|
||||
N_("register clean resolutions in index"), 1),
|
||||
OPT_HIDDEN_BOOL(0, "skip-locked", &skip_locked,
|
||||
N_("skip gc while another process holds the lock")),
|
||||
OPT_END(),
|
||||
};
|
||||
|
||||
argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
|
||||
|
||||
if (skip_locked && (argc < 1 || strcmp(argv[0], "gc")))
|
||||
die(_("the option '%s' requires '%s'"), "--skip-locked", "gc");
|
||||
|
||||
repo_config(the_repository, git_xmerge_config, NULL);
|
||||
|
||||
if (autoupdate == 1)
|
||||
@@ -98,7 +103,8 @@ int cmd_rerere(int argc,
|
||||
if (!strcmp(argv[0], "clear")) {
|
||||
rerere_clear(the_repository, &merge_rr);
|
||||
} else if (!strcmp(argv[0], "gc"))
|
||||
rerere_gc(the_repository, &merge_rr);
|
||||
rerere_gc(the_repository, &merge_rr,
|
||||
skip_locked ? RERERE_NOWAIT : 0);
|
||||
else if (!strcmp(argv[0], "status")) {
|
||||
if (setup_rerere(the_repository, &merge_rr,
|
||||
flags | RERERE_READONLY) < 0)
|
||||
|
||||
@@ -33,6 +33,9 @@ static int rerere_enabled = -1;
|
||||
/* automatically update cleanly resolved paths to the index */
|
||||
static int rerere_autoupdate;
|
||||
|
||||
/* how long to wait for MERGE_RR.lock, in milliseconds */
|
||||
static int rerere_lock_timeout_ms = 1000;
|
||||
|
||||
#define RR_HAS_POSTIMAGE 1
|
||||
#define RR_HAS_PREIMAGE 2
|
||||
struct rerere_dir {
|
||||
@@ -872,6 +875,8 @@ static void git_rerere_config(void)
|
||||
{
|
||||
repo_config_get_bool(the_repository, "rerere.enabled", &rerere_enabled);
|
||||
repo_config_get_bool(the_repository, "rerere.autoupdate", &rerere_autoupdate);
|
||||
repo_config_get_int(the_repository, "rerere.locktimeout",
|
||||
&rerere_lock_timeout_ms);
|
||||
repo_config(the_repository, git_default_config, NULL);
|
||||
}
|
||||
|
||||
@@ -904,12 +909,30 @@ int setup_rerere(struct repository *r, struct string_list *merge_rr, int flags)
|
||||
|
||||
if (flags & (RERERE_AUTOUPDATE|RERERE_NOAUTOUPDATE))
|
||||
rerere_autoupdate = !!(flags & RERERE_AUTOUPDATE);
|
||||
if (flags & RERERE_READONLY)
|
||||
if ((flags & RERERE_READONLY) && (flags & RERERE_NOWAIT))
|
||||
BUG("RERERE_NOWAIT does not apply with RERERE_READONLY");
|
||||
if (flags & RERERE_READONLY) {
|
||||
fd = 0;
|
||||
else
|
||||
fd = repo_hold_lock_file_for_update(r, &write_lock,
|
||||
} else {
|
||||
int lock_flags = LOCK_DIE_ON_ERROR;
|
||||
int timeout_ms = rerere_lock_timeout_ms;
|
||||
|
||||
if (flags & RERERE_NOWAIT) {
|
||||
lock_flags = 0;
|
||||
timeout_ms = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Another process may hold the lock for a while, e.g.
|
||||
* "git rerere gc" while it prunes rr-cache, so by default
|
||||
* wait for it instead of dying right away.
|
||||
*/
|
||||
fd = repo_hold_lock_file_for_update_timeout(r, &write_lock,
|
||||
git_path_merge_rr(r),
|
||||
LOCK_DIE_ON_ERROR);
|
||||
lock_flags, timeout_ms);
|
||||
if (fd < 0)
|
||||
return -1;
|
||||
}
|
||||
read_rr(r, merge_rr);
|
||||
return fd;
|
||||
}
|
||||
@@ -1293,7 +1316,7 @@ out:
|
||||
return needed;
|
||||
}
|
||||
|
||||
void rerere_gc(struct repository *r, struct string_list *rr)
|
||||
void rerere_gc(struct repository *r, struct string_list *rr, int flags)
|
||||
{
|
||||
struct string_list to_remove = STRING_LIST_INIT_DUP;
|
||||
DIR *dir;
|
||||
@@ -1303,7 +1326,7 @@ void rerere_gc(struct repository *r, struct string_list *rr)
|
||||
timestamp_t cutoff_resolve;
|
||||
struct strbuf buf = STRBUF_INIT;
|
||||
|
||||
if (setup_rerere(r, rr, 0) < 0)
|
||||
if (setup_rerere(r, rr, flags) < 0)
|
||||
return;
|
||||
|
||||
rerere_gc_cutoffs(r, &cutoff_resolve, &cutoff_noresolve);
|
||||
|
||||
@@ -10,6 +10,8 @@ struct repository;
|
||||
#define RERERE_AUTOUPDATE 01
|
||||
#define RERERE_NOAUTOUPDATE 02
|
||||
#define RERERE_READONLY 04
|
||||
/* If MERGE_RR.lock is taken, return -1 as if rerere were disabled */
|
||||
#define RERERE_NOWAIT 010
|
||||
|
||||
/*
|
||||
* Marks paths that have been hand-resolved and added to the
|
||||
@@ -37,7 +39,7 @@ const char *rerere_path(struct strbuf *buf, const struct rerere_id *,
|
||||
int rerere_forget(struct repository *, struct pathspec *);
|
||||
int rerere_remaining(struct repository *, struct string_list *);
|
||||
void rerere_clear(struct repository *, struct string_list *);
|
||||
void rerere_gc(struct repository *, struct string_list *);
|
||||
void rerere_gc(struct repository *, struct string_list *, int);
|
||||
|
||||
/*
|
||||
* Check whether garbage collection for rerere entries is needed, which is
|
||||
|
||||
@@ -242,6 +242,85 @@ test_expect_success 'old records rest in peace' '
|
||||
test_path_is_missing $rr2/preimage
|
||||
'
|
||||
|
||||
test_expect_success 'gc --skip-locked does nothing while MERGE_RR is locked' '
|
||||
mkdir -p $rr2 &&
|
||||
echo Hello >$rr2/preimage &&
|
||||
test-tool chmtime =$just_over_15_days_ago $rr2/preimage &&
|
||||
|
||||
test_when_finished "rm -f .git/MERGE_RR.lock" &&
|
||||
>.git/MERGE_RR.lock &&
|
||||
git rerere gc --skip-locked 2>err &&
|
||||
test_must_be_empty err &&
|
||||
test_path_is_file $rr2/preimage
|
||||
'
|
||||
|
||||
test_expect_success 'gc --skip-locked prunes while MERGE_RR is not locked' '
|
||||
mkdir -p $rr2 &&
|
||||
echo Hello >$rr2/preimage &&
|
||||
test-tool chmtime =$just_over_15_days_ago $rr2/preimage &&
|
||||
|
||||
git rerere gc --skip-locked &&
|
||||
test_path_is_missing $rr2/preimage
|
||||
'
|
||||
|
||||
test_expect_success '--skip-locked is only accepted by gc' '
|
||||
test_must_fail git rerere --skip-locked clear 2>err &&
|
||||
test_grep "option .--skip-locked. requires .gc." err
|
||||
'
|
||||
|
||||
test_expect_success 'a held lock is waited out within rerere.lockTimeout' '
|
||||
git reset --hard &&
|
||||
rm -rf $rr &&
|
||||
test_when_finished "wait && rm -f .git/MERGE_RR.lock" &&
|
||||
>.git/MERGE_RR.lock &&
|
||||
{
|
||||
( sleep 1 && rm -f .git/MERGE_RR.lock ) &
|
||||
} &&
|
||||
test_must_fail git -c rerere.lockTimeout=5000 merge first 2>err &&
|
||||
test_grep ! "Unable to create.*MERGE_RR\.lock" err &&
|
||||
test_grep "^=======\$" $rr/preimage
|
||||
'
|
||||
|
||||
test_expect_success 'merge fails on a lock it cannot take' '
|
||||
git reset --hard &&
|
||||
rm -rf $rr &&
|
||||
test_when_finished "rm -f .git/MERGE_RR.lock" &&
|
||||
>.git/MERGE_RR.lock &&
|
||||
test_must_fail git -c rerere.lockTimeout=0 merge first 2>err &&
|
||||
test_grep "Unable to create.*MERGE_RR\.lock" err &&
|
||||
test_grep "^=======\$" a1 &&
|
||||
test_path_is_missing $rr/preimage
|
||||
'
|
||||
|
||||
test_expect_success 'rerere, forget, clear and gc fail on a lock they cannot take' '
|
||||
test_when_finished "rm -f .git/MERGE_RR.lock" &&
|
||||
>.git/MERGE_RR.lock &&
|
||||
test_must_fail git -c rerere.lockTimeout=0 rerere 2>err &&
|
||||
test_grep "Unable to create.*MERGE_RR\.lock" err &&
|
||||
test_must_fail git -c rerere.lockTimeout=0 rerere forget a1 2>err &&
|
||||
test_grep "Unable to create.*MERGE_RR\.lock" err &&
|
||||
test_must_fail git -c rerere.lockTimeout=0 rerere clear 2>err &&
|
||||
test_grep "Unable to create.*MERGE_RR\.lock" err &&
|
||||
test_must_fail git -c rerere.lockTimeout=0 rerere gc 2>err &&
|
||||
test_grep "Unable to create.*MERGE_RR\.lock" err
|
||||
'
|
||||
|
||||
test_expect_success 'rebase --abort fails on a lock it cannot take' '
|
||||
git reset --hard &&
|
||||
git checkout -b lock-held-abort third &&
|
||||
test_when_finished "git checkout third && git branch -D lock-held-abort" &&
|
||||
test_must_fail git rebase first &&
|
||||
test_when_finished "test_might_fail git rebase --abort" &&
|
||||
test_when_finished "rm -f .git/MERGE_RR.lock" &&
|
||||
>.git/MERGE_RR.lock &&
|
||||
test_must_fail git -c rerere.lockTimeout=0 rebase --abort 2>err &&
|
||||
test_grep "Unable to create.*MERGE_RR\.lock" err &&
|
||||
test_path_is_dir .git/rebase-merge &&
|
||||
rm .git/MERGE_RR.lock &&
|
||||
git rebase --abort &&
|
||||
test_path_is_missing .git/rebase-merge
|
||||
'
|
||||
|
||||
rerere_gc_custom_expiry_test () {
|
||||
five_days="$1" right_now="$2"
|
||||
test_expect_success "rerere gc with custom expiry ($five_days, $right_now)" '
|
||||
|
||||
+25
-1
@@ -1007,9 +1007,17 @@ test_expect_rerere_gc () {
|
||||
shift
|
||||
fi
|
||||
|
||||
# An automatic run passes --skip-locked to "git rerere gc".
|
||||
skip_locked=
|
||||
case " $* " in
|
||||
*" --auto "*)
|
||||
skip_locked=--skip-locked
|
||||
;;
|
||||
esac
|
||||
|
||||
rm -f "rerere-gc.txt" &&
|
||||
GIT_TRACE2_EVENT="$(pwd)/rerere-gc.txt" "$@" &&
|
||||
test_subcommand $negate git rerere gc <rerere-gc.txt
|
||||
test_subcommand $negate git rerere gc $skip_locked <rerere-gc.txt
|
||||
}
|
||||
|
||||
test_expect_success 'rerere-gc task without --auto always collects garbage' '
|
||||
@@ -1084,6 +1092,22 @@ test_expect_success 'rerere-gc task with --auto honors maintenance.rerere-gc.aut
|
||||
test_expect_rerere_gc ! git -c maintenance.rerere-gc.auto=0 maintenance run --auto --task=rerere-gc
|
||||
'
|
||||
|
||||
test_expect_success 'rerere-gc task with --auto succeeds while MERGE_RR is locked' '
|
||||
test_when_finished "rm -rf .git/rr-cache .git/MERGE_RR.lock" &&
|
||||
# Without "rr-cache", rerere is disabled and never takes the lock.
|
||||
mkdir .git/rr-cache &&
|
||||
>.git/MERGE_RR.lock &&
|
||||
test_expect_rerere_gc git -c maintenance.rerere-gc.auto=-1 maintenance run --auto --task=rerere-gc
|
||||
'
|
||||
|
||||
test_expect_success 'rerere-gc task without --auto fails while MERGE_RR is locked' '
|
||||
test_when_finished "rm -rf .git/rr-cache .git/MERGE_RR.lock" &&
|
||||
mkdir .git/rr-cache &&
|
||||
>.git/MERGE_RR.lock &&
|
||||
test_must_fail git -c rerere.lockTimeout=0 maintenance run --task=rerere-gc 2>err &&
|
||||
test_grep "Unable to create.*MERGE_RR\.lock" err
|
||||
'
|
||||
|
||||
test_expect_success '--auto and --schedule incompatible' '
|
||||
test_must_fail git maintenance run --auto --schedule=daily 2>err &&
|
||||
test_grep "cannot be used together" err
|
||||
|
||||
Reference in new issue
Block a user