MCPcopy Index your code
hub / github.com/git/git / write_archive_entry

Function write_archive_entry

archive.c:151–228  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

149}
150
151static int write_archive_entry(const struct object_id *oid, const char *base,
152 int baselen, const char *filename, unsigned mode,
153 void *context)
154{
155 static struct strbuf path = STRBUF_INIT;
156 struct archiver_context *c = context;
157 struct archiver_args *args = c->args;
158 write_archive_entry_fn_t write_entry = c->write_entry;
159 int err;
160 const char *path_without_prefix;
161 size_t size;
162 void *buffer;
163 enum object_type type;
164
165 args->convert = 0;
166 strbuf_reset(&path);
167 strbuf_grow(&path, PATH_MAX);
168 strbuf_add(&path, args->base, args->baselen);
169 strbuf_add(&path, base, baselen);
170 strbuf_addstr(&path, filename);
171 if (S_ISDIR(mode) || S_ISGITLINK(mode))
172 strbuf_addch(&path, '/');
173 path_without_prefix = path.buf + args->baselen;
174
175 if (!S_ISDIR(mode)) {
176 const struct attr_check *check;
177 check = get_archive_attrs(args->repo->index, path_without_prefix);
178 if (check_attr_export_ignore(check))
179 return 0;
180 args->convert = check_attr_export_subst(check);
181 }
182
183 if (args->prefix) {
184 static struct strbuf new_path = STRBUF_INIT;
185 static struct strbuf buf = STRBUF_INIT;
186 const char *rel;
187
188 rel = relative_path(path_without_prefix, args->prefix, &buf);
189
190 /*
191 * We don't add an entry for the current working
192 * directory when we are at the root; skip it also when
193 * we're in a subdirectory or submodule. Skip entries
194 * higher up as well.
195 */
196 if (!strcmp(rel, "./") || starts_with(rel, "../"))
197 return S_ISDIR(mode) ? READ_TREE_RECURSIVE : 0;
198
199 /* rel can refer to path, so don't edit it in place */
200 strbuf_reset(&new_path);
201 strbuf_add(&new_path, args->base, args->baselen);
202 strbuf_addstr(&new_path, rel);
203 strbuf_swap(&path, &new_path);
204 }
205
206 if (args->verbose)
207 fprintf(stderr, "%.*s\n", (int)path.len, path.buf);
208

Callers 2

write_directoryFunction · 0.85

Calls 15

strbuf_growFunction · 0.85
strbuf_addFunction · 0.85
strbuf_addstrFunction · 0.85
strbuf_addchFunction · 0.85
get_archive_attrsFunction · 0.85
check_attr_export_ignoreFunction · 0.85
check_attr_export_substFunction · 0.85
relative_pathFunction · 0.85
starts_withFunction · 0.85
strbuf_swapFunction · 0.85
write_entryFunction · 0.85
odb_read_object_infoFunction · 0.85

Tested by

no test coverage detected