1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.logTask = exports.parseLogOptions = void 0;
|
4 | const parse_list_log_summary_1 = require("../parsers/parse-list-log-summary");
|
5 | const utils_1 = require("../utils");
|
6 | const task_1 = require("./task");
|
7 | var excludeOptions;
|
8 | (function (excludeOptions) {
|
9 | excludeOptions[excludeOptions["--pretty"] = 0] = "--pretty";
|
10 | excludeOptions[excludeOptions["max-count"] = 1] = "max-count";
|
11 | excludeOptions[excludeOptions["maxCount"] = 2] = "maxCount";
|
12 | excludeOptions[excludeOptions["n"] = 3] = "n";
|
13 | excludeOptions[excludeOptions["file"] = 4] = "file";
|
14 | excludeOptions[excludeOptions["format"] = 5] = "format";
|
15 | excludeOptions[excludeOptions["from"] = 6] = "from";
|
16 | excludeOptions[excludeOptions["to"] = 7] = "to";
|
17 | excludeOptions[excludeOptions["splitter"] = 8] = "splitter";
|
18 | excludeOptions[excludeOptions["symmetric"] = 9] = "symmetric";
|
19 | excludeOptions[excludeOptions["mailMap"] = 10] = "mailMap";
|
20 | excludeOptions[excludeOptions["multiLine"] = 11] = "multiLine";
|
21 | excludeOptions[excludeOptions["strictDate"] = 12] = "strictDate";
|
22 | })(excludeOptions || (excludeOptions = {}));
|
23 | function prettyFormat(format, splitter) {
|
24 | const fields = [];
|
25 | const formatStr = [];
|
26 | Object.keys(format).forEach((field) => {
|
27 | fields.push(field);
|
28 | formatStr.push(String(format[field]));
|
29 | });
|
30 | return [
|
31 | fields, formatStr.join(splitter)
|
32 | ];
|
33 | }
|
34 | function userOptions(input) {
|
35 | const output = Object.assign({}, input);
|
36 | Object.keys(input).forEach(key => {
|
37 | if (key in excludeOptions) {
|
38 | delete output[key];
|
39 | }
|
40 | });
|
41 | return output;
|
42 | }
|
43 | function parseLogOptions(opt = {}, customArgs = []) {
|
44 | const splitter = opt.splitter || parse_list_log_summary_1.SPLITTER;
|
45 | const format = opt.format || {
|
46 | hash: '%H',
|
47 | date: opt.strictDate === false ? '%ai' : '%aI',
|
48 | message: '%s',
|
49 | refs: '%D',
|
50 | body: opt.multiLine ? '%B' : '%b',
|
51 | author_name: opt.mailMap !== false ? '%aN' : '%an',
|
52 | author_email: opt.mailMap !== false ? '%aE' : '%ae'
|
53 | };
|
54 | const [fields, formatStr] = prettyFormat(format, splitter);
|
55 | const suffix = [];
|
56 | const command = [
|
57 | `--pretty=format:${parse_list_log_summary_1.START_BOUNDARY}${formatStr}${parse_list_log_summary_1.COMMIT_BOUNDARY}`,
|
58 | ...customArgs,
|
59 | ];
|
60 | const maxCount = opt.n || opt['max-count'] || opt.maxCount;
|
61 | if (maxCount) {
|
62 | command.push(`--max-count=${maxCount}`);
|
63 | }
|
64 | if (opt.from && opt.to) {
|
65 | const rangeOperator = (opt.symmetric !== false) ? '...' : '..';
|
66 | suffix.push(`${opt.from}${rangeOperator}${opt.to}`);
|
67 | }
|
68 | if (opt.file) {
|
69 | suffix.push('--follow', opt.file);
|
70 | }
|
71 | utils_1.appendTaskOptions(userOptions(opt), command);
|
72 | return {
|
73 | fields,
|
74 | splitter,
|
75 | commands: [
|
76 | ...command,
|
77 | ...suffix,
|
78 | ],
|
79 | };
|
80 | }
|
81 | exports.parseLogOptions = parseLogOptions;
|
82 | function logTask(splitter, fields, customArgs) {
|
83 | return {
|
84 | commands: ['log', ...customArgs],
|
85 | format: 'utf-8',
|
86 | parser: parse_list_log_summary_1.createListLogSummaryParser(splitter, fields),
|
87 | };
|
88 | }
|
89 | exports.logTask = logTask;
|
90 | function default_1() {
|
91 | return {
|
92 | log(...rest) {
|
93 | const next = utils_1.trailingFunctionArgument(arguments);
|
94 | const task = rejectDeprecatedSignatures(...rest) ||
|
95 | createLogTask(parseLogOptions(utils_1.trailingOptionsArgument(arguments), utils_1.filterType(arguments[0], utils_1.filterArray)));
|
96 | return this._runTask(task, next);
|
97 | }
|
98 | };
|
99 | function createLogTask(options) {
|
100 | return logTask(options.splitter, options.fields, options.commands);
|
101 | }
|
102 | function rejectDeprecatedSignatures(from, to) {
|
103 | return (utils_1.filterString(from) &&
|
104 | utils_1.filterString(to) &&
|
105 | task_1.configurationErrorTask(`git.log(string, string) should be replaced with git.log({ from: string, to: string })`));
|
106 | }
|
107 | }
|
108 | exports.default = default_1;
|
109 |
|
\ | No newline at end of file |