git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v5 4/4] maintenance: use Windows scheduled tasks

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Nov 27, 2020, 09:08 UTC
Message-ID
<CAPig+cQ6vZzbb36t5Kn=NM9wXC8i1MpcGXfK=QwnNRoTQsQP0A@mail.gmail.com>
In-Reply-To
<ac9a28bea39b4d1897ad6a41331e52770c8c7531.1606191405.git.gitgitgadget@gmail.com>

On Mon, Nov 23, 2020 at 11:16 PM Derrick Stolee via GitGitGadget <gitgitgadget@gmail.com> wrote:

Show 14 quoted lines
> Git's background maintenance uses cron by default, but this is not
> available on Windows. Instead, integrate with Task Scheduler.
> [...]
> Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
> ---
> diff --git a/builtin/gc.c b/builtin/gc.c
> @@ -1671,6 +1671,162 @@ static int launchctl_update_schedule(int run_maintenance, int fd, const char *cm
> +static int schtasks_schedule_task(const char *exec_path, enum schedule_priority schedule, const char *cmd)
> +{
> +       const char *frequency = get_frequency(schedule);
> +
> +       tfile = xmks_tempfile("schedule_XXXXXX");
> +       if (!tfile || !fdopen_tempfile(tfile, "w"))
> +               die(_("failed to create temp xml file"));
Several comments:

The "x" prefix on xmks_tempfile() means that it will die() if it can't open the tempfile, so the `!tfile` condition is pointless, thus it could be written:

    if (!fdopen_tempfile(tfile, "w"))

The mks_tempfile_t*() functions with a trailing "t" will place the temporary file in TMPDIR, whereas xmks_tempfile() used here places it in the worktree directory, which is not as desirable. Ideally, this would be using xmks_tempfile_t(), however, that function doesn't exist yet in tempfile.h, so the best you can do (without the extra work of also adding the missing function) is to use mks_tempfile_t(). That doesn't die(), so `!tfile` would still be needed in the conditional.

In earlier versions, you incorporated `frequency` into the temporary filename which was nice because it made the test easier to understand. It's not hard to do so here, as well, nor to extract a useful filename in the test (as I'll show below). For instance:

    struct strbuf tpath = STRBUF_INIT;
    strbuf_addf(&tpath, "schedule-%s-XXXXXX", frequency);
    tfile = mks_tempfile_t(tpath.buf);
    strbuf_release(&tpath);
    if (!tfile || !fdopen(tempfile(tfile, "w"))
        die(...);
> +       strvec_pushl(&child.args, "/create", "/tn", name, "/f", "/xml", tfile->filename.buf, NULL);
Alternately, use the getter:
    strvec_pushl(..., get_tempfile_path(&tfile), ...);
Show 13 quoted lines
> diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh
> @@ -453,6 +453,50 @@ test_expect_success !MINGW 'start and stop macOS maintenance' '
> +test_expect_success 'start and stop Windows maintenance' '
> +       write_script print-args <<-\EOF &&
> +       echo $* >>args
> +       while test $# -gt 0
> +       do
> +               case "$1" in
> +               /xml) shift; xmlfile=$1; break ;;
> +               *) shift ;;
> +               esac
> +       done
> +       lines=$(wc -l args | awk "{print \$1;}")

You're using `awk` to pluck out the line count and ignore the filename, but the same can be accomplished by feeding the file as stdin to `wc` rather than naming it as an argument, thus this is equivalent:

    lines=$(wc -l <args)

However, this idea of constructing stable names for the files by assigning them numerically incrementing values is unnecessary and makes the test harder to understand.

> +       test -z "$xmlfile" || cp "$xmlfile" "schedule-$lines.xml"

If you take the suggestion earlier in this review of naming the file "schedule-${frequency}-XXXXXX.xml", then you can strip it down to just "schedule-${frequency}.xml" using the expression `${xmlfile%-*}.xml`. There is no need for `$lines`. Thus, copying the file would become:

    test -z "$xmlfile" || cp "$xmlfile" "${xmlfile%-*}.xml"
> +       for i in 1 2 3
> +       do

Which means that you can use the more easily understood `hourly daily weekly` enumeration here rather than `1 2 3`.

Having said all this, I'm not sure it's worth a re-roll. These sort of tweaks can be done atop the current series if someone wants to tackle it.

Previous: Derrick Stolee via GitGitGadgetNext: Derrick Stolee via GitGitGadget
Message 67 of 83 in “Maintenance IV: Platform-specific background maintenance”
  1. 0/3 Maintenance IV: Platform-specific background maintenanceDerrick Stolee via GitGitGadget, Nov 3, 2020
  2. 1/3 maintenance: extract platform-specific schedulingDerrick Stolee via GitGitGadget, Nov 3, 2020
  3. 3/3 maintenance: use Windows scheduled tasksDerrick Stolee via GitGitGadget, Nov 3, 2020
  4. Eric SunshineNov 3, 2020
  5. Derrick StoleeNov 3, 2020
  6. 2/3 maintenance: use launchctl on macOSDerrick Stolee via GitGitGadget, Nov 3, 2020
  7. Eric SunshineNov 3, 2020
  8. Derrick StoleeNov 3, 2020
  9. Eric SunshineNov 3, 2020
  10. Derrick StoleeNov 4, 2020
  11. Derrick StoleeNov 4, 2020
  12. Junio C HamanoNov 3, 2020
  13. Junio C HamanoNov 3, 2020
  14. Derrick StoleeNov 3, 2020
  15. Junio C HamanoNov 3, 2020
  16. Derrick StoleeNov 4, 2020
  17. Junio C HamanoNov 4, 2020
  18. Derrick StoleeNov 4, 2020
  19. 0/4 Maintenance IV: Platform-specific background maintenanceDerrick Stolee via GitGitGadget, Nov 4, 2020
  20. 3/4 maintenance: use launchctl on macOSDerrick Stolee via GitGitGadget, Nov 4, 2020
  21. Eric SunshineNov 11, 2020
  22. Derrick StoleeNov 12, 2020
  23. Eric SunshineNov 12, 2020
  24. 2/4 maintenance: include 'cron' details in docsDerrick Stolee via GitGitGadget, Nov 4, 2020
  25. Eric SunshineNov 11, 2020
  26. 4/4 maintenance: use Windows scheduled tasksDerrick Stolee via GitGitGadget, Nov 4, 2020
  27. Eric SunshineNov 11, 2020
  28. Derrick StoleeNov 12, 2020
  29. 1/4 maintenance: extract platform-specific schedulingDerrick Stolee via GitGitGadget, Nov 4, 2020
  30. 0/4 Maintenance IV: Platform-specific background maintenanceDerrick Stolee via GitGitGadget, Nov 13, 2020
  31. 1/4 maintenance: extract platform-specific schedulingDerrick Stolee via GitGitGadget, Nov 13, 2020
  32. 2/4 maintenance: include 'cron' details in docsDerrick Stolee via GitGitGadget, Nov 13, 2020
  33. 3/4 maintenance: use launchctl on macOSDerrick Stolee via GitGitGadget, Nov 13, 2020
  34. Eric SunshineNov 13, 2020
  35. Derrick StoleeNov 13, 2020
  36. Eric SunshineNov 13, 2020
  37. Eric SunshineNov 13, 2020
  38. 4/4 maintenance: use Windows scheduled tasksDerrick Stolee via GitGitGadget, Nov 13, 2020
  39. Eric SunshineNov 13, 2020
  40. Derrick StoleeNov 13, 2020
  41. Eric SunshineNov 13, 2020
  42. Derrick StoleeNov 16, 2020
  43. Eric SunshineNov 13, 2020
  44. Eric SunshineNov 14, 2020
  45. Derrick StoleeNov 16, 2020
  46. 0/4 Maintenance IV: Platform-specific background maintenanceDerrick Stolee via GitGitGadget, Nov 17, 2020
  47. 1/4 maintenance: extract platform-specific schedulingDerrick Stolee via GitGitGadget, Nov 17, 2020
  48. 2/4 maintenance: include 'cron' details in docsDerrick Stolee via GitGitGadget, Nov 17, 2020
  49. Eric SunshineNov 18, 2020
  50. Derrick StoleeNov 18, 2020
  51. 3/4 maintenance: use launchctl on macOSDerrick Stolee via GitGitGadget, Nov 17, 2020
  52. Eric SunshineNov 18, 2020
  53. Derrick StoleeNov 18, 2020
  54. 4/4 maintenance: use Windows scheduled tasksDerrick Stolee via GitGitGadget, Nov 17, 2020
  55. Eric SunshineNov 18, 2020
  56. Derrick StoleeNov 18, 2020
  57. Eric SunshineNov 18, 2020
  58. Derrick StoleeNov 18, 2020
  59. Eric SunshineNov 17, 2020
  60. Derrick StoleeNov 24, 2020
  61. Eric SunshineNov 24, 2020
  62. Eric SunshineNov 17, 2020
  63. 0/4 Maintenance IV: Platform-specific background maintenanceDerrick Stolee via GitGitGadget, Nov 24, 2020
  64. 1/4 maintenance: extract platform-specific schedulingDerrick Stolee via GitGitGadget, Nov 24, 2020
  65. 2/4 maintenance: include 'cron' details in docsDerrick Stolee via GitGitGadget, Nov 24, 2020
  66. 4/4 maintenance: use Windows scheduled tasksDerrick Stolee via GitGitGadget, Nov 24, 2020
  67. Eric SunshineNov 27, 2020
  68. 3/4 maintenance: use launchctl on macOSDerrick Stolee via GitGitGadget, Nov 24, 2020
  69. 0/4 Maintenance IV: Platform-specific background maintenanceDerrick Stolee via GitGitGadget, Dec 9, 2020
  70. 2/4 maintenance: include 'cron' details in docsDerrick Stolee via GitGitGadget, Dec 9, 2020
  71. 1/4 maintenance: extract platform-specific schedulingDerrick Stolee via GitGitGadget, Dec 9, 2020
  72. 4/4 maintenance: use Windows scheduled tasksDerrick Stolee via GitGitGadget, Dec 9, 2020
  73. 3/4 maintenance: use launchctl on macOSDerrick Stolee via GitGitGadget, Dec 9, 2020
  74. Junio C HamanoDec 10, 2020
  75. Eric SunshineDec 10, 2020
  76. Junio C HamanoDec 10, 2020
  77. Derrick StoleeJan 5, 2021
  78. 0/4 Maintenance IV: Platform-specific background maintenanceDerrick Stolee via GitGitGadget, Jan 5, 2021
  79. 2/4 maintenance: include 'cron' details in docsDerrick Stolee via GitGitGadget, Jan 5, 2021
  80. 1/4 maintenance: extract platform-specific schedulingDerrick Stolee via GitGitGadget, Jan 5, 2021
  81. 4/4 maintenance: use Windows scheduled tasksDerrick Stolee via GitGitGadget, Jan 5, 2021
  82. 3/4 maintenance: use launchctl on macOSDerrick Stolee via GitGitGadget, Jan 5, 2021
  83. Eric SunshineJan 10, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.