1392
1393
static void cmd_mark(void)
1394
{
1395
- if (!strncmp("mark :", command_buf.buf, 6)) {
1395
+ if (!(-prefixcmp(command_buf.buf, "mark :"))) {
1396
next_mark = strtoumax(command_buf.buf + 6, NULL, 10);
1397
read_next_command();
1398
}
1405
size_t length;
1406
char *buffer;
1407
1408
- if (strncmp("data ", command_buf.buf, 5))
1408
+ if ((-prefixcmp(command_buf.buf, "data ")))
1409
die("Expected 'data n' command, found: %s", command_buf.buf);
1410
1411
- if (!strncmp("<<", command_buf.buf + 5, 2)) {
1411
+ if (!(-prefixcmp(command_buf.buf + 5, "<<"))) {
1412
char *term = xstrdup(command_buf.buf + 5 + 2);
1413
size_t sz = 8192, term_len = command_buf.len - 5 - 2;
1414
length = 0;
1595
oe = find_mark(strtoumax(p + 1, &x, 10));
1596
hashcpy(sha1, oe->sha1);
1597
p = x;
1598
- } else if (!strncmp("inline", p, 6)) {
1598
+ } else if (!(-prefixcmp(p, "inline"))) {
1599
inline_data = 1;
1600
p += 6;
1601
} else {
1668
const char *from;
1669
struct branch *s;
1670
1671
- if (strncmp("from ", command_buf.buf, 5))
1671
+ if ((-prefixcmp(command_buf.buf, "from ")))
1672
return;
1673
1674
if (b->branch_tree.tree) {
1734
struct branch *s;
1735
1736
*count = 0;
1737
- while (!strncmp("merge ", command_buf.buf, 6)) {
1737
+ while (!(-prefixcmp(command_buf.buf, "merge "))) {
1738
from = strchr(command_buf.buf, ' ') + 1;
1739
n = xmalloc(sizeof(*n));
1740
s = lookup_branch(from);
1780
1781
read_next_command();
1782
cmd_mark();
1783
- if (!strncmp("author ", command_buf.buf, 7)) {
1783
+ if (!(-prefixcmp(command_buf.buf, "author "))) {
1784
author = parse_ident(command_buf.buf + 7);
1785
read_next_command();
1786
}
1787
- if (!strncmp("committer ", command_buf.buf, 10)) {
1787
+ if (!(-prefixcmp(command_buf.buf, "committer "))) {
1788
committer = parse_ident(command_buf.buf + 10);
1789
read_next_command();
1790
}
1805
for (;;) {
1806
if (1 == command_buf.len)
1807
break;
1808
- else if (!strncmp("M ", command_buf.buf, 2))
1808
+ else if (!(-prefixcmp(command_buf.buf, "M ")))
1809
file_change_m(b);
1810
- else if (!strncmp("D ", command_buf.buf, 2))
1810
+ else if (!(-prefixcmp(command_buf.buf, "D ")))
1811
file_change_d(b);
1812
else if (!strcmp("deleteall", command_buf.buf))
1813
file_change_deleteall(b);
1877
read_next_command();
1878
1879
/* from ... */
1880
- if (strncmp("from ", command_buf.buf, 5))
1880
+ if ((-prefixcmp(command_buf.buf, "from ")))
1881
die("Expected from command, got %s", command_buf.buf);
1882
from = strchr(command_buf.buf, ' ') + 1;
1883
s = lookup_branch(from);
1904
read_next_command();
1905
1906
/* tagger ... */
1907
- if (strncmp("tagger ", command_buf.buf, 7))
1907
+ if ((-prefixcmp(command_buf.buf, "tagger ")))
1908
die("Expected tagger command, got %s", command_buf.buf);
1909
tagger = parse_ident(command_buf.buf + 7);
1910
1981
1982
if (*a != '-' || !strcmp(a, "--"))
1983
break;
1984
- else if (!strncmp(a, "--date-format=", 14)) {
1984
+ else if (!prefixcmp(a, "--date-format=")) {
1985
const char *fmt = a + 14;
1986
if (!strcmp(fmt, "raw"))
1987
whenspec = WHENSPEC_RAW;
1992
else
1993
die("unknown --date-format argument %s", fmt);
1994
}
1995
- else if (!strncmp(a, "--max-pack-size=", 16))
1995
+ else if (!prefixcmp(a, "--max-pack-size="))
1996
max_packsize = strtoumax(a + 16, NULL, 0) * 1024 * 1024;
1997
- else if (!strncmp(a, "--depth=", 8))
1997
+ else if (!prefixcmp(a, "--depth="))
1998
max_depth = strtoul(a + 8, NULL, 0);
1999
- else if (!strncmp(a, "--active-branches=", 18))
1999
+ else if (!prefixcmp(a, "--active-branches="))
2000
max_active_branches = strtoul(a + 18, NULL, 0);
2001
- else if (!strncmp(a, "--export-marks=", 15))
2001
+ else if (!prefixcmp(a, "--export-marks="))
2002
mark_file = a + 15;
2003
- else if (!strncmp(a, "--export-pack-edges=", 20)) {
2003
+ else if (!prefixcmp(a, "--export-pack-edges=")) {
2004
if (pack_edges)
2005
fclose(pack_edges);
2006
pack_edges = fopen(a + 20, "a");
2033
break;
2034
else if (!strcmp("blob", command_buf.buf))
2035
cmd_new_blob();
2036
- else if (!strncmp("commit ", command_buf.buf, 7))
2036
+ else if (!(-prefixcmp(command_buf.buf, "commit ")))
2037
cmd_new_commit();
2038
- else if (!strncmp("tag ", command_buf.buf, 4))
2038
+ else if (!(-prefixcmp(command_buf.buf, "tag ")))
2039
cmd_new_tag();
2040
- else if (!strncmp("reset ", command_buf.buf, 6))
2040
+ else if (!(-prefixcmp(command_buf.buf, "reset ")))
2041
cmd_reset_branch();
2042
else if (!strcmp("checkpoint", command_buf.buf))
2043
cmd_checkpoint();