@matheusbsbs / matheus-bagliano / commits / 5fced8dc6f
Fork 0

Added 'reset' command to clear a branch's tree.

Sometimes an import frontend may need to work with a temporary branch which will actually contain many different branches over the life of the import. This is especially useful when the frontend needs to create a tag from a set of file versions which are otherwise never a commit. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Aug 27, 2006 at 06:20 UTC 5fced8dc6f4844997b6e25a67a00f428775c5233
1 file changed +32
fast-import.c
+32
@@ -6,6 +6,7 @@ Format of STDIN stream:
6 cmd ::= new_blob
7 | new_commit
8 | new_tag
9 + | reset_branch
10 ;
11
12 new_blob ::= 'blob' lf
@@ -34,6 +35,8 @@ Format of STDIN stream:
35 tag_msg;
36 tag_msg ::= data;
37
38 + reset_branch ::= 'reset' sp ref_str lf;
39 +
40 # note: the first idnum in a stream should be 1 and subsequent
41 # idnums should not have gaps between values as this will cause
42 # the stream parser to reserve space for the gapped values. An
@@ -1604,6 +1607,33 @@ static void cmd_new_tag()
1607 }
1608 }
1609
1610 +static void cmd_reset_branch()
1611 +{
1612 + struct branch *b;
1613 + char *str_uq;
1614 + const char *endp;
1615 + char *sp;
1616 +
1617 + /* Obtain the branch name from the rest of our command */
1618 + sp = strchr(command_buf.buf, ' ') + 1;
1619 + str_uq = unquote_c_style(sp, &endp);
1620 + if (str_uq) {
1621 + if (*endp)
1622 + die("Garbage after ref in: %s", command_buf.buf);
1623 + sp = str_uq;
1624 + }
1625 + b = lookup_branch(sp);
1626 + if (b) {
1627 + b->last_commit = 0;
1628 + if (b->branch_tree.tree) {
1629 + release_tree_content_recursive(b->branch_tree.tree);
1630 + b->branch_tree.tree = NULL;
1631 + }
1632 + }
1633 + if (str_uq)
1634 + free(str_uq);
1635 +}
1636 +
1637 static const char fast_import_usage[] =
1638 "git-fast-import [--objects=n] [--depth=n] [--active-branches=n] [--export-marks=marks.file] [--branch-log=log] temp.pack";
1639
@@ -1673,6 +1703,8 @@ int main(int argc, const char **argv)
1703 cmd_new_commit();
1704 else if (!strncmp("tag ", command_buf.buf, 4))
1705 cmd_new_tag();
1706 + else if (!strncmp("reset ", command_buf.buf, 6))
1707 + cmd_reset_branch();
1708 else
1709 die("Unsupported command: %s", command_buf.buf);
1710 }