archive: convert write_archive_entry_fn_t to object_id

Convert the write_archive_entry_fn_t type to use a pointer to struct object_id. Convert various static functions in the tar and zip archivers also. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed Mar 12, 2018 at 02:27 UTC 015ff4f8225841d791c9940d71ebbce82c978a3c
4 files changed +29 -29
archive-tar.c
+14 -14
@@ -111,7 +111,7 @@ static void write_trailer(void)
111 * queues up writes, so that all our write(2) calls write exactly one
112 * full block; pads writes to RECORDSIZE
113 */
114 -static int stream_blocked(const unsigned char *sha1)
114 +static int stream_blocked(const struct object_id *oid)
115 {
116 struct git_istream *st;
117 enum object_type type;
@@ -119,9 +119,9 @@ static int stream_blocked(const unsigned char *sha1)
119 char buf[BLOCKSIZE];
120 ssize_t readlen;
121
122 - st = open_istream(sha1, &type, &sz, NULL);
122 + st = open_istream(oid->hash, &type, &sz, NULL);
123 if (!st)
124 - return error("cannot stream blob %s", sha1_to_hex(sha1));
124 + return error("cannot stream blob %s", oid_to_hex(oid));
125 for (;;) {
126 readlen = read_istream(st, buf, sizeof(buf));
127 if (readlen <= 0)
@@ -218,7 +218,7 @@ static void prepare_header(struct archiver_args *args,
218 }
219
220 static void write_extended_header(struct archiver_args *args,
221 - const unsigned char *sha1,
221 + const struct object_id *oid,
222 const void *buffer, unsigned long size)
223 {
224 struct ustar_header header;
@@ -226,14 +226,14 @@ static void write_extended_header(struct archiver_args *args,
226 memset(&header, 0, sizeof(header));
227 *header.typeflag = TYPEFLAG_EXT_HEADER;
228 mode = 0100666;
229 - xsnprintf(header.name, sizeof(header.name), "%s.paxheader", sha1_to_hex(sha1));
229 + xsnprintf(header.name, sizeof(header.name), "%s.paxheader", oid_to_hex(oid));
230 prepare_header(args, &header, mode, size);
231 write_blocked(&header, sizeof(header));
232 write_blocked(buffer, size);
233 }
234
235 static int write_tar_entry(struct archiver_args *args,
236 - const unsigned char *sha1,
236 + const struct object_id *oid,
237 const char *path, size_t pathlen,
238 unsigned int mode)
239 {
@@ -257,7 +257,7 @@ static int write_tar_entry(struct archiver_args *args,
257 mode = (mode | ((mode & 0100) ? 0777 : 0666)) & ~tar_umask;
258 } else {
259 return error("unsupported file mode: 0%o (SHA1: %s)",
260 - mode, sha1_to_hex(sha1));
260 + mode, oid_to_hex(oid));
261 }
262 if (pathlen > sizeof(header.name)) {
263 size_t plen = get_path_prefix(path, pathlen,
@@ -268,7 +268,7 @@ static int write_tar_entry(struct archiver_args *args,
268 memcpy(header.name, path + plen + 1, rest);
269 } else {
270 xsnprintf(header.name, sizeof(header.name), "%s.data",
271 - sha1_to_hex(sha1));
271 + oid_to_hex(oid));
272 strbuf_append_ext_header(&ext_header, "path",
273 path, pathlen);
274 }
@@ -276,14 +276,14 @@ static int write_tar_entry(struct archiver_args *args,
276 memcpy(header.name, path, pathlen);
277
278 if (S_ISREG(mode) && !args->convert &&
279 - sha1_object_info(sha1, &size) == OBJ_BLOB &&
279 + sha1_object_info(oid->hash, &size) == OBJ_BLOB &&
280 size > big_file_threshold)
281 buffer = NULL;
282 else if (S_ISLNK(mode) || S_ISREG(mode)) {
283 enum object_type type;
284 - buffer = sha1_file_to_archive(args, path, sha1, old_mode, &type, &size);
284 + buffer = sha1_file_to_archive(args, path, oid->hash, old_mode, &type, &size);
285 if (!buffer)
286 - return error("cannot read %s", sha1_to_hex(sha1));
286 + return error("cannot read %s", oid_to_hex(oid));
287 } else {
288 buffer = NULL;
289 size = 0;
@@ -292,7 +292,7 @@ static int write_tar_entry(struct archiver_args *args,
292 if (S_ISLNK(mode)) {
293 if (size > sizeof(header.linkname)) {
294 xsnprintf(header.linkname, sizeof(header.linkname),
295 - "see %s.paxheader", sha1_to_hex(sha1));
295 + "see %s.paxheader", oid_to_hex(oid));
296 strbuf_append_ext_header(&ext_header, "linkpath",
297 buffer, size);
298 } else
@@ -308,7 +308,7 @@ static int write_tar_entry(struct archiver_args *args,
308 prepare_header(args, &header, mode, size_in_header);
309
310 if (ext_header.len > 0) {
311 - write_extended_header(args, sha1, ext_header.buf,
311 + write_extended_header(args, oid, ext_header.buf,
312 ext_header.len);
313 }
314 strbuf_release(&ext_header);
@@ -317,7 +317,7 @@ static int write_tar_entry(struct archiver_args *args,
317 if (buffer)
318 write_blocked(buffer, size);
319 else
320 - err = stream_blocked(sha1);
320 + err = stream_blocked(oid);
321 }
322 free(buffer);
323 return err;
archive-zip.c
+8 -8
@@ -276,7 +276,7 @@ static int entry_is_binary(const char *path, const void *buffer, size_t size)
276 #define STREAM_BUFFER_SIZE (1024 * 16)
277
278 static int write_zip_entry(struct archiver_args *args,
279 - const unsigned char *sha1,
279 + const struct object_id *oid,
280 const char *path, size_t pathlen,
281 unsigned int mode)
282 {
@@ -314,7 +314,7 @@ static int write_zip_entry(struct archiver_args *args,
314
315 if (pathlen > 0xffff) {
316 return error("path too long (%d chars, SHA1: %s): %s",
317 - (int)pathlen, sha1_to_hex(sha1), path);
317 + (int)pathlen, oid_to_hex(oid), path);
318 }
319
320 if (S_ISDIR(mode) || S_ISGITLINK(mode)) {
@@ -325,7 +325,7 @@ static int write_zip_entry(struct archiver_args *args,
325 compressed_size = 0;
326 buffer = NULL;
327 } else if (S_ISREG(mode) || S_ISLNK(mode)) {
328 - enum object_type type = sha1_object_info(sha1, &size);
328 + enum object_type type = sha1_object_info(oid->hash, &size);
329
330 method = 0;
331 attr2 = S_ISLNK(mode) ? ((mode | 0777) << 16) :
@@ -337,18 +337,18 @@ static int write_zip_entry(struct archiver_args *args,
337
338 if (S_ISREG(mode) && type == OBJ_BLOB && !args->convert &&
339 size > big_file_threshold) {
340 - stream = open_istream(sha1, &type, &size, NULL);
340 + stream = open_istream(oid->hash, &type, &size, NULL);
341 if (!stream)
342 return error("cannot stream blob %s",
343 - sha1_to_hex(sha1));
343 + oid_to_hex(oid));
344 flags |= ZIP_STREAM;
345 out = buffer = NULL;
346 } else {
347 - buffer = sha1_file_to_archive(args, path, sha1, mode,
347 + buffer = sha1_file_to_archive(args, path, oid->hash, mode,
348 &type, &size);
349 if (!buffer)
350 return error("cannot read %s",
351 - sha1_to_hex(sha1));
351 + oid_to_hex(oid));
352 crc = crc32(crc, buffer, size);
353 is_binary = entry_is_binary(path_without_prefix,
354 buffer, size);
@@ -357,7 +357,7 @@ static int write_zip_entry(struct archiver_args *args,
357 compressed_size = (method == 0) ? size : 0;
358 } else {
359 return error("unsupported file mode: 0%o (SHA1: %s)", mode,
360 - sha1_to_hex(sha1));
360 + oid_to_hex(oid));
361 }
362
363 if (creator_version > max_creator_version)
archive.c
+6 -6
@@ -121,7 +121,7 @@ static int check_attr_export_subst(const struct attr_check *check)
121 return check && ATTR_TRUE(check->items[1].value);
122 }
123
124 -static int write_archive_entry(const unsigned char *sha1, const char *base,
124 +static int write_archive_entry(const struct object_id *oid, const char *base,
125 int baselen, const char *filename, unsigned mode, int stage,
126 void *context)
127 {
@@ -153,7 +153,7 @@ static int write_archive_entry(const unsigned char *sha1, const char *base,
153 if (S_ISDIR(mode) || S_ISGITLINK(mode)) {
154 if (args->verbose)
155 fprintf(stderr, "%.*s\n", (int)path.len, path.buf);
156 - err = write_entry(args, sha1, path.buf, path.len, mode);
156 + err = write_entry(args, oid, path.buf, path.len, mode);
157 if (err)
158 return err;
159 return (S_ISDIR(mode) ? READ_TREE_RECURSIVE : 0);
@@ -161,7 +161,7 @@ static int write_archive_entry(const unsigned char *sha1, const char *base,
161
162 if (args->verbose)
163 fprintf(stderr, "%.*s\n", (int)path.len, path.buf);
164 - return write_entry(args, sha1, path.buf, path.len, mode);
164 + return write_entry(args, oid, path.buf, path.len, mode);
165 }
166
167 static void queue_directory(const unsigned char *sha1,
@@ -191,7 +191,7 @@ static int write_directory(struct archiver_context *c)
191 d->path[d->len - 1] = '\0'; /* no trailing slash */
192 ret =
193 write_directory(c) ||
194 - write_archive_entry(d->oid.hash, d->path, d->baselen,
194 + write_archive_entry(&d->oid, d->path, d->baselen,
195 d->path + d->baselen, d->mode,
196 d->stage, c) != READ_TREE_RECURSIVE;
197 free(d);
@@ -231,7 +231,7 @@ static int queue_or_write_archive_entry(const struct object_id *oid,
231
232 if (write_directory(c))
233 return -1;
234 - return write_archive_entry(oid->hash, base->buf, base->len, filename, mode,
234 + return write_archive_entry(oid, base->buf, base->len, filename, mode,
235 stage, context);
236 }
237
@@ -250,7 +250,7 @@ int write_archive_entries(struct archiver_args *args,
250 len--;
251 if (args->verbose)
252 fprintf(stderr, "%.*s\n", (int)len, args->base);
253 - err = write_entry(args, args->tree->object.oid.hash, args->base,
253 + err = write_entry(args, &args->tree->object.oid, args->base,
254 len, 040777);
255 if (err)
256 return err;
archive.h
+1 -1
@@ -31,7 +31,7 @@ extern void init_tar_archiver(void);
31 extern void init_zip_archiver(void);
32
33 typedef int (*write_archive_entry_fn_t)(struct archiver_args *args,
34 - const unsigned char *sha1,
34 + const struct object_id *oid,
35 const char *path, size_t pathlen,
36 unsigned int mode);
37