diff options
author | Shawn O. Pearce <spearce@spearce.org> | 2007-02-12 04:08:43 -0500 |
---|---|---|
committer | Shawn O. Pearce <spearce@spearce.org> | 2007-02-12 12:17:31 -0500 |
commit | ea5e370aa9203f999dd8bcd4a9cd29452f1c9181 (patch) | |
tree | 4123553e856c4ccb4d10518c43250a09f7476d50 /fast-import.c | |
parent | b4d2b04c9b6dc42c0bcf0513b9d8f731ec26db82 (diff) | |
download | git-ea5e370aa9203f999dd8bcd4a9cd29452f1c9181.tar.gz |
fast-import: Support reusing 'from' and brown paper bag fix reset.
It was suggested on the mailing list that being able to use `from`
in any commit to reset the current branch is useful in some types of
importers, such as a darcs importer.
We originally did not permit resetting an existing branch with a
new `from` command during a `commit` command, but this restriction
was only to help debug the hacked up cvs2svn that Jon Smirl was
developing in parallel with git-fast-import. It is probably more
of a problem to disallow it than to allow it. So now we permit a
`from` during any `commit`.
While making the changes required to permit multiple `from`
commands on the same branch, I discovered we no longer needed the
last_commit field to be set to 0 during a reset, so that was removed.
(Reset was originally setting the field to 0 to signal cmd_from()
that it was OK to execute on the branch.)
While poking around in this section of fast-import I also realized
the `reset` command was not working as intended if the corresponding
`from` command was omitted (as allowed by the BNF grammar and the
code). If `from` was omitted we cleared out the tree but we left
the tree SHA-1 and parent commit SHA-1 intact. This is not what
the user intended in this case. Instead they would be trying to
reset the branch to have no parent and to have no tree, making the
branch look new-born during the next commit. We now clear these
SHA-1 values during `reset`, ensuring the branch looks new-born if
`from` does not get supplied.
New test cases for these were also added.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'fast-import.c')
-rw-r--r-- | fast-import.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/fast-import.c b/fast-import.c index f9cfc72637..fd3b117574 100644 --- a/fast-import.c +++ b/fast-import.c @@ -1667,8 +1667,10 @@ static void cmd_from(struct branch *b) if (strncmp("from ", command_buf.buf, 5)) return; - if (b->last_commit) - die("Can't reinitailize branch %s", b->name); + if (b->branch_tree.tree) { + release_tree_content_recursive(b->branch_tree.tree); + b->branch_tree.tree = NULL; + } from = strchr(command_buf.buf, ' ') + 1; s = lookup_branch(from); @@ -1936,7 +1938,9 @@ static void cmd_reset_branch(void) sp = strchr(command_buf.buf, ' ') + 1; b = lookup_branch(sp); if (b) { - b->last_commit = 0; + hashclr(b->sha1); + hashclr(b->branch_tree.versions[0].sha1); + hashclr(b->branch_tree.versions[1].sha1); if (b->branch_tree.tree) { release_tree_content_recursive(b->branch_tree.tree); b->branch_tree.tree = NULL; |