Skip to content

Commit 015ff4f

Browse files
bk2204gitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent eedc994 commit 015ff4f

File tree

4 files changed

+29
-29
lines changed

4 files changed

+29
-29
lines changed

Diff for: archive-tar.c

+14-14
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,17 @@ static void write_trailer(void)
111111
* queues up writes, so that all our write(2) calls write exactly one
112112
* full block; pads writes to RECORDSIZE
113113
*/
114-
static int stream_blocked(const unsigned char *sha1)
114+
static int stream_blocked(const struct object_id *oid)
115115
{
116116
struct git_istream *st;
117117
enum object_type type;
118118
unsigned long sz;
119119
char buf[BLOCKSIZE];
120120
ssize_t readlen;
121121

122-
st = open_istream(sha1, &type, &sz, NULL);
122+
st = open_istream(oid->hash, &type, &sz, NULL);
123123
if (!st)
124-
return error("cannot stream blob %s", sha1_to_hex(sha1));
124+
return error("cannot stream blob %s", oid_to_hex(oid));
125125
for (;;) {
126126
readlen = read_istream(st, buf, sizeof(buf));
127127
if (readlen <= 0)
@@ -218,22 +218,22 @@ static void prepare_header(struct archiver_args *args,
218218
}
219219

220220
static void write_extended_header(struct archiver_args *args,
221-
const unsigned char *sha1,
221+
const struct object_id *oid,
222222
const void *buffer, unsigned long size)
223223
{
224224
struct ustar_header header;
225225
unsigned int mode;
226226
memset(&header, 0, sizeof(header));
227227
*header.typeflag = TYPEFLAG_EXT_HEADER;
228228
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));
230230
prepare_header(args, &header, mode, size);
231231
write_blocked(&header, sizeof(header));
232232
write_blocked(buffer, size);
233233
}
234234

235235
static int write_tar_entry(struct archiver_args *args,
236-
const unsigned char *sha1,
236+
const struct object_id *oid,
237237
const char *path, size_t pathlen,
238238
unsigned int mode)
239239
{
@@ -257,7 +257,7 @@ static int write_tar_entry(struct archiver_args *args,
257257
mode = (mode | ((mode & 0100) ? 0777 : 0666)) & ~tar_umask;
258258
} else {
259259
return error("unsupported file mode: 0%o (SHA1: %s)",
260-
mode, sha1_to_hex(sha1));
260+
mode, oid_to_hex(oid));
261261
}
262262
if (pathlen > sizeof(header.name)) {
263263
size_t plen = get_path_prefix(path, pathlen,
@@ -268,22 +268,22 @@ static int write_tar_entry(struct archiver_args *args,
268268
memcpy(header.name, path + plen + 1, rest);
269269
} else {
270270
xsnprintf(header.name, sizeof(header.name), "%s.data",
271-
sha1_to_hex(sha1));
271+
oid_to_hex(oid));
272272
strbuf_append_ext_header(&ext_header, "path",
273273
path, pathlen);
274274
}
275275
} else
276276
memcpy(header.name, path, pathlen);
277277

278278
if (S_ISREG(mode) && !args->convert &&
279-
sha1_object_info(sha1, &size) == OBJ_BLOB &&
279+
sha1_object_info(oid->hash, &size) == OBJ_BLOB &&
280280
size > big_file_threshold)
281281
buffer = NULL;
282282
else if (S_ISLNK(mode) || S_ISREG(mode)) {
283283
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);
285285
if (!buffer)
286-
return error("cannot read %s", sha1_to_hex(sha1));
286+
return error("cannot read %s", oid_to_hex(oid));
287287
} else {
288288
buffer = NULL;
289289
size = 0;
@@ -292,7 +292,7 @@ static int write_tar_entry(struct archiver_args *args,
292292
if (S_ISLNK(mode)) {
293293
if (size > sizeof(header.linkname)) {
294294
xsnprintf(header.linkname, sizeof(header.linkname),
295-
"see %s.paxheader", sha1_to_hex(sha1));
295+
"see %s.paxheader", oid_to_hex(oid));
296296
strbuf_append_ext_header(&ext_header, "linkpath",
297297
buffer, size);
298298
} else
@@ -308,7 +308,7 @@ static int write_tar_entry(struct archiver_args *args,
308308
prepare_header(args, &header, mode, size_in_header);
309309

310310
if (ext_header.len > 0) {
311-
write_extended_header(args, sha1, ext_header.buf,
311+
write_extended_header(args, oid, ext_header.buf,
312312
ext_header.len);
313313
}
314314
strbuf_release(&ext_header);
@@ -317,7 +317,7 @@ static int write_tar_entry(struct archiver_args *args,
317317
if (buffer)
318318
write_blocked(buffer, size);
319319
else
320-
err = stream_blocked(sha1);
320+
err = stream_blocked(oid);
321321
}
322322
free(buffer);
323323
return err;

Diff for: archive-zip.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ static int entry_is_binary(const char *path, const void *buffer, size_t size)
276276
#define STREAM_BUFFER_SIZE (1024 * 16)
277277

278278
static int write_zip_entry(struct archiver_args *args,
279-
const unsigned char *sha1,
279+
const struct object_id *oid,
280280
const char *path, size_t pathlen,
281281
unsigned int mode)
282282
{
@@ -314,7 +314,7 @@ static int write_zip_entry(struct archiver_args *args,
314314

315315
if (pathlen > 0xffff) {
316316
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);
318318
}
319319

320320
if (S_ISDIR(mode) || S_ISGITLINK(mode)) {
@@ -325,7 +325,7 @@ static int write_zip_entry(struct archiver_args *args,
325325
compressed_size = 0;
326326
buffer = NULL;
327327
} 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);
329329

330330
method = 0;
331331
attr2 = S_ISLNK(mode) ? ((mode | 0777) << 16) :
@@ -337,18 +337,18 @@ static int write_zip_entry(struct archiver_args *args,
337337

338338
if (S_ISREG(mode) && type == OBJ_BLOB && !args->convert &&
339339
size > big_file_threshold) {
340-
stream = open_istream(sha1, &type, &size, NULL);
340+
stream = open_istream(oid->hash, &type, &size, NULL);
341341
if (!stream)
342342
return error("cannot stream blob %s",
343-
sha1_to_hex(sha1));
343+
oid_to_hex(oid));
344344
flags |= ZIP_STREAM;
345345
out = buffer = NULL;
346346
} else {
347-
buffer = sha1_file_to_archive(args, path, sha1, mode,
347+
buffer = sha1_file_to_archive(args, path, oid->hash, mode,
348348
&type, &size);
349349
if (!buffer)
350350
return error("cannot read %s",
351-
sha1_to_hex(sha1));
351+
oid_to_hex(oid));
352352
crc = crc32(crc, buffer, size);
353353
is_binary = entry_is_binary(path_without_prefix,
354354
buffer, size);
@@ -357,7 +357,7 @@ static int write_zip_entry(struct archiver_args *args,
357357
compressed_size = (method == 0) ? size : 0;
358358
} else {
359359
return error("unsupported file mode: 0%o (SHA1: %s)", mode,
360-
sha1_to_hex(sha1));
360+
oid_to_hex(oid));
361361
}
362362

363363
if (creator_version > max_creator_version)

Diff for: archive.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ static int check_attr_export_subst(const struct attr_check *check)
121121
return check && ATTR_TRUE(check->items[1].value);
122122
}
123123

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,
125125
int baselen, const char *filename, unsigned mode, int stage,
126126
void *context)
127127
{
@@ -153,15 +153,15 @@ static int write_archive_entry(const unsigned char *sha1, const char *base,
153153
if (S_ISDIR(mode) || S_ISGITLINK(mode)) {
154154
if (args->verbose)
155155
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);
157157
if (err)
158158
return err;
159159
return (S_ISDIR(mode) ? READ_TREE_RECURSIVE : 0);
160160
}
161161

162162
if (args->verbose)
163163
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);
165165
}
166166

167167
static void queue_directory(const unsigned char *sha1,
@@ -191,7 +191,7 @@ static int write_directory(struct archiver_context *c)
191191
d->path[d->len - 1] = '\0'; /* no trailing slash */
192192
ret =
193193
write_directory(c) ||
194-
write_archive_entry(d->oid.hash, d->path, d->baselen,
194+
write_archive_entry(&d->oid, d->path, d->baselen,
195195
d->path + d->baselen, d->mode,
196196
d->stage, c) != READ_TREE_RECURSIVE;
197197
free(d);
@@ -231,7 +231,7 @@ static int queue_or_write_archive_entry(const struct object_id *oid,
231231

232232
if (write_directory(c))
233233
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,
235235
stage, context);
236236
}
237237

@@ -250,7 +250,7 @@ int write_archive_entries(struct archiver_args *args,
250250
len--;
251251
if (args->verbose)
252252
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,
254254
len, 040777);
255255
if (err)
256256
return err;

Diff for: archive.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ extern void init_tar_archiver(void);
3131
extern void init_zip_archiver(void);
3232

3333
typedef int (*write_archive_entry_fn_t)(struct archiver_args *args,
34-
const unsigned char *sha1,
34+
const struct object_id *oid,
3535
const char *path, size_t pathlen,
3636
unsigned int mode);
3737

0 commit comments

Comments
 (0)