)]}'
{
  "commit": "cc4affc5ee570cbd628b03ac382a4e8a56e9d012",
  "tree": "f0bf793dea3e6ad653d8338df6eca5437c8f76d6",
  "parents": [
    "f7fd8656e9a1cabac87e69861a0913a9946e32db"
  ],
  "author": {
    "name": "Christian Couder",
    "email": "christian.couder@gmail.com",
    "time": "Mon Nov 02 16:14:51 2026 +0100"
  },
  "committer": {
    "name": "Junio C Hamano",
    "email": "gitster@pobox.com",
    "time": "Mon Nov 02 11:02:27 2026 -0800"
  },
  "message": "parse-options: add early_scan_options()\n\nSome commands need to look at a few of their options before they can\nparse their command line for real, for example because the result\ndecides whether a repository is needed at all, or how the beginning of\ntheir input should be interpreted.\n\nSuch an early scan has to know which options take their value as a\nseparate argument, or it mistakes such a value for an option. Several\ncommands get this wrong, as they just walk their arguments comparing\nthem to the few option names they care about.\n\nLet\u0027s add early_scan_options() to help with this. It walks the\narguments using the very same `struct option` array that the command\nalready passes to parse_options(). It looks up long options with the\nlookup_long_opt() helper extracted from parse_long_opt() in a previous\ncommit, so that negated forms, unambiguous abbreviations and aliases\nare recognized the same way, and it uses the\nparse_options_takes_argument() helper added in another previous\ncommit, so that the scan and the actual parsing agree on which options\ntake a value.\n\nThe options the caller wants to be told about are marked with a new\nPARSE_OPT_EARLY flag, so that nothing has to be spelled out a second\ntime, and so that the mark cannot drift away from the option it refers\nto.\n\nUsing a per-option flag for this is not new as that flag space already\nholds flags that the parsing loop itself ignores, like\nPARSE_OPT_NOCOMPLETE and PARSE_OPT_COMP_ARG, which only the completion\nhelper looks at, or PARSE_OPT_HIDDEN and PARSE_OPT_LITERAL_ARGHELP,\nwhich only the usage output looks at.\n\nThe scan is deliberately kept much simpler than parse_options(),\ninstead of teaching the latter to perform a side effect free \"dry\nrun\". Such a dry run would have to avoid writing through `opt-\u003evalue`,\ncalling option callbacks, dying on an invalid value, handling `--help`\nand tracking command mode conflicts, so it would be a much larger\nrefactoring. If parse_options() learns to do it in the future though,\nthe commands converted now would keep both their option array and their\nPARSE_OPT_EARLY marks, so their conversion would not have to be redone.\n\nOne consequence of staying simple is that the scan doesn\u0027t try to\nhandle what it cannot reliably skip, like short options, unknown\noptions, ambiguous abbreviations or options with a low-level callback,\nwhich may consume any number of arguments. It stops at them instead,\nso that it never takes an option\u0027s value for an option. This matters,\nas for example with:\n\n  git fast-import --quiet --export-pack --allow-unsafe-features\n\nparse_options() takes `--allow-unsafe-features` as the value of\n`--export-pack-edges`, which `--export-pack` abbreviates. A scan that\njust skipped `--export-pack` as an unknown option would wrongly see\n`--allow-unsafe-features` there.\n\nSo the scan can fail to see an option that parse_options() would\naccept, but it doesn\u0027t report an option that parse_options() would\nnot, and its callers can safely err on the side of not having seen an\noption. The differences with parse_options() are documented in\n\"parse-options.h\".\n\nIn practice, despite these limitations, early scans using\nearly_scan_options() should still be safer and cleaner than the\nad-hoc hand-rolled scans they are meant to replace, which don\u0027t know\nabout option values at all and therefore disagree with\nparse_options() in ways that create plain bugs.\n\nHelped-by: Kaartic Sivaraam \u003ckaartic.sivaraam@gmail.com\u003e\nSigned-off-by: Christian Couder \u003cchristian.couder@gmail.com\u003e\nSigned-off-by: Junio C Hamano \u003cgitster@pobox.com\u003e\n",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "95b7924e84e2c877388dd093c8fb545c3d6ebdbe",
      "old_mode": 33188,
      "old_path": "Documentation/technical/api-parse-options.adoc",
      "new_id": "f59d8e90a5a46036702bba53af213495e97e87f7",
      "new_mode": 33188,
      "new_path": "Documentation/technical/api-parse-options.adoc"
    },
    {
      "type": "modify",
      "old_id": "d94d6fed93117f8c5e251beb1fd202b2dcf07c80",
      "old_mode": 33188,
      "old_path": "parse-options.c",
      "new_id": "7e8b4061295ec0c5bcbea4163fa9de9a866d4e10",
      "new_mode": 33188,
      "new_path": "parse-options.c"
    },
    {
      "type": "modify",
      "old_id": "589f8d900837daaab343fe6322af684cfa1199c9",
      "old_mode": 33188,
      "old_path": "parse-options.h",
      "new_id": "14e85689898957bb23b8421c5c815f9728016573",
      "new_mode": 33188,
      "new_path": "parse-options.h"
    },
    {
      "type": "modify",
      "old_id": "f181f0c02d355a9dd55abd482b4ed1caecfecebe",
      "old_mode": 33188,
      "old_path": "t/helper/test-parse-options.c",
      "new_id": "de3dd5751ca4ffc31e7d8573df1a6a6b127d95aa",
      "new_mode": 33188,
      "new_path": "t/helper/test-parse-options.c"
    },
    {
      "type": "modify",
      "old_id": "b71a22b43bbc9ec41424dbe1e79757b8e6c959ad",
      "old_mode": 33188,
      "old_path": "t/helper/test-tool.c",
      "new_id": "5d2f5877d925ee5d99ec954b25cb2c37b97940ea",
      "new_mode": 33188,
      "new_path": "t/helper/test-tool.c"
    },
    {
      "type": "modify",
      "old_id": "f2885b33d58aa8956500f3c4cd735ab43e6d2048",
      "old_mode": 33188,
      "old_path": "t/helper/test-tool.h",
      "new_id": "071306d52dabc33b55061021af63ba0b64be564c",
      "new_mode": 33188,
      "new_path": "t/helper/test-tool.h"
    },
    {
      "type": "modify",
      "old_id": "449fff4d34b1723c111211a8d18d994198f9a59e",
      "old_mode": 33261,
      "old_path": "t/t0040-parse-options.sh",
      "new_id": "c44b12e46d90c7bf1bec32caa67f9741d2d8c510",
      "new_mode": 33261,
      "new_path": "t/t0040-parse-options.sh"
    }
  ]
}
