]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'ma/more-opaque-lock-file'
authorJunio C Hamano <gitster@pobox.com>
Mon, 25 Jan 2021 22:19:17 +0000 (14:19 -0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 25 Jan 2021 22:19:17 +0000 (14:19 -0800)
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`

1  2 
builtin/gc.c
commit-graph.c
midx.c

diff --cc builtin/gc.c
index b315b2ad5881abba70aed1c95b98c2c8dea7657f,64f2b52d6e2cf24d205fb956c77e9839a4ba6fe0..fe35b10fe9413402bae8cbe81409d6530cbc7d73
@@@ -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;
  }
  
diff --cc commit-graph.c
Simple merge
diff --cc midx.c
Simple merge