Skip to content

Commit 0dc691a

Browse files
committed
Merge branch 'di/fast-import-tagging'
* di/fast-import-tagging: fast-import: allow to tag newly created objects fast-import: add tests for tagging blobs
2 parents 05d88e6 + 6c447f6 commit 0dc691a

File tree

2 files changed

+74
-7
lines changed

2 files changed

+74
-7
lines changed

fast-import.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2726,13 +2726,13 @@ static void parse_new_tag(void)
27262726
type = oe->type;
27272727
hashcpy(sha1, oe->idx.sha1);
27282728
} else if (!get_sha1(from, sha1)) {
2729-
unsigned long size;
2730-
char *buf;
2731-
2732-
buf = read_sha1_file(sha1, &type, &size);
2733-
if (!buf || size < 46)
2734-
die("Not a valid commit: %s", from);
2735-
free(buf);
2729+
struct object_entry *oe = find_object(sha1);
2730+
if (!oe) {
2731+
type = sha1_object_info(sha1, NULL);
2732+
if (type < 0)
2733+
die("Not a valid object: %s", from);
2734+
} else
2735+
type = oe->type;
27362736
} else
27372737
die("Invalid ref name or SHA1 expression: %s", from);
27382738
read_next_command();

t/t9300-fast-import.sh

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ data <<EOF
9494
An annotated tag without a tagger
9595
EOF
9696
97+
tag series-A-blob
98+
from :3
99+
data <<EOF
100+
An annotated tag that annotates a blob.
101+
EOF
102+
97103
INPUT_END
98104
test_expect_success \
99105
'A: create pack from stdin' \
@@ -151,6 +157,18 @@ test_expect_success 'A: verify tag/series-A' '
151157
test_cmp expect actual
152158
'
153159

160+
cat >expect <<EOF
161+
object $(git rev-parse refs/heads/master:file3)
162+
type blob
163+
tag series-A-blob
164+
165+
An annotated tag that annotates a blob.
166+
EOF
167+
test_expect_success 'A: verify tag/series-A-blob' '
168+
git cat-file tag tags/series-A-blob >actual &&
169+
test_cmp expect actual
170+
'
171+
154172
cat >expect <<EOF
155173
:2 `git rev-parse --verify master:file2`
156174
:3 `git rev-parse --verify master:file3`
@@ -169,6 +187,55 @@ test_expect_success \
169187
</dev/null &&
170188
test_cmp expect marks.new'
171189

190+
test_tick
191+
new_blob=$(echo testing | git hash-object --stdin)
192+
cat >input <<INPUT_END
193+
tag series-A-blob-2
194+
from $(git rev-parse refs/heads/master:file3)
195+
data <<EOF
196+
Tag blob by sha1.
197+
EOF
198+
199+
blob
200+
mark :6
201+
data <<EOF
202+
testing
203+
EOF
204+
205+
commit refs/heads/new_blob
206+
committer <> 0 +0000
207+
data 0
208+
M 644 :6 new_blob
209+
#pretend we got sha1 from fast-import
210+
ls "new_blob"
211+
212+
tag series-A-blob-3
213+
from $new_blob
214+
data <<EOF
215+
Tag new_blob.
216+
EOF
217+
INPUT_END
218+
219+
cat >expect <<EOF
220+
object $(git rev-parse refs/heads/master:file3)
221+
type blob
222+
tag series-A-blob-2
223+
224+
Tag blob by sha1.
225+
object $new_blob
226+
type blob
227+
tag series-A-blob-3
228+
229+
Tag new_blob.
230+
EOF
231+
232+
test_expect_success \
233+
'A: tag blob by sha1' \
234+
'git fast-import <input &&
235+
git cat-file tag tags/series-A-blob-2 >actual &&
236+
git cat-file tag tags/series-A-blob-3 >>actual &&
237+
test_cmp expect actual'
238+
172239
test_tick
173240
cat >input <<INPUT_END
174241
commit refs/heads/verify--import-marks

0 commit comments

Comments
 (0)