17
18
new_commit ::= 'commit' sp ref_str lf
19
mark?
20
- ('author' sp name '<' email '>' ts tz lf)?
21
- 'committer' sp name '<' email '>' ts tz lf
20
+ ('author' sp name '<' email '>' when lf)?
21
+ 'committer' sp name '<' email '>' when lf
22
commit_msg
23
('from' sp (ref_str | hexsha1 | sha1exp_str | idnum) lf)?
24
('merge' sp (ref_str | hexsha1 | sha1exp_str | idnum) lf)*
34
35
new_tag ::= 'tag' sp tag_str lf
36
'from' sp (ref_str | hexsha1 | sha1exp_str | idnum) lf
37
- 'tagger' sp name '<' email '>' ts tz lf
37
+ 'tagger' sp name '<' email '>' when lf
38
tag_msg;
39
tag_msg ::= data;
40
88
bigint ::= # unsigned integer value, ascii base10 notation;
89
binary_data ::= # file content, not interpreted;
90
91
+ when ::= raw_when | rfc2822_when;
92
+ raw_when ::= ts sp tz;
93
+ rfc2822_when ::= # Valid RFC 2822 date and time;
94
+
95
sp ::= # ASCII space character;
96
lf ::= # ASCII newline (LF) character;
97
238
unsigned char sha1[20];
239
};
240
241
+typedef enum {
242
+ WHENSPEC_RAW = 1,
243
+ WHENSPEC_RFC2822,
244
+ WHENSPEC_NOW,
245
+} whenspec_type;
246
+
247
/* Configured limits on output */
248
static unsigned long max_depth = 10;
249
static unsigned long max_packsize = (1LL << 32) - 1;
304
static struct tag *last_tag;
305
306
/* Input stream parsing */
307
+static whenspec_type whenspec = WHENSPEC_RAW;
308
static struct strbuf command_buf;
309
static uintmax_t next_mark;
310
static struct dbuf new_data;
1407
return buffer;
1408
}
1409
1410
+static int validate_raw_date(const char *src, char *result, int maxlen)
1411
+{
1412
+ const char *orig_src = src;
1413
+ char *endp, sign;
1414
+
1415
+ strtoul(src, &endp, 10);
1416
+ if (endp == src || *endp != ' ')
1417
+ return -1;
1418
+
1419
+ src = endp + 1;
1420
+ if (*src != '-' && *src != '+')
1421
+ return -1;
1422
+ sign = *src;
1423
+
1424
+ strtoul(src + 1, &endp, 10);
1425
+ if (endp == src || *endp || (endp - orig_src) >= maxlen)
1426
+ return -1;
1427
+
1428
+ strcpy(result, orig_src);
1429
+ return 0;
1430
+}
1431
+
1432
+static char *parse_ident(const char *buf)
1433
+{
1434
+ const char *gt;
1435
+ size_t name_len;
1436
+ char *ident;
1437
+
1438
+ gt = strrchr(buf, '>');
1439
+ if (!gt)
1440
+ die("Missing > in ident string: %s", buf);
1441
+ gt++;
1442
+ if (*gt != ' ')
1443
+ die("Missing space after > in ident string: %s", buf);
1444
+ gt++;
1445
+ name_len = gt - buf;
1446
+ ident = xmalloc(name_len + 24);
1447
+ strncpy(ident, buf, name_len);
1448
+
1449
+ switch (whenspec) {
1450
+ case WHENSPEC_RAW:
1451
+ if (validate_raw_date(gt, ident + name_len, 24) < 0)
1452
+ die("Invalid raw date \"%s\" in ident: %s", gt, buf);
1453
+ break;
1454
+ case WHENSPEC_RFC2822:
1455
+ if (parse_date(gt, ident + name_len, 24) < 0)
1456
+ die("Invalid rfc2822 date \"%s\" in ident: %s", gt, buf);
1457
+ break;
1458
+ case WHENSPEC_NOW:
1459
+ if (strcmp("now", gt))
1460
+ die("Date in ident must be 'now': %s", buf);
1461
+ datestamp(ident + name_len, 24);
1462
+ break;
1463
+ }
1464
+
1465
+ return ident;
1466
+}
1467
+
1468
static void cmd_new_blob(void)
1469
{
1470
size_t l;
1724
read_next_command();
1725
cmd_mark();
1726
if (!strncmp("author ", command_buf.buf, 7)) {
1658
- author = strdup(command_buf.buf);
1727
+ author = parse_ident(command_buf.buf + 7);
1728
read_next_command();
1729
}
1730
if (!strncmp("committer ", command_buf.buf, 10)) {
1662
- committer = strdup(command_buf.buf);
1731
+ committer = parse_ident(command_buf.buf + 10);
1732
read_next_command();
1733
}
1734
if (!committer)
1761
store_tree(&b->branch_tree);
1762
hashcpy(b->branch_tree.versions[0].sha1,
1763
b->branch_tree.versions[1].sha1);
1695
- size_dbuf(&new_data, 97 + msglen
1764
+ size_dbuf(&new_data, 114 + msglen
1765
+ merge_count * 49
1766
+ (author
1767
? strlen(author) + strlen(committer)
1777
free(merge_list);
1778
merge_list = next;
1779
}
1711
- if (author)
1712
- sp += sprintf(sp, "%s\n", author);
1713
- else
1714
- sp += sprintf(sp, "author %s\n", committer + 10);
1715
- sp += sprintf(sp, "%s\n\n", committer);
1780
+ sp += sprintf(sp, "author %s\n", author ? author : committer);
1781
+ sp += sprintf(sp, "committer %s\n", committer);
1782
+ *sp++ = '\n';
1783
memcpy(sp, msg, msglen);
1784
sp += msglen;
1785
free(author);
1847
/* tagger ... */
1848
if (strncmp("tagger ", command_buf.buf, 7))
1849
die("Expected tagger command, got %s", command_buf.buf);
1783
- tagger = strdup(command_buf.buf);
1850
+ tagger = parse_ident(command_buf.buf + 7);
1851
1852
/* tag payload/message */
1853
read_next_command();
1859
sp += sprintf(sp, "object %s\n", sha1_to_hex(sha1));
1860
sp += sprintf(sp, "type %s\n", type_names[OBJ_COMMIT]);
1861
sp += sprintf(sp, "tag %s\n", t->name);
1795
- sp += sprintf(sp, "%s\n\n", tagger);
1862
+ sp += sprintf(sp, "tagger %s\n", tagger);
1863
+ *sp++ = '\n';
1864
memcpy(sp, msg, msglen);
1865
sp += msglen;
1866
free(tagger);
1903
}
1904
1905
static const char fast_import_usage[] =
1838
-"git-fast-import [--depth=n] [--active-branches=n] [--export-marks=marks.file] [--branch-log=log]";
1906
+"git-fast-import [--date-format=f] [--max-pack-size=n] [--depth=n] [--active-branches=n] [--export-marks=marks.file]";
1907
1908
int main(int argc, const char **argv)
1909
{
1917
1918
if (*a != '-' || !strcmp(a, "--"))
1919
break;
1920
+ else if (!strncmp(a, "--date-format=", 14)) {
1921
+ const char *fmt = a + 14;
1922
+ if (!strcmp(fmt, "raw"))
1923
+ whenspec = WHENSPEC_RAW;
1924
+ else if (!strcmp(fmt, "rfc2822"))
1925
+ whenspec = WHENSPEC_RFC2822;
1926
+ else if (!strcmp(fmt, "now"))
1927
+ whenspec = WHENSPEC_NOW;
1928
+ else
1929
+ die("unknown --date-format argument %s", fmt);
1930
+ }
1931
else if (!strncmp(a, "--max-pack-size=", 16))
1932
max_packsize = strtoumax(a + 16, NULL, 0) * 1024 * 1024;
1933
else if (!strncmp(a, "--depth=", 8))