@@ -550,6 +550,21 @@ static const char *anonymize_refname(const char *refname)
return anon.buf;
}
+static const char *anonymize_tagname(size_t tagname_len, const char *tagname)
+{
+ /*
+ * Use anonymize_refname internally, so that the anonymization
+ * is consistent between a tag's refname and its internal
+ * tagname (if they were consistent to begin with, anyway).
+ */
+ static struct strbuf as_refname = STRBUF_INIT;
+
+ strbuf_reset(&as_refname);
+ strbuf_addf(&as_refname, "refs/tags/%.*s", (int)tagname_len, tagname);
+
+ return anonymize_refname(as_refname.buf) + strlen("refs/tags/");
+}
+
/*
* We do not even bother to cache commit messages, as they are unlikely
* to be repeated verbatim, and it is not that interesting when they are.
@@ -775,6 +790,7 @@ static void handle_tag(const char *refname, struct tag *tag)
const char *message;
size_t message_size = 0;
const char *tagname;
+ size_t tagname_len;
const char *tagger, *tagger_end;
struct object *tagged;
int tagged_mark;
@@ -804,6 +820,12 @@ static void handle_tag(const char *refname, struct tag *tag)
message_size = strlen(message);
}
+ tagname = memmem(buf, message ? message - buf : size, "\ntag ", 5);
+ if (!tagname)
+ die("malformed tag %s", oid_to_hex(&tag->object.oid));
+ tagname += 5;
+ tagname_len = (size_t)(strchrnul(tagname, '\n') - tagname);
+
tagger = memmem(buf, message ? message - buf : size, "\ntagger ", 8);
if (!tagger) {
if (fake_missing_tagger)
@@ -821,6 +843,8 @@ static void handle_tag(const char *refname, struct tag *tag)
if (anonymize) {
refname = anonymize_refname(refname);
+ tagname = anonymize_tagname(tagname_len, tagname);
+ tagname_len = strlen(tagname);
if (message) {
static struct hashmap tags;
message = anonymize_str(&tags, anonymize_tag,
@@ -890,9 +914,7 @@ static void handle_tag(const char *refname, struct tag *tag)
printf("reset %s\nfrom %s\n\n",
refname, oid_to_hex(&null_oid));
}
- tagname = refname;
- skip_prefix(tagname, "refs/tags/", &tagname);
- printf("tag %s\n", tagname);
+ printf("tag %.*s\n", (int)tagname_len, tagname);
if (mark_tags) {
mark_next_object(&tag->object);
printf("mark :%"PRIu32"\n", last_idnum);
@@ -572,10 +572,17 @@ test_expect_success 'handling tags of blobs' '
test_expect_success 'handling nested tags' '
git tag -a -m "This is a nested tag" nested muss &&
+ NESTED=$(git rev-parse --verify nested) &&
git fast-export --mark-tags nested >output &&
grep "^from $ZERO_OID$" output &&
grep "^tag nested$" output >tag_lines &&
- test_line_count = 2 tag_lines
+ test_line_count = 1 tag_lines &&
+ rm -rf new &&
+ mkdir new &&
+ git --git-dir=new/.git init &&
+ (cd new &&
+ git fast-import &&
+ test $NESTED = $(git rev-parse --verify refs/tags/nested)) <output
'
test_expect_success 'directory becomes symlink' '