5 static void format_subst(const struct commit *commit,
6 const char *src, size_t len,
13 to_free = strbuf_detach(buf, NULL);
18 b = memmem(src, len, "$Format:", 8);
19 if (!b || src + len < b + 9)
21 c = memchr(b + 8, '$', len - 8);
26 strbuf_add(&fmt, b + 8, c - b - 8);
28 strbuf_add(buf, src, b - src);
29 format_commit_message(commit, fmt.buf, buf);
33 strbuf_add(buf, src, len);
38 static int convert_to_archive(const char *path,
39 const void *src, size_t len,
41 const struct commit *commit)
43 static struct git_attr *attr_export_subst;
44 struct git_attr_check check[1];
49 if (!attr_export_subst)
50 attr_export_subst = git_attr("export-subst", 12);
52 check[0].attr = attr_export_subst;
53 if (git_checkattr(path, ARRAY_SIZE(check), check))
55 if (!ATTR_TRUE(check[0].value))
58 format_subst(commit, src, len, buf);
62 void *sha1_file_to_archive(const char *path, const unsigned char *sha1,
63 unsigned int mode, enum object_type *type,
65 const struct commit *commit)
69 buffer = read_sha1_file(sha1, type, sizep);
70 if (buffer && S_ISREG(mode)) {
75 strbuf_attach(&buf, buffer, *sizep, *sizep + 1);
76 convert_to_working_tree(path, buf.buf, buf.len, &buf);
77 convert_to_archive(path, buf.buf, buf.len, &buf, commit);
78 buffer = strbuf_detach(&buf, &size);