revision.c: use skip_prefix() in handle_revision_opt()
Instead of starts_with() and a bunch of magic numbers. Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com> Reviewed-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
SZEDER Gábor committed
Jun 9, 2017 at 20:17 UTC
479b3d978597110208d5a7623a626b28d5c801e0
1 file changed
+23
-25
revision.c
+23
-25
@@ -1690,8 +1690,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
1690
revs->max_count = atoi(argv[1]);
1691
revs->no_walk = 0;
1692
return 2;
1693
- } else if (starts_with(arg, "-n")) {
1694
- revs->max_count = atoi(arg + 2);
1693
+ } else if (skip_prefix(arg, "-n", &optarg)) {
1694
+ revs->max_count = atoi(optarg);
1695
revs->no_walk = 0;
1696
} else if ((argcount = parse_long_opt("max-age", argv, &optarg))) {
1697
revs->max_age = atoi(optarg);
@@ -1772,12 +1772,12 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
1772
revs->min_parents = 2;
1773
} else if (!strcmp(arg, "--no-merges")) {
1774
revs->max_parents = 1;
1775
- } else if (starts_with(arg, "--min-parents=")) {
1776
- revs->min_parents = atoi(arg+14);
1775
+ } else if (skip_prefix(arg, "--min-parents=", &optarg)) {
1776
+ revs->min_parents = atoi(optarg);
1777
} else if (!strcmp(arg, "--no-min-parents")) {
1778
revs->min_parents = 0;
1779
- } else if (starts_with(arg, "--max-parents=")) {
1780
- revs->max_parents = atoi(arg+14);
1779
+ } else if (skip_prefix(arg, "--max-parents=", &optarg)) {
1780
+ revs->max_parents = atoi(optarg);
1781
} else if (!strcmp(arg, "--no-max-parents")) {
1782
revs->max_parents = -1;
1783
} else if (!strcmp(arg, "--boundary")) {
@@ -1859,14 +1859,15 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
1859
revs->verbose_header = 1;
1860
revs->pretty_given = 1;
1861
get_commit_format(NULL, revs);
1862
- } else if (starts_with(arg, "--pretty=") || starts_with(arg, "--format=")) {
1862
+ } else if (skip_prefix(arg, "--pretty=", &optarg) ||
1863
+ skip_prefix(arg, "--format=", &optarg)) {
1864
/*
1865
* Detached form ("--pretty X" as opposed to "--pretty=X")
1866
* not allowed, since the argument is optional.
1867
*/
1868
revs->verbose_header = 1;
1869
revs->pretty_given = 1;
1869
- get_commit_format(arg+9, revs);
1870
+ get_commit_format(optarg, revs);
1871
} else if (!strcmp(arg, "--expand-tabs")) {
1872
revs->expand_tabs_in_log = 8;
1873
} else if (!strcmp(arg, "--no-expand-tabs")) {
@@ -1884,26 +1885,23 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
1885
revs->show_signature = 1;
1886
} else if (!strcmp(arg, "--no-show-signature")) {
1887
revs->show_signature = 0;
1887
- } else if (!strcmp(arg, "--show-linear-break") ||
1888
- starts_with(arg, "--show-linear-break=")) {
1889
- if (starts_with(arg, "--show-linear-break="))
1890
- revs->break_bar = xstrdup(arg + 20);
1891
- else
1892
- revs->break_bar = " ..........";
1888
+ } else if (!strcmp(arg, "--show-linear-break")) {
1889
+ revs->break_bar = " ..........";
1890
+ revs->track_linear = 1;
1891
+ revs->track_first_time = 1;
1892
+ } else if (skip_prefix(arg, "--show-linear-break=", &optarg)) {
1893
+ revs->break_bar = xstrdup(optarg);
1894
revs->track_linear = 1;
1895
revs->track_first_time = 1;
1895
- } else if (starts_with(arg, "--show-notes=") ||
1896
- starts_with(arg, "--notes=")) {
1896
+ } else if (skip_prefix(arg, "--show-notes=", &optarg) ||
1897
+ skip_prefix(arg, "--notes=", &optarg)) {
1898
struct strbuf buf = STRBUF_INIT;
1899
revs->show_notes = 1;
1900
revs->show_notes_given = 1;
1900
- if (starts_with(arg, "--show-notes")) {
1901
- if (revs->notes_opt.use_default_notes < 0)
1902
- revs->notes_opt.use_default_notes = 1;
1903
- strbuf_addstr(&buf, arg+13);
1904
- }
1905
- else
1906
- strbuf_addstr(&buf, arg+8);
1901
+ if (starts_with(arg, "--show-notes=") &&
1902
+ revs->notes_opt.use_default_notes < 0)
1903
+ revs->notes_opt.use_default_notes = 1;
1904
+ strbuf_addstr(&buf, optarg);
1905
expand_notes_ref(&buf);
1906
string_list_append(&revs->notes_opt.extra_notes_refs,
1907
strbuf_detach(&buf, NULL));
@@ -1940,8 +1938,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
1938
revs->abbrev = 0;
1939
} else if (!strcmp(arg, "--abbrev")) {
1940
revs->abbrev = DEFAULT_ABBREV;
1943
- } else if (starts_with(arg, "--abbrev=")) {
1944
- revs->abbrev = strtoul(arg + 9, NULL, 10);
1941
+ } else if (skip_prefix(arg, "--abbrev=", &optarg)) {
1942
+ revs->abbrev = strtoul(optarg, NULL, 10);
1943
if (revs->abbrev < MINIMUM_ABBREV)
1944
revs->abbrev = MINIMUM_ABBREV;
1945
else if (revs->abbrev > 40)