From 825769a8fe4d0529268fee7e763bc8f24ed4218e Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Wed, 7 Feb 2007 02:03:03 -0500 Subject: [PATCH] Teach fast-import how to clear the internal branch content. Some frontends may not be able to (easily) keep track of which files are included in the branch, and which aren't. Performing this tracking can be tedious and error prone for the frontend to do, especially if its foreign data source cannot supply the changed path list on a per-commit basis. fast-import now allows a frontend to request that a branch's tree be wiped clean (reset to the empty tree) at the start of a commit, allowing the frontend to feed in all paths which belong on the branch. This is ideal for a tar-file importer frontend, for example, as the frontend just needs to reformat the tar data stream into a gfi data stream, which may be something a few Perl regexps can take care of. :) Signed-off-by: Shawn O. Pearce --- Documentation/git-fast-import.txt | 36 +++++++++++++++++++--- fast-import.c | 13 +++++++- t/t9300-fast-import.sh | 51 +++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 6 deletions(-) diff --git a/Documentation/git-fast-import.txt b/Documentation/git-fast-import.txt index aeddd5e28..8bb5a0b36 100644 --- a/Documentation/git-fast-import.txt +++ b/Documentation/git-fast-import.txt @@ -269,7 +269,7 @@ change to the project. data ('from' SP LF)? ('merge' SP LF)? - (filemodify | filedelete)* + (filemodify | filedelete | filedeleteall)* LF .... @@ -292,10 +292,12 @@ commit message use a 0 length data. Commit messages are free-form and are not interpreted by Git. Currently they must be encoded in UTF-8, as gfi does not permit other encodings to be specified. -Zero or more `filemodify` and `filedelete` commands may be -included to update the contents of the branch prior to the commit. -These commands can be supplied in any order, gfi is not sensitive -to pathname or operation ordering. +Zero or more `filemodify`, `filedelete` and `filedeleteall` commands +may be included to update the contents of the branch prior to +creating the commit. These commands may be supplied in any order. +However it is recommended that a `filedeleteall` command preceed +all `filemodify` commands in the same commit, as `filedeleteall` +wipes the branch clean (see below). `author` ^^^^^^^^ @@ -459,6 +461,30 @@ first non-empty directory or the root is reached. here `` is the complete path of the file to be removed. See `filemodify` above for a detailed description of ``. +`filedeleteall` +^^^^^^^^^^^^^^^ +Included in a `commit` command to remove all files (and also all +directories) from the branch. This command resets the internal +branch structure to have no files in it, allowing the frontend +to subsequently add all interesting files from scratch. + +.... + 'deleteall' LF +.... + +This command is extremely useful if the frontend does not know +(or does not care to know) what files are currently on the branch, +and therefore cannot generate the proper `filedelete` commands to +update the content. + +Issuing a `filedeleteall` followed by the needed `filemodify` +commands to set the correct content will produce the same results +as sending only the needed `filemodify` and `filedelete` commands. +The `filedeleteall` approach may however require gfi to use slightly +more memory per active branch (less than 1 MiB for even most large +projects); so frontends that can easily obtain only the affected +paths for a commit are encouraged to do so. + `mark` ~~~~~~ Arranges for gfi to save a reference to the current object, allowing diff --git a/fast-import.c b/fast-import.c index c72c5c7a9..f80ddee2f 100644 --- a/fast-import.c +++ b/fast-import.c @@ -26,7 +26,8 @@ Format of STDIN stream: lf; commit_msg ::= data; - file_change ::= file_del | file_obm | file_inm; + file_change ::= file_clr | file_del | file_obm | file_inm; + file_clr ::= 'deleteall' lf; file_del ::= 'D' sp path_str lf; file_obm ::= 'M' sp mode sp (hexsha1 | idnum) sp path_str lf; file_inm ::= 'M' sp mode sp 'inline' sp path_str lf @@ -1640,6 +1641,14 @@ static void file_change_d(struct branch *b) free(p_uq); } +static void file_change_deleteall(struct branch *b) +{ + release_tree_content_recursive(b->branch_tree.tree); + hashclr(b->branch_tree.versions[0].sha1); + hashclr(b->branch_tree.versions[1].sha1); + load_tree(&b->branch_tree); +} + static void cmd_from(struct branch *b) { const char *from; @@ -1784,6 +1793,8 @@ static void cmd_new_commit(void) file_change_m(b); else if (!strncmp("D ", command_buf.buf, 2)) file_change_d(b); + else if (!strcmp("deleteall", command_buf.buf)) + file_change_deleteall(b); else die("Unsupported file_change: %s", command_buf.buf); read_next_command(); diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh index 23a2ba78f..357a8724d 100755 --- a/t/t9300-fast-import.sh +++ b/t/t9300-fast-import.sh @@ -356,4 +356,55 @@ test_expect_success \ 'test $old_branch != `git-rev-parse --verify branch^0` && test $old_branch = `git-rev-parse --verify branch@{1}`' +### +### series H +### + +test_tick +cat >input < $GIT_COMMITTER_DATE +data <expect <actual +test_expect_success \ + 'H: validate old files removed, new files added' \ + 'compare_diff_raw expect actual' + +echo "$file5_data" >expect +test_expect_success \ + 'H: verify file' \ + 'git-cat-file blob H:h/e/l/lo >actual && + diff -u expect actual' + test_done -- 2.45.2