summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 85c6239)
raw | patch | inline | side by side (parent: 85c6239)
author | Jonathan Nieder <jrnieder@gmail.com> | |
Sun, 28 Nov 2010 19:45:58 +0000 (13:45 -0600) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Wed, 1 Dec 2010 21:28:04 +0000 (13:28 -0800) |
The new rule: a "cat-blob" can be inserted wherever a comment is
allowed, which means at the start of any line except in the middle of
a "data" command.
This saves frontends from having to loop over everything they want to
commit in the next commit and cat-ing the necessary objects in
advance.
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: David Barr <david.barr@cordelta.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
allowed, which means at the start of any line except in the middle of
a "data" command.
This saves frontends from having to loop over everything they want to
commit in the next commit and cat-ing the necessary objects in
advance.
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: David Barr <david.barr@cordelta.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-fast-import.txt | patch | blob | history | |
fast-import.c | patch | blob | history | |
t/t9300-fast-import.sh | patch | blob | history |
index 5d8f60c7909e0fe3dbbdf900cc885115bc932dc8..534b2519b32b1d008e289639d5b5df4539d42117 100644 (file)
<contents> LF
====
+This command can be used anywhere in the stream that comments are
+accepted. In particular, the `cat-blob` command can be used in the
+middle of a commit but not in the middle of a `data` command.
+
`feature`
~~~~~~~~~
Require that fast-import supports the specified feature, or abort if
diff --git a/fast-import.c b/fast-import.c
index dd58f517b9f0e30fcd232afffbdeca1831b1b1e2..f71ea3e7bc5e0fc110dec9f983f37bbfcef9855d 100644 (file)
--- a/fast-import.c
+++ b/fast-import.c
('from' sp committish lf)?
lf?;
- cat_blob ::= 'cat-blob' sp (hexsha1 | idnum) lf;
-
checkpoint ::= 'checkpoint' lf
lf?;
ts ::= # time since the epoch in seconds, ascii base10 notation;
tz ::= # GIT style timezone;
- # note: comments may appear anywhere in the input, except
- # within a data command. Any form of the data command
- # always escapes the related input from comment processing.
+ # note: comments and cat requests may appear anywhere
+ # in the input, except within a data command. Any form
+ # of the data command always escapes the related input
+ # from comment processing.
#
# In case it is not clear, the '#' that starts the comment
# must be the first character on that line (an lf
# preceded it).
#
+ cat_blob ::= 'cat-blob' sp (hexsha1 | idnum) lf;
+
comment ::= '#' not_lf* lf;
not_lf ::= # Any byte that is not ASCII newline (LF);
*/
static int cat_blob_fd = STDOUT_FILENO;
static void parse_argv(void);
+static void parse_cat_blob(void);
static void write_branch_report(FILE *rpt, struct branch *b)
{
fclose(f);
}
-
static int read_next_command(void)
{
static int stdin_eof = 0;
return EOF;
}
- do {
+ for (;;) {
if (unread_command_buf) {
unread_command_buf = 0;
} else {
rc->prev->next = rc;
cmd_tail = rc;
}
- } while (command_buf.buf[0] == '#');
-
- return 0;
+ if (!prefixcmp(command_buf.buf, "cat-blob ")) {
+ parse_cat_blob();
+ continue;
+ }
+ if (command_buf.buf[0] == '#')
+ continue;
+ return 0;
+ }
}
static void skip_optional_lf(void)
parse_new_tag();
else if (!prefixcmp(command_buf.buf, "reset "))
parse_reset_branch();
- else if (!prefixcmp(command_buf.buf, "cat-blob "))
- parse_cat_blob();
else if (!strcmp("checkpoint", command_buf.buf))
parse_checkpoint();
else if (!prefixcmp(command_buf.buf, "progress "))
diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh
index a0162b73d9e63659f6ef9102daede32bce816f04..d615d04a32cd96cf2de5ccec3cd1a66dddca8620 100755 (executable)
--- a/t/t9300-fast-import.sh
+++ b/t/t9300-fast-import.sh
test_cmp big actual
'
+test_expect_success PIPE 'R: print blob mid-commit' '
+ rm -f blobs &&
+ echo "A blob from _before_ the commit." >expect &&
+ mkfifo blobs &&
+ (
+ exec 3<blobs &&
+ cat <<-EOF &&
+ feature cat-blob
+ blob
+ mark :1
+ data <<BLOB
+ A blob from _before_ the commit.
+ BLOB
+ commit refs/heads/temporary
+ committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+ data <<COMMIT
+ Empty commit
+ COMMIT
+ cat-blob :1
+ EOF
+
+ read blob_id type size <&3 &&
+ dd if=/dev/stdin of=actual bs=$size count=1 <&3 &&
+ read newline <&3 &&
+
+ echo
+ ) |
+ git fast-import --cat-blob-fd=3 3>blobs &&
+ test_cmp expect actual
+'
+
+test_expect_success PIPE 'R: print staged blob within commit' '
+ rm -f blobs &&
+ echo "A blob from _within_ the commit." >expect &&
+ mkfifo blobs &&
+ (
+ exec 3<blobs &&
+ cat <<-EOF &&
+ feature cat-blob
+ commit refs/heads/within
+ committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+ data <<COMMIT
+ Empty commit
+ COMMIT
+ M 644 inline within
+ data <<BLOB
+ A blob from _within_ the commit.
+ BLOB
+ EOF
+
+ to_get=$(
+ echo "A blob from _within_ the commit." |
+ git hash-object --stdin
+ ) &&
+ echo "cat-blob $to_get" &&
+
+ read blob_id type size <&3 &&
+ dd if=/dev/stdin of=actual bs=$size count=1 <&3 &&
+ read newline <&3 &&
+
+ echo deleteall
+ ) |
+ git fast-import --cat-blob-fd=3 3>blobs &&
+ test_cmp expect actual
+'
+
cat >input << EOF
option git quiet
blob