Skip to content

Commit 0656ce1

Browse files
committed
Adds script to parse and generate metadata for all possible git log fields
1 parent d7b96d1 commit 0656ce1

File tree

3 files changed

+384
-1
lines changed

3 files changed

+384
-1
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
"prepublish": "npm run build"
3232
},
3333
"dependencies": {
34-
"chalk": "^1.1.3"
34+
"chalk": "^1.1.3",
35+
"lodash": "^4.17.2"
3536
},
3637
"devDependencies": {
3738
"babel-cli": "^6.18.0",

scripts/git-log-fields.generate.js

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
// Code generator: generates JS list of all git log fields
2+
3+
const {groupBy, each} = require('lodash');
4+
const {inspect} = require('util');
5+
const fs = require('fs');
6+
const path = require('path');
7+
8+
// Copy-pasted from https://git-scm.com/docs/pretty-formats, with all formatting-related codes removed.
9+
const gitLogFieldDocs = `
10+
'%H': commit hash
11+
12+
'%h': abbreviated commit hash
13+
14+
'%T': tree hash
15+
16+
'%t': abbreviated tree hash
17+
18+
'%P': parent hashes
19+
20+
'%p': abbreviated parent hashes
21+
22+
'%an': author name
23+
24+
'%aN': author name (respecting .mailmap, see git-shortlog[1] or git-blame[1])
25+
26+
'%ae': author email
27+
28+
'%aE': author email (respecting .mailmap, see git-shortlog[1] or git-blame[1])
29+
30+
'%ad': author date (format respects --date= option)
31+
32+
'%aD': author date, RFC2822 style
33+
34+
'%ar': author date, relative
35+
36+
'%at': author date, UNIX timestamp
37+
38+
'%ai': author date, ISO 8601-like format
39+
40+
'%aI': author date, strict ISO 8601 format
41+
42+
'%cn': committer name
43+
44+
'%cN': committer name (respecting .mailmap, see git-shortlog[1] or git-blame[1])
45+
46+
'%ce': committer email
47+
48+
'%cE': committer email (respecting .mailmap, see git-shortlog[1] or git-blame[1])
49+
50+
'%cd': committer date (format respects --date= option)
51+
52+
'%cD': committer date, RFC2822 style
53+
54+
'%cr': committer date, relative
55+
56+
'%ct': committer date, UNIX timestamp
57+
58+
'%ci': committer date, ISO 8601-like format
59+
60+
'%cI': committer date, strict ISO 8601 format
61+
62+
'%d': ref names, like the --decorate option of git-log[1]
63+
64+
'%D': ref names without the " (", ")" wrapping.
65+
66+
'%e': encoding
67+
68+
'%s': subject
69+
70+
'%f': sanitized subject line, suitable for a filename
71+
72+
'%b': body
73+
74+
'%B': raw body (unwrapped subject and body)
75+
76+
'%N': commit notes
77+
78+
'%GG': raw verification message from GPG for a signed commit
79+
80+
'%G?': show "G" for a good (valid) signature, "B" for a bad signature, "U" for a good signature with unknown validity, "X" for a good signature that has expired, "Y" for a good signature made by an expired key, "R" for a good signature made by a revoked key, "E" if the signature cannot be checked (e.g. missing key) and "N" for no signature
81+
82+
'%GS': show the name of the signer for a signed commit
83+
84+
'%GK': show the key used to sign a signed commit
85+
86+
'%gD': reflog selector, e.g., refs/stash@{1} or refs/stash@{2 minutes ago}; the format follows the rules described for the -g option. The portion before the @ is the refname as given on the command line (so git log -g refs/heads/master would yield refs/heads/master@{0}).
87+
88+
'%gd': shortened reflog selector; same as %gD, but the refname portion is shortened for human readability (so refs/heads/master becomes just master).
89+
90+
'%gn': reflog identity name
91+
92+
'%gN': reflog identity name (respecting .mailmap, see git-shortlog[1] or git-blame[1])
93+
94+
'%ge': reflog identity email
95+
96+
'%gE': reflog identity email (respecting .mailmap, see git-shortlog[1] or git-blame[1])
97+
98+
'%gs': reflog subject
99+
100+
// '%Cred': switch color to red
101+
//
102+
// '%Cgreen': switch color to green
103+
//
104+
// '%Cblue': switch color to blue
105+
//
106+
// '%Creset': reset color
107+
//
108+
// '%C(…​)': color specification, as described under Values in the "CONFIGURATION FILE" section of git-config[1]; adding auto, at the beginning will emit color only when colors are enabled for log output (by color.diff, color.ui, or --color, and respecting the auto settings of the former if we are going to a terminal). auto alone (i.e. %C(auto)) will turn on auto coloring on the next placeholders until the color is switched again.
109+
//
110+
// '%m': left (<), right (>) or boundary (-) mark
111+
//
112+
// '%n': newline
113+
//
114+
// '%%': a raw '%'
115+
//
116+
// '%x00': print a byte from a hex code
117+
//
118+
// '%w([<w>[,<i1>[,<i2>]]])': switch line wrapping, like the -w option of git-shortlog[1].
119+
//
120+
// '%<(<N>[,trunc|ltrunc|mtrunc])': make the next placeholder take at least N columns, padding spaces on the right if necessary. Optionally truncate at the beginning (ltrunc), the middle (mtrunc) or the end (trunc) if the output is longer than N columns. Note that truncating only works correctly with N >= 2.
121+
//
122+
// '%<|(<N>)': make the next placeholder take at least until Nth columns, padding spaces on the right if necessary
123+
//
124+
// '%>(<N>)', '%>|(<N>)': similar to '%<(<N>)', '%<|(<N>)' respectively, but padding spaces on the left
125+
//
126+
// '%>>(<N>)', '%>>|(<N>)': similar to '%>(<N>)', '%>|(<N>)' respectively, except that if the next placeholder takes more spaces than given and there are spaces on its left, use those spaces
127+
//
128+
// '%><(<N>)', '%><|(<N>)': similar to '% <(<N>)', '%<|(<N>)' respectively, but padding both sides (i.e. the text is centered)
129+
`;
130+
131+
const fields = gitLogFieldDocs.split(/\r\n|\n/).filter(line => (
132+
line && line.indexOf('//') != 0
133+
)).map(line => {
134+
const [, code, fullDescription, name, description] = line.match(/'(.*?)': ((.*?)((?:,|;| \(|$).*))/);
135+
return {
136+
code,
137+
name,
138+
fullDescription,
139+
description,
140+
identifier: name.replace(/ /g, '_')
141+
};
142+
});
143+
144+
// For fields that end up with identical identifiers, give them longer, unique identifiers
145+
each(groupBy(fields, 'identifier'), group => {
146+
if(group.length < 2) return;
147+
group.forEach(field => {
148+
field.identifier = field.fullDescription.replace(/[,;]? /g, '_');
149+
});
150+
});
151+
152+
const output = `
153+
exports.fields = ${ inspect(fields) };
154+
`;
155+
156+
fs.writeFileSync(path.join(__dirname, 'git-log-fields.js'), output);

scripts/git-log-fields.js

Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
2+
exports.fields = [ { code: '%H',
3+
name: 'commit hash',
4+
fullDescription: 'commit hash',
5+
description: '',
6+
identifier: 'commit_hash' },
7+
{ code: '%h',
8+
name: 'abbreviated commit hash',
9+
fullDescription: 'abbreviated commit hash',
10+
description: '',
11+
identifier: 'abbreviated_commit_hash' },
12+
{ code: '%T',
13+
name: 'tree hash',
14+
fullDescription: 'tree hash',
15+
description: '',
16+
identifier: 'tree_hash' },
17+
{ code: '%t',
18+
name: 'abbreviated tree hash',
19+
fullDescription: 'abbreviated tree hash',
20+
description: '',
21+
identifier: 'abbreviated_tree_hash' },
22+
{ code: '%P',
23+
name: 'parent hashes',
24+
fullDescription: 'parent hashes',
25+
description: '',
26+
identifier: 'parent_hashes' },
27+
{ code: '%p',
28+
name: 'abbreviated parent hashes',
29+
fullDescription: 'abbreviated parent hashes',
30+
description: '',
31+
identifier: 'abbreviated_parent_hashes' },
32+
{ code: '%an',
33+
name: 'author name',
34+
fullDescription: 'author name',
35+
description: '',
36+
identifier: 'author_name' },
37+
{ code: '%aN',
38+
name: 'author name',
39+
fullDescription: 'author name (respecting .mailmap, see git-shortlog[1] or git-blame[1])',
40+
description: ' (respecting .mailmap, see git-shortlog[1] or git-blame[1])',
41+
identifier: 'author_name_(respecting_.mailmap_see_git-shortlog[1]_or_git-blame[1])' },
42+
{ code: '%ae',
43+
name: 'author email',
44+
fullDescription: 'author email',
45+
description: '',
46+
identifier: 'author_email' },
47+
{ code: '%aE',
48+
name: 'author email',
49+
fullDescription: 'author email (respecting .mailmap, see git-shortlog[1] or git-blame[1])',
50+
description: ' (respecting .mailmap, see git-shortlog[1] or git-blame[1])',
51+
identifier: 'author_email_(respecting_.mailmap_see_git-shortlog[1]_or_git-blame[1])' },
52+
{ code: '%ad',
53+
name: 'author date',
54+
fullDescription: 'author date (format respects --date= option)',
55+
description: ' (format respects --date= option)',
56+
identifier: 'author_date_(format_respects_--date=_option)' },
57+
{ code: '%aD',
58+
name: 'author date',
59+
fullDescription: 'author date, RFC2822 style',
60+
description: ', RFC2822 style',
61+
identifier: 'author_date_RFC2822_style' },
62+
{ code: '%ar',
63+
name: 'author date',
64+
fullDescription: 'author date, relative',
65+
description: ', relative',
66+
identifier: 'author_date_relative' },
67+
{ code: '%at',
68+
name: 'author date',
69+
fullDescription: 'author date, UNIX timestamp',
70+
description: ', UNIX timestamp',
71+
identifier: 'author_date_UNIX_timestamp' },
72+
{ code: '%ai',
73+
name: 'author date',
74+
fullDescription: 'author date, ISO 8601-like format',
75+
description: ', ISO 8601-like format',
76+
identifier: 'author_date_ISO_8601-like_format' },
77+
{ code: '%aI',
78+
name: 'author date',
79+
fullDescription: 'author date, strict ISO 8601 format',
80+
description: ', strict ISO 8601 format',
81+
identifier: 'author_date_strict_ISO_8601_format' },
82+
{ code: '%cn',
83+
name: 'committer name',
84+
fullDescription: 'committer name',
85+
description: '',
86+
identifier: 'committer_name' },
87+
{ code: '%cN',
88+
name: 'committer name',
89+
fullDescription: 'committer name (respecting .mailmap, see git-shortlog[1] or git-blame[1])',
90+
description: ' (respecting .mailmap, see git-shortlog[1] or git-blame[1])',
91+
identifier: 'committer_name_(respecting_.mailmap_see_git-shortlog[1]_or_git-blame[1])' },
92+
{ code: '%ce',
93+
name: 'committer email',
94+
fullDescription: 'committer email',
95+
description: '',
96+
identifier: 'committer_email' },
97+
{ code: '%cE',
98+
name: 'committer email',
99+
fullDescription: 'committer email (respecting .mailmap, see git-shortlog[1] or git-blame[1])',
100+
description: ' (respecting .mailmap, see git-shortlog[1] or git-blame[1])',
101+
identifier: 'committer_email_(respecting_.mailmap_see_git-shortlog[1]_or_git-blame[1])' },
102+
{ code: '%cd',
103+
name: 'committer date',
104+
fullDescription: 'committer date (format respects --date= option)',
105+
description: ' (format respects --date= option)',
106+
identifier: 'committer_date_(format_respects_--date=_option)' },
107+
{ code: '%cD',
108+
name: 'committer date',
109+
fullDescription: 'committer date, RFC2822 style',
110+
description: ', RFC2822 style',
111+
identifier: 'committer_date_RFC2822_style' },
112+
{ code: '%cr',
113+
name: 'committer date',
114+
fullDescription: 'committer date, relative',
115+
description: ', relative',
116+
identifier: 'committer_date_relative' },
117+
{ code: '%ct',
118+
name: 'committer date',
119+
fullDescription: 'committer date, UNIX timestamp',
120+
description: ', UNIX timestamp',
121+
identifier: 'committer_date_UNIX_timestamp' },
122+
{ code: '%ci',
123+
name: 'committer date',
124+
fullDescription: 'committer date, ISO 8601-like format',
125+
description: ', ISO 8601-like format',
126+
identifier: 'committer_date_ISO_8601-like_format' },
127+
{ code: '%cI',
128+
name: 'committer date',
129+
fullDescription: 'committer date, strict ISO 8601 format',
130+
description: ', strict ISO 8601 format',
131+
identifier: 'committer_date_strict_ISO_8601_format' },
132+
{ code: '%d',
133+
name: 'ref names',
134+
fullDescription: 'ref names, like the --decorate option of git-log[1]',
135+
description: ', like the --decorate option of git-log[1]',
136+
identifier: 'ref_names' },
137+
{ code: '%D',
138+
name: 'ref names without the "',
139+
fullDescription: 'ref names without the " (", ")" wrapping.',
140+
description: ' (", ")" wrapping.',
141+
identifier: 'ref_names_without_the_"' },
142+
{ code: '%e',
143+
name: 'encoding',
144+
fullDescription: 'encoding',
145+
description: '',
146+
identifier: 'encoding' },
147+
{ code: '%s',
148+
name: 'subject',
149+
fullDescription: 'subject',
150+
description: '',
151+
identifier: 'subject' },
152+
{ code: '%f',
153+
name: 'sanitized subject line',
154+
fullDescription: 'sanitized subject line, suitable for a filename',
155+
description: ', suitable for a filename',
156+
identifier: 'sanitized_subject_line' },
157+
{ code: '%b',
158+
name: 'body',
159+
fullDescription: 'body',
160+
description: '',
161+
identifier: 'body' },
162+
{ code: '%B',
163+
name: 'raw body',
164+
fullDescription: 'raw body (unwrapped subject and body)',
165+
description: ' (unwrapped subject and body)',
166+
identifier: 'raw_body' },
167+
{ code: '%N',
168+
name: 'commit notes',
169+
fullDescription: 'commit notes',
170+
description: '',
171+
identifier: 'commit_notes' },
172+
{ code: '%GG',
173+
name: 'raw verification message from GPG for a signed commit',
174+
fullDescription: 'raw verification message from GPG for a signed commit',
175+
description: '',
176+
identifier: 'raw_verification_message_from_GPG_for_a_signed_commit' },
177+
{ code: '%G?',
178+
name: 'show "G" for a good',
179+
fullDescription: 'show "G" for a good (valid) signature, "B" for a bad signature, "U" for a good signature with unknown validity, "X" for a good signature that has expired, "Y" for a good signature made by an expired key, "R" for a good signature made by a revoked key, "E" if the signature cannot be checked (e.g. missing key) and "N" for no signature',
180+
description: ' (valid) signature, "B" for a bad signature, "U" for a good signature with unknown validity, "X" for a good signature that has expired, "Y" for a good signature made by an expired key, "R" for a good signature made by a revoked key, "E" if the signature cannot be checked (e.g. missing key) and "N" for no signature',
181+
identifier: 'show_"G"_for_a_good' },
182+
{ code: '%GS',
183+
name: 'show the name of the signer for a signed commit',
184+
fullDescription: 'show the name of the signer for a signed commit',
185+
description: '',
186+
identifier: 'show_the_name_of_the_signer_for_a_signed_commit' },
187+
{ code: '%GK',
188+
name: 'show the key used to sign a signed commit',
189+
fullDescription: 'show the key used to sign a signed commit',
190+
description: '',
191+
identifier: 'show_the_key_used_to_sign_a_signed_commit' },
192+
{ code: '%gD',
193+
name: 'reflog selector',
194+
fullDescription: 'reflog selector, e.g., refs/stash@{1} or refs/stash@{2 minutes ago}; the format follows the rules described for the -g option. The portion before the @ is the refname as given on the command line (so git log -g refs/heads/master would yield refs/heads/master@{0}).',
195+
description: ', e.g., refs/stash@{1} or refs/stash@{2 minutes ago}; the format follows the rules described for the -g option. The portion before the @ is the refname as given on the command line (so git log -g refs/heads/master would yield refs/heads/master@{0}).',
196+
identifier: 'reflog_selector' },
197+
{ code: '%gd',
198+
name: 'shortened reflog selector',
199+
fullDescription: 'shortened reflog selector; same as %gD, but the refname portion is shortened for human readability (so refs/heads/master becomes just master).',
200+
description: '; same as %gD, but the refname portion is shortened for human readability (so refs/heads/master becomes just master).',
201+
identifier: 'shortened_reflog_selector' },
202+
{ code: '%gn',
203+
name: 'reflog identity name',
204+
fullDescription: 'reflog identity name',
205+
description: '',
206+
identifier: 'reflog_identity_name' },
207+
{ code: '%gN',
208+
name: 'reflog identity name',
209+
fullDescription: 'reflog identity name (respecting .mailmap, see git-shortlog[1] or git-blame[1])',
210+
description: ' (respecting .mailmap, see git-shortlog[1] or git-blame[1])',
211+
identifier: 'reflog_identity_name_(respecting_.mailmap_see_git-shortlog[1]_or_git-blame[1])' },
212+
{ code: '%ge',
213+
name: 'reflog identity email',
214+
fullDescription: 'reflog identity email',
215+
description: '',
216+
identifier: 'reflog_identity_email' },
217+
{ code: '%gE',
218+
name: 'reflog identity email',
219+
fullDescription: 'reflog identity email (respecting .mailmap, see git-shortlog[1] or git-blame[1])',
220+
description: ' (respecting .mailmap, see git-shortlog[1] or git-blame[1])',
221+
identifier: 'reflog_identity_email_(respecting_.mailmap_see_git-shortlog[1]_or_git-blame[1])' },
222+
{ code: '%gs',
223+
name: 'reflog subject',
224+
fullDescription: 'reflog subject',
225+
description: '',
226+
identifier: 'reflog_subject' } ];

0 commit comments

Comments
 (0)