23
('from' sp (ref_str | hexsha1 | sha1exp_str | idnum) lf)?
24
('merge' sp (ref_str | hexsha1 | sha1exp_str | idnum) lf)*
25
file_change*
26
- lf;
26
+ lf?;
27
commit_msg ::= data;
28
29
file_change ::= file_clr
48
49
reset_branch ::= 'reset' sp ref_str lf
50
('from' sp (ref_str | hexsha1 | sha1exp_str | idnum) lf)?
51
- lf;
51
+ lf?;
52
53
checkpoint ::= 'checkpoint' lf
54
- lf;
54
+ lf?;
55
56
# note: the first idnum in a stream should be 1 and subsequent
57
# idnums should not have gaps between values as this will cause
330
/* Input stream parsing */
331
static whenspec_type whenspec = WHENSPEC_RAW;
332
static struct strbuf command_buf;
333
+static int unread_command_buf;
334
static uintmax_t next_mark;
335
static struct dbuf new_data;
336
1467
static void read_next_command(void)
1468
{
1469
do {
1469
- read_line(&command_buf, stdin, '\n');
1470
+ if (unread_command_buf)
1471
+ unread_command_buf = 0;
1472
+ else
1473
+ read_line(&command_buf, stdin, '\n');
1474
} while (!command_buf.eof && command_buf.buf[0] == '#');
1475
}
1476
1829
}
1830
}
1831
1828
-static void cmd_from(struct branch *b)
1832
+static int cmd_from(struct branch *b)
1833
{
1834
const char *from;
1835
struct branch *s;
1836
1837
if (prefixcmp(command_buf.buf, "from "))
1834
- return;
1838
+ return 0;
1839
1840
if (b->branch_tree.tree) {
1841
release_tree_content_recursive(b->branch_tree.tree);
1870
die("Invalid ref name or SHA1 expression: %s", from);
1871
1872
read_next_command();
1873
+ return 1;
1874
}
1875
1876
static struct hash_list *cmd_merge(unsigned int *count)
1955
}
1956
1957
/* file_change* */
1953
- for (;;) {
1954
- if (1 == command_buf.len)
1955
- break;
1956
- else if (!prefixcmp(command_buf.buf, "M "))
1958
+ while (!command_buf.eof && command_buf.len > 1) {
1959
+ if (!prefixcmp(command_buf.buf, "M "))
1960
file_change_m(b);
1961
else if (!prefixcmp(command_buf.buf, "D "))
1962
file_change_d(b);
1966
file_change_cr(b, 0);
1967
else if (!strcmp("deleteall", command_buf.buf))
1968
file_change_deleteall(b);
1966
- else
1967
- die("Unsupported file_change: %s", command_buf.buf);
1969
+ else {
1970
+ unread_command_buf = 1;
1971
+ break;
1972
+ }
1973
read_next_command();
1974
}
1975
2110
else
2111
b = new_branch(sp);
2112
read_next_command();
2108
- cmd_from(b);
2113
+ if (!cmd_from(b) && command_buf.len > 1)
2114
+ unread_command_buf = 1;
2115
}
2116
2117
static void cmd_checkpoint(void)
2122
dump_tags();
2123
dump_marks();
2124
}
2119
- read_next_command();
2125
+ skip_optional_lf();
2126
}
2127
2128
static void import_marks(const char *input_file)