@matheusbsbs / matheus-bagliano / commits / b715cfbba4
Fork 0

Accept 'inline' file data in fast-import commit structure.

Its very annoying to need to specify the file content ahead of a commit and use marks to connect the individual blobs to the commit's file modification entry, especially if the frontend can't/won't generate the blob SHA1s itself. Instead it would much easier to use if we can accept the blob data at the same time as we receive each file_change line. Now fast-import accepts 'inline' instead of a mark idnum or blob SHA1 within the 'M' type file_change command. If an inline is detected the very next line must be a 'data n' command, supplying the file data. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Jan 18, 2007 at 15:17 UTC b715cfbba4083d25ec0d0f94e440ad734607ddb0
2 files changed +82 -6
fast-import.c
+23 -6
@@ -25,10 +25,11 @@ Format of STDIN stream:
25 lf;
26 commit_msg ::= data;
27
28 - file_change ::= 'M' sp mode sp (hexsha1 | idnum) sp path_str lf
29 - | 'D' sp path_str lf
30 - ;
31 - mode ::= '644' | '755';
28 + file_change ::= file_del | file_obm | file_inm;
29 + file_del ::= 'D' sp path_str lf;
30 + file_obm ::= 'M' sp mode sp (hexsha1 | idnum) sp path_str lf;
31 + file_inm ::= 'M' sp mode sp 'inline' sp path_str lf
32 + data;
33
34 new_tag ::= 'tag' sp tag_str lf
35 'from' sp (ref_str | hexsha1 | sha1exp_str | idnum) lf
@@ -77,6 +78,10 @@ Format of STDIN stream:
78 sha1exp_str ::= sha1exp | '"' quoted(sha1exp) '"' ;
79 tag_str ::= tag | '"' quoted(tag) '"' ;
80 path_str ::= path | '"' quoted(path) '"' ;
81 + mode ::= '100644' | '644'
82 + | '100755' | '755'
83 + | '140000'
84 + ;
85
86 declen ::= # unsigned 32 bit value, ascii base10 notation;
87 bigint ::= # unsigned integer value, ascii base10 notation;
@@ -1452,7 +1457,7 @@ static void file_change_m(struct branch *b)
1457 const char *endp;
1458 struct object_entry *oe;
1459 unsigned char sha1[20];
1455 - unsigned int mode;
1460 + unsigned int mode, inline_data = 0;
1461 char type[20];
1462
1463 p = get_mode(p, &mode);
@@ -1475,6 +1480,9 @@ static void file_change_m(struct branch *b)
1480 oe = find_mark(strtoumax(p + 1, &x, 10));
1481 hashcpy(sha1, oe->sha1);
1482 p = x;
1483 + } else if (!strncmp("inline", p, 6)) {
1484 + inline_data = 1;
1485 + p += 6;
1486 } else {
1487 if (get_sha1_hex(p, sha1))
1488 die("Invalid SHA1: %s", command_buf.buf);
@@ -1491,7 +1499,16 @@ static void file_change_m(struct branch *b)
1499 p = p_uq;
1500 }
1501
1494 - if (oe) {
1502 + if (inline_data) {
1503 + size_t l;
1504 + void *d;
1505 + if (!p_uq)
1506 + p = p_uq = xstrdup(p);
1507 + read_next_command();
1508 + d = cmd_data(&l);
1509 + if (store_object(OBJ_BLOB, d, l, &last_blob, sha1, 0))
1510 + free(d);
1511 + } else if (oe) {
1512 if (oe->type != OBJ_BLOB)
1513 die("Not a blob (actually a %s): %s",
1514 command_buf.buf, type_names[oe->type]);
t/t9300-fast-import.sh
+59
@@ -17,6 +17,12 @@ in 3rd file
17 file4_data=abcd
18 file4_len=4
19
20 +file5_data='an inline file.
21 + we should see it later.'
22 +
23 +file6_data='#!/bin/sh
24 +echo "$@"'
25 +
26 ###
27 ### series A
28 ###
@@ -181,4 +187,57 @@ test_expect_success \
187 'C: validate rename result' \
188 'compare_diff_raw expect actual'
189
190 +###
191 +### series D
192 +###
193 +
194 +test_tick
195 +cat >input <<INPUT_END
196 +commit refs/heads/branch
197 +committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
198 +data <<COMMIT
199 +third
200 +COMMIT
201 +
202 +from refs/heads/branch^0
203 +M 644 inline newdir/interesting
204 +data <<EOF
205 +$file5_data
206 +EOF
207 +
208 +M 755 inline newdir/exec.sh
209 +data <<EOF
210 +$file6_data
211 +EOF
212 +
213 +INPUT_END
214 +test_expect_success \
215 + 'D: inline data in commit' \
216 + 'git-fast-import <input &&
217 + git-whatchanged branch'
218 +test_expect_success \
219 + 'D: verify pack' \
220 + 'for p in .git/objects/pack/*.pack;do git-verify-pack $p||exit;done'
221 +
222 +cat >expect <<EOF
223 +:000000 100755 0000000000000000000000000000000000000000 35a59026a33beac1569b1c7f66f3090ce9c09afc A newdir/exec.sh
224 +:000000 100644 0000000000000000000000000000000000000000 046d0371e9220107917db0d0e030628de8a1de9b A newdir/interesting
225 +EOF
226 +git-diff-tree -M -r branch^ branch >actual
227 +test_expect_success \
228 + 'D: validate new files added' \
229 + 'compare_diff_raw expect actual'
230 +
231 +echo "$file5_data" >expect
232 +test_expect_success \
233 + 'D: verify file5' \
234 + 'git-cat-file blob branch:newdir/interesting >actual &&
235 + diff -u expect actual'
236 +
237 +echo "$file6_data" >expect
238 +test_expect_success \
239 + 'D: verify file6' \
240 + 'git-cat-file blob branch:newdir/exec.sh >actual &&
241 + diff -u expect actual'
242 +
243 test_done