fast-import: allow to tag newly created objects

fast-import allows to tag objects by sha1 and to query sha1 of objects being imported. So it should allow to tag these objects, make it do so. Signed-off-by: Dmitry Ivankov <divanorama@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Dmitry Ivankov committed Aug 22, 2011 at 18:10 UTC 6c447f633cedd6e2366151b0b82b1731f8c1ee1d
2 files changed +33 -3
fast-import.c
+7 -3
@@ -2688,9 +2688,13 @@ static void parse_new_tag(void)
2688 type = oe->type;
2689 hashcpy(sha1, oe->idx.sha1);
2690 } else if (!get_sha1(from, sha1)) {
2691 - type = sha1_object_info(sha1, NULL);
2692 - if (type < 0)
2693 - die("Not a valid object: %s", from);
2691 + struct object_entry *oe = find_object(sha1);
2692 + if (!oe) {
2693 + type = sha1_object_info(sha1, NULL);
2694 + if (type < 0)
2695 + die("Not a valid object: %s", from);
2696 + } else
2697 + type = oe->type;
2698 } else
2699 die("Invalid ref name or SHA1 expression: %s", from);
2700 read_next_command();
t/t9300-fast-import.sh
+26
@@ -188,12 +188,32 @@ test_expect_success \
188 test_cmp expect marks.new'
189
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
@@ -202,12 +222,18 @@ 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
239 test_tick