Skip to main content

git_policy_cli/
command_commit_table.rs

1//! What:
2//!  The complete option table of `git commit` in Git 2.56.0.
3//! Why:
4//!  Declaring every option Git accepts removes the guess about whether an undeclared
5//!      option consumes the next token.
6//!  Rows follow `builtin_commit_options`
7//!      (builtin/commit.c:1705-1785) in source order,
8//!  which the completion control compares.
9//!
10//! In TS you'd write (pseudocode):
11//! ```ts
12//! // export const COMMIT_TABLE: readonly OptionSpec[] = [ ... ];
13//! ```
14
15/// What:
16///  Bring the row type,
17///  its builder and the arity names into this file.
18///  `UNREAD` is the
19///       identifier of rows no commit fact reads.
20/// Why:
21///   The table is data for the shared tokenizer.
22///
23/// In TS you'd write (pseudocode):
24/// ```ts
25/// import { Arity, type OptionSpec, row, UNREAD } from './command_options.ts';
26/// ```
27use super::command_options::{Arity, OptionSpec, UNREAD, row};
28
29/// `-a`,
30///  `--all`:
31///  stage every tracked modification before committing.
32pub const ALL: u16 = 1;
33/// `-o`,
34///  `--only`:
35///  commit only the named paths.
36pub const ONLY: u16 = 2;
37/// `-i`,
38///  `--include`:
39///  add the named paths to the index for this commit.
40pub const INCLUDE: u16 = 3;
41/// `--interactive`:
42///  choose content interactively.
43pub const INTERACTIVE: u16 = 4;
44/// `-p`,
45///  `--patch`:
46///  choose hunks interactively.
47pub const PATCH: u16 = 5;
48/// `--dry-run`:
49///  show what would be committed.
50pub const DRY_RUN: u16 = 6;
51/// `--short`:
52///  status format that implies a dry run.
53pub const SHORT: u16 = 7;
54/// `--porcelain`:
55///  status format that implies a dry run.
56pub const PORCELAIN: u16 = 8;
57/// `--long`:
58///  status format that implies a dry run.
59pub const LONG: u16 = 9;
60/// `-z`,
61///  `--null`:
62///  NUL-terminated status output,
63///  which implies a dry run.
64pub const NULL: u16 = 10;
65/// `--amend`:
66///  replace the tip commit.
67pub const AMEND: u16 = 11;
68/// `--allow-empty`:
69///  permit a commit that records no change.
70pub const ALLOW_EMPTY: u16 = 12;
71/// `--fixup=[(amend|reword):]<commit>`.
72pub const FIXUP: u16 = 13;
73/// `--pathspec-from-file=<file>`.
74pub const PATHSPEC_FROM_FILE: u16 = 14;
75/// `--pathspec-file-nul`.
76pub const PATHSPEC_FILE_NUL: u16 = 15;
77
78/// What:
79///  `pub const NAME: &[OptionSpec] = &[...]` is a table baked into the program.
80///       `&[T]` is a borrowed list;
81///  `Some(b'q')` is "the byte `q`";
82///  `None` is "no letter".
83/// Why:
84///   Each row copies one Git declaration:
85///  letter,
86///  name,
87///  value arity and whether
88///       `--no-<name>` is accepted (false only for `PARSE_OPT_NONEG`).
89///
90/// In TS you'd write (pseudocode):
91/// ```ts
92/// export const COMMIT_TABLE = [row(UNREAD, 'q', 'quiet', 'none', true), /* ... */] as const;
93/// ```
94pub const COMMIT_TABLE: &[OptionSpec] = &[
95    row(UNREAD, Some(b'q'), Some("quiet"), Arity::None, true),
96    row(UNREAD, Some(b'v'), Some("verbose"), Arity::None, true),
97    row(UNREAD, Some(b'F'), Some("file"), Arity::Required, true),
98    row(UNREAD, None, Some("author"), Arity::Required, true),
99    row(UNREAD, None, Some("date"), Arity::Required, true),
100    row(UNREAD, Some(b'm'), Some("message"), Arity::Required, true),
101    row(
102        UNREAD,
103        Some(b'c'),
104        Some("reedit-message"),
105        Arity::Required,
106        true,
107    ),
108    row(
109        UNREAD,
110        Some(b'C'),
111        Some("reuse-message"),
112        Arity::Required,
113        true,
114    ),
115    row(FIXUP, None, Some("fixup"), Arity::Required, true),
116    row(UNREAD, None, Some("squash"), Arity::Required, true),
117    row(UNREAD, None, Some("reset-author"), Arity::None, true),
118    row(UNREAD, None, Some("trailer"), Arity::Required, true),
119    row(UNREAD, Some(b's'), Some("signoff"), Arity::None, true),
120    row(UNREAD, Some(b't'), Some("template"), Arity::Required, true),
121    row(UNREAD, Some(b'e'), Some("edit"), Arity::None, true),
122    row(UNREAD, None, Some("cleanup"), Arity::Required, true),
123    row(UNREAD, None, Some("status"), Arity::None, true),
124    // `PARSE_OPT_OPTARG`: `-S<key>` and `--gpg-sign=<key>` only (commit.c:1730-1739).
125    row(UNREAD, Some(b'S'), Some("gpg-sign"), Arity::Optional, true),
126    row(ALL, Some(b'a'), Some("all"), Arity::None, true),
127    row(INCLUDE, Some(b'i'), Some("include"), Arity::None, true),
128    row(INTERACTIVE, None, Some("interactive"), Arity::None, true),
129    row(PATCH, Some(b'p'), Some("patch"), Arity::None, true),
130    // `OPT_DIFF_UNIFIED` and `OPT_DIFF_INTERHUNK_CONTEXT` are `PARSE_OPT_NONEG`
131    // (parse-options.h:633-634).
132    row(UNREAD, Some(b'U'), Some("unified"), Arity::Required, false),
133    row(
134        UNREAD,
135        None,
136        Some("inter-hunk-context"),
137        Arity::Required,
138        false,
139    ),
140    row(ONLY, Some(b'o'), Some("only"), Arity::None, true),
141    row(UNREAD, Some(b'n'), Some("no-verify"), Arity::None, true),
142    row(DRY_RUN, None, Some("dry-run"), Arity::None, true),
143    row(SHORT, None, Some("short"), Arity::None, true),
144    row(UNREAD, None, Some("branch"), Arity::None, true),
145    row(UNREAD, None, Some("ahead-behind"), Arity::None, true),
146    // Unlike `git status`, `git commit --porcelain` takes no value (commit.c:1757-1758).
147    row(PORCELAIN, None, Some("porcelain"), Arity::None, true),
148    row(LONG, None, Some("long"), Arity::None, true),
149    row(NULL, Some(b'z'), Some("null"), Arity::None, true),
150    row(AMEND, None, Some("amend"), Arity::None, true),
151    row(UNREAD, None, Some("no-post-rewrite"), Arity::None, true),
152    // `PARSE_OPT_OPTARG`: `-u<mode>` and `--untracked-files=<mode>` only (commit.c:1766-1775).
153    row(
154        UNREAD,
155        Some(b'u'),
156        Some("untracked-files"),
157        Arity::Optional,
158        true,
159    ),
160    row(
161        PATHSPEC_FROM_FILE,
162        None,
163        Some("pathspec-from-file"),
164        Arity::Required,
165        true,
166    ),
167    row(
168        PATHSPEC_FILE_NUL,
169        None,
170        Some("pathspec-file-nul"),
171        Arity::None,
172        true,
173    ),
174    row(ALLOW_EMPTY, None, Some("allow-empty"), Arity::None, true),
175    row(UNREAD, None, Some("allow-empty-message"), Arity::None, true),
176];