Skip to content

Commit e77d58a

Browse files
committed
Merge branch 'sg/revision-parser-skip-prefix'
Code clean-up. * sg/revision-parser-skip-prefix: revision.c: use skip_prefix() in handle_revision_pseudo_opt() revision.c: use skip_prefix() in handle_revision_opt() revision.c: stricter parsing of '--early-output' revision.c: stricter parsing of '--no-{min,max}-parents' revision.h: turn rev_info.early_output back into an unsigned int
2 parents f77149c + 8b1d913 commit e77d58a

File tree

2 files changed

+44
-48
lines changed

2 files changed

+44
-48
lines changed

revision.c

Lines changed: 41 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,8 +1725,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
17251725
revs->max_count = atoi(argv[1]);
17261726
revs->no_walk = 0;
17271727
return 2;
1728-
} else if (starts_with(arg, "-n")) {
1729-
revs->max_count = atoi(arg + 2);
1728+
} else if (skip_prefix(arg, "-n", &optarg)) {
1729+
revs->max_count = atoi(optarg);
17301730
revs->no_walk = 0;
17311731
} else if ((argcount = parse_long_opt("max-age", argv, &optarg))) {
17321732
revs->max_age = atoi(optarg);
@@ -1785,16 +1785,13 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
17851785
} else if (!strcmp(arg, "--author-date-order")) {
17861786
revs->sort_order = REV_SORT_BY_AUTHOR_DATE;
17871787
revs->topo_order = 1;
1788-
} else if (starts_with(arg, "--early-output")) {
1789-
int count = 100;
1790-
switch (arg[14]) {
1791-
case '=':
1792-
count = atoi(arg+15);
1793-
/* Fallthrough */
1794-
case 0:
1795-
revs->topo_order = 1;
1796-
revs->early_output = count;
1797-
}
1788+
} else if (!strcmp(arg, "--early-output")) {
1789+
revs->early_output = 100;
1790+
revs->topo_order = 1;
1791+
} else if (skip_prefix(arg, "--early-output=", &optarg)) {
1792+
if (strtoul_ui(optarg, 10, &revs->early_output) < 0)
1793+
die("'%s': not a non-negative integer", optarg);
1794+
revs->topo_order = 1;
17981795
} else if (!strcmp(arg, "--parents")) {
17991796
revs->rewrite_parents = 1;
18001797
revs->print_parents = 1;
@@ -1810,13 +1807,13 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
18101807
revs->min_parents = 2;
18111808
} else if (!strcmp(arg, "--no-merges")) {
18121809
revs->max_parents = 1;
1813-
} else if (starts_with(arg, "--min-parents=")) {
1814-
revs->min_parents = atoi(arg+14);
1815-
} else if (starts_with(arg, "--no-min-parents")) {
1810+
} else if (skip_prefix(arg, "--min-parents=", &optarg)) {
1811+
revs->min_parents = atoi(optarg);
1812+
} else if (!strcmp(arg, "--no-min-parents")) {
18161813
revs->min_parents = 0;
1817-
} else if (starts_with(arg, "--max-parents=")) {
1818-
revs->max_parents = atoi(arg+14);
1819-
} else if (starts_with(arg, "--no-max-parents")) {
1814+
} else if (skip_prefix(arg, "--max-parents=", &optarg)) {
1815+
revs->max_parents = atoi(optarg);
1816+
} else if (!strcmp(arg, "--no-max-parents")) {
18201817
revs->max_parents = -1;
18211818
} else if (!strcmp(arg, "--boundary")) {
18221819
revs->boundary = 1;
@@ -1897,14 +1894,15 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
18971894
revs->verbose_header = 1;
18981895
revs->pretty_given = 1;
18991896
get_commit_format(NULL, revs);
1900-
} else if (starts_with(arg, "--pretty=") || starts_with(arg, "--format=")) {
1897+
} else if (skip_prefix(arg, "--pretty=", &optarg) ||
1898+
skip_prefix(arg, "--format=", &optarg)) {
19011899
/*
19021900
* Detached form ("--pretty X" as opposed to "--pretty=X")
19031901
* not allowed, since the argument is optional.
19041902
*/
19051903
revs->verbose_header = 1;
19061904
revs->pretty_given = 1;
1907-
get_commit_format(arg+9, revs);
1905+
get_commit_format(optarg, revs);
19081906
} else if (!strcmp(arg, "--expand-tabs")) {
19091907
revs->expand_tabs_in_log = 8;
19101908
} else if (!strcmp(arg, "--no-expand-tabs")) {
@@ -1922,26 +1920,23 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
19221920
revs->show_signature = 1;
19231921
} else if (!strcmp(arg, "--no-show-signature")) {
19241922
revs->show_signature = 0;
1925-
} else if (!strcmp(arg, "--show-linear-break") ||
1926-
starts_with(arg, "--show-linear-break=")) {
1927-
if (starts_with(arg, "--show-linear-break="))
1928-
revs->break_bar = xstrdup(arg + 20);
1929-
else
1930-
revs->break_bar = " ..........";
1923+
} else if (!strcmp(arg, "--show-linear-break")) {
1924+
revs->break_bar = " ..........";
19311925
revs->track_linear = 1;
19321926
revs->track_first_time = 1;
1933-
} else if (starts_with(arg, "--show-notes=") ||
1934-
starts_with(arg, "--notes=")) {
1927+
} else if (skip_prefix(arg, "--show-linear-break=", &optarg)) {
1928+
revs->break_bar = xstrdup(optarg);
1929+
revs->track_linear = 1;
1930+
revs->track_first_time = 1;
1931+
} else if (skip_prefix(arg, "--show-notes=", &optarg) ||
1932+
skip_prefix(arg, "--notes=", &optarg)) {
19351933
struct strbuf buf = STRBUF_INIT;
19361934
revs->show_notes = 1;
19371935
revs->show_notes_given = 1;
1938-
if (starts_with(arg, "--show-notes")) {
1939-
if (revs->notes_opt.use_default_notes < 0)
1940-
revs->notes_opt.use_default_notes = 1;
1941-
strbuf_addstr(&buf, arg+13);
1942-
}
1943-
else
1944-
strbuf_addstr(&buf, arg+8);
1936+
if (starts_with(arg, "--show-notes=") &&
1937+
revs->notes_opt.use_default_notes < 0)
1938+
revs->notes_opt.use_default_notes = 1;
1939+
strbuf_addstr(&buf, optarg);
19451940
expand_notes_ref(&buf);
19461941
string_list_append(&revs->notes_opt.extra_notes_refs,
19471942
strbuf_detach(&buf, NULL));
@@ -1978,8 +1973,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
19781973
revs->abbrev = 0;
19791974
} else if (!strcmp(arg, "--abbrev")) {
19801975
revs->abbrev = DEFAULT_ABBREV;
1981-
} else if (starts_with(arg, "--abbrev=")) {
1982-
revs->abbrev = strtoul(arg + 9, NULL, 10);
1976+
} else if (skip_prefix(arg, "--abbrev=", &optarg)) {
1977+
revs->abbrev = strtoul(optarg, NULL, 10);
19831978
if (revs->abbrev < MINIMUM_ABBREV)
19841979
revs->abbrev = MINIMUM_ABBREV;
19851980
else if (revs->abbrev > 40)
@@ -2140,20 +2135,20 @@ static int handle_revision_pseudo_opt(const char *submodule,
21402135
} else if ((argcount = parse_long_opt("exclude", argv, &optarg))) {
21412136
add_ref_exclusion(&revs->ref_excludes, optarg);
21422137
return argcount;
2143-
} else if (starts_with(arg, "--branches=")) {
2138+
} else if (skip_prefix(arg, "--branches=", &optarg)) {
21442139
struct all_refs_cb cb;
21452140
init_all_refs_cb(&cb, revs, *flags);
2146-
for_each_glob_ref_in(handle_one_ref, arg + 11, "refs/heads/", &cb);
2141+
for_each_glob_ref_in(handle_one_ref, optarg, "refs/heads/", &cb);
21472142
clear_ref_exclusion(&revs->ref_excludes);
2148-
} else if (starts_with(arg, "--tags=")) {
2143+
} else if (skip_prefix(arg, "--tags=", &optarg)) {
21492144
struct all_refs_cb cb;
21502145
init_all_refs_cb(&cb, revs, *flags);
2151-
for_each_glob_ref_in(handle_one_ref, arg + 7, "refs/tags/", &cb);
2146+
for_each_glob_ref_in(handle_one_ref, optarg, "refs/tags/", &cb);
21522147
clear_ref_exclusion(&revs->ref_excludes);
2153-
} else if (starts_with(arg, "--remotes=")) {
2148+
} else if (skip_prefix(arg, "--remotes=", &optarg)) {
21542149
struct all_refs_cb cb;
21552150
init_all_refs_cb(&cb, revs, *flags);
2156-
for_each_glob_ref_in(handle_one_ref, arg + 10, "refs/remotes/", &cb);
2151+
for_each_glob_ref_in(handle_one_ref, optarg, "refs/remotes/", &cb);
21572152
clear_ref_exclusion(&revs->ref_excludes);
21582153
} else if (!strcmp(arg, "--reflog")) {
21592154
add_reflogs_to_pending(revs, *flags);
@@ -2163,14 +2158,14 @@ static int handle_revision_pseudo_opt(const char *submodule,
21632158
*flags ^= UNINTERESTING | BOTTOM;
21642159
} else if (!strcmp(arg, "--no-walk")) {
21652160
revs->no_walk = REVISION_WALK_NO_WALK_SORTED;
2166-
} else if (starts_with(arg, "--no-walk=")) {
2161+
} else if (skip_prefix(arg, "--no-walk=", &optarg)) {
21672162
/*
21682163
* Detached form ("--no-walk X" as opposed to "--no-walk=X")
21692164
* not allowed, since the argument is optional.
21702165
*/
2171-
if (!strcmp(arg + 10, "sorted"))
2166+
if (!strcmp(optarg, "sorted"))
21722167
revs->no_walk = REVISION_WALK_NO_WALK_SORTED;
2173-
else if (!strcmp(arg + 10, "unsorted"))
2168+
else if (!strcmp(optarg, "unsorted"))
21742169
revs->no_walk = REVISION_WALK_NO_WALK_UNSORTED;
21752170
else
21762171
return error("invalid argument to --no-walk");

revision.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,9 @@ struct rev_info {
7474
/* topo-sort */
7575
enum rev_sort_order sort_order;
7676

77-
unsigned int early_output:1,
78-
ignore_missing:1,
77+
unsigned int early_output;
78+
79+
unsigned int ignore_missing:1,
7980
ignore_missing_links:1;
8081

8182
/* Traversal flags */

0 commit comments

Comments
 (0)