Added --branch-log to option to fast-import.
This option can be used to have a record of every commit, the mark (if supplied) and branch name of the commit recorded into a log file when the commit is generated. This log can be useful to verify the results of an import as the commits can be compared to some source repository matching commits through the mark value. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce committed
Aug 25, 2006 at 23:07 UTC
264244a0429e23616a6065f6f52a15711981a8db
1 file changed
+37
-5
fast-import.c
+37
-5
@@ -248,6 +248,7 @@ static struct tag *last_tag;
248
/* Input stream parsing */
249
static struct strbuf command_buf;
250
static unsigned long next_mark;
251
+static FILE* branch_log;
252
253
254
static void alloc_objects(int cnt)
@@ -1137,7 +1138,7 @@ static void dump_marks_helper(FILE *f,
1138
} else {
1139
for (k = 0; k < 1024; k++) {
1140
if (m->data.marked[k])
1140
- fprintf(f, "%lu,%s\n", base + k,
1141
+ fprintf(f, ":%lu %s\n", base + k,
1142
sha1_to_hex(m->data.marked[k]->sha1));
1143
}
1144
}
@@ -1476,6 +1477,18 @@ static void cmd_new_commit()
1477
store_object(OBJ_COMMIT, body, sp - body, NULL, b->sha1, next_mark);
1478
free(body);
1479
b->last_commit = object_count_by_type[OBJ_COMMIT];
1480
+
1481
+ if (branch_log) {
1482
+ int need_dq = quote_c_style(b->name, NULL, NULL, 0);
1483
+ fprintf(branch_log, "commit ");
1484
+ if (need_dq) {
1485
+ fputc('"', branch_log);
1486
+ quote_c_style(b->name, NULL, branch_log, 0);
1487
+ fputc('"', branch_log);
1488
+ } else
1489
+ fprintf(branch_log, "%s", b->name);
1490
+ fprintf(branch_log," :%lu %s\n",next_mark,sha1_to_hex(b->sha1));
1491
+ }
1492
}
1493
1494
static void cmd_new_tag()
@@ -1490,6 +1503,7 @@ static void cmd_new_tag()
1503
size_t msglen;
1504
char *body;
1505
struct tag *t;
1506
+ unsigned long from_mark = 0;
1507
unsigned char sha1[20];
1508
1509
/* Obtain the new tag name from the rest of our command */
@@ -1528,10 +1542,10 @@ static void cmd_new_tag()
1542
if (s) {
1543
memcpy(sha1, s->sha1, 20);
1544
} else if (*from == ':') {
1531
- unsigned long idnum = strtoul(from + 1, NULL, 10);
1532
- struct object_entry *oe = find_mark(idnum);
1545
+ from_mark = strtoul(from + 1, NULL, 10);
1546
+ struct object_entry *oe = find_mark(from_mark);
1547
if (oe->type != OBJ_COMMIT)
1534
- die("Mark :%lu not a commit", idnum);
1548
+ die("Mark :%lu not a commit", from_mark);
1549
memcpy(sha1, oe->sha1, 20);
1550
} else if (!get_sha1(from, sha1)) {
1551
unsigned long size;
@@ -1572,10 +1586,22 @@ static void cmd_new_tag()
1586
1587
store_object(OBJ_TAG, body, sp - body, NULL, t->sha1, 0);
1588
free(body);
1589
+
1590
+ if (branch_log) {
1591
+ int need_dq = quote_c_style(t->name, NULL, NULL, 0);
1592
+ fprintf(branch_log, "tag ");
1593
+ if (need_dq) {
1594
+ fputc('"', branch_log);
1595
+ quote_c_style(t->name, NULL, branch_log, 0);
1596
+ fputc('"', branch_log);
1597
+ } else
1598
+ fprintf(branch_log, "%s", t->name);
1599
+ fprintf(branch_log," :%lu %s\n",from_mark,sha1_to_hex(t->sha1));
1600
+ }
1601
}
1602
1603
static const char fast_import_usage[] =
1578
-"git-fast-import [--objects=n] [--depth=n] [--active-branches=n] [--export-marks=marks.file] temp.pack";
1604
+"git-fast-import [--objects=n] [--depth=n] [--active-branches=n] [--export-marks=marks.file] [--branch-log=log] temp.pack";
1605
1606
int main(int argc, const char **argv)
1607
{
@@ -1602,6 +1628,11 @@ int main(int argc, const char **argv)
1628
max_active_branches = strtoul(a + 18, NULL, 0);
1629
else if (!strncmp(a, "--export-marks=", 15))
1630
mark_file = a + 15;
1631
+ else if (!strncmp(a, "--branch-log=", 13)) {
1632
+ branch_log = fopen(a + 13, "w");
1633
+ if (!branch_log)
1634
+ die("Can't create %s: %s", a + 13, strerror(errno));
1635
+ }
1636
else
1637
die("unknown option %s", a);
1638
}
@@ -1647,6 +1678,7 @@ int main(int argc, const char **argv)
1678
dump_branches();
1679
dump_tags();
1680
dump_marks();
1681
+ fclose(branch_log);
1682
1683
fprintf(stderr, "%s statistics:\n", argv[0]);
1684
fprintf(stderr, "---------------------------------------------------\n");