From: Junio C Hamano Date: Mon, 25 Jan 2021 22:19:17 +0000 (-0800) Subject: Merge branch 'ma/more-opaque-lock-file' X-Git-Tag: v2.31.0-rc0~109 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=58e2ce9112446935a1294d095a07390ed665a6bc;p=thirdparty%2Fgit.git Merge branch 'ma/more-opaque-lock-file' Code clean-up. * ma/more-opaque-lock-file: read-cache: try not to peek into `struct {lock_,temp}file` refs/files-backend: don't peek into `struct lock_file` midx: don't peek into `struct lock_file` commit-graph: don't peek into `struct lock_file` builtin/gc: don't peek into `struct lock_file` --- 58e2ce9112446935a1294d095a07390ed665a6bc diff --cc builtin/gc.c index b315b2ad58,64f2b52d6e..fe35b10fe9 --- a/builtin/gc.c +++ b/builtin/gc.c @@@ -1915,54 -1587,14 +1915,54 @@@ static int crontab_update_schedule(int close(crontab_edit.in); done_editing: - if (finish_command(&crontab_edit)) { + if (finish_command(&crontab_edit)) result = error(_("'crontab' died")); - goto cleanup; + else + fclose(cron_list); + return result; +} + +#if defined(__APPLE__) +static const char platform_scheduler[] = "launchctl"; +#elif defined(GIT_WINDOWS_NATIVE) +static const char platform_scheduler[] = "schtasks"; +#else +static const char platform_scheduler[] = "crontab"; +#endif + +static int update_background_schedule(int enable) +{ + int result; + const char *scheduler = platform_scheduler; + const char *cmd = scheduler; + char *testing; + struct lock_file lk; + char *lock_path = xstrfmt("%s/schedule", the_repository->objects->odb->path); + + testing = xstrdup_or_null(getenv("GIT_TEST_MAINT_SCHEDULER")); + if (testing) { + char *sep = strchr(testing, ':'); + if (!sep) + die("GIT_TEST_MAINT_SCHEDULER unparseable: %s", testing); + *sep = '\0'; + scheduler = testing; + cmd = sep + 1; } - fclose(cron_list); -cleanup: + if (hold_lock_file_for_update(&lk, lock_path, LOCK_NO_DEREF) < 0) + return error(_("another process is scheduling background maintenance")); + + if (!strcmp(scheduler, "launchctl")) - result = launchctl_update_schedule(enable, lk.tempfile->fd, cmd); ++ result = launchctl_update_schedule(enable, get_lock_file_fd(&lk), cmd); + else if (!strcmp(scheduler, "schtasks")) - result = schtasks_update_schedule(enable, lk.tempfile->fd, cmd); ++ result = schtasks_update_schedule(enable, get_lock_file_fd(&lk), cmd); + else if (!strcmp(scheduler, "crontab")) - result = crontab_update_schedule(enable, lk.tempfile->fd, cmd); ++ result = crontab_update_schedule(enable, get_lock_file_fd(&lk), cmd); + else + die("unknown background scheduler: %s", scheduler); + rollback_lock_file(&lk); + free(testing); return result; }