Skip to content

Commit a5bbc29

Browse files
committed
Merge branch 'bc/object-id'
Conversion from uchar[20] to struct object_id continues. * bc/object-id: (36 commits) convert: convert to struct object_id sha1_file: introduce a constant for max header length Convert lookup_replace_object to struct object_id sha1_file: convert read_sha1_file to struct object_id sha1_file: convert read_object_with_reference to object_id tree-walk: convert tree entry functions to object_id streaming: convert istream internals to struct object_id tree-walk: convert get_tree_entry_follow_symlinks internals to object_id builtin/notes: convert static functions to object_id builtin/fmt-merge-msg: convert remaining code to object_id sha1_file: convert sha1_object_info* to object_id Convert remaining callers of sha1_object_info_extended to object_id packfile: convert unpack_entry to struct object_id sha1_file: convert retry_bad_packed_offset to struct object_id sha1_file: convert assert_sha1_type to object_id builtin/mktree: convert to struct object_id streaming: convert open_istream to use struct object_id sha1_file: convert check_sha1_signature to struct object_id sha1_file: convert read_loose_object to use struct object_id builtin/index-pack: convert struct ref_delta_entry to object_id ...
2 parents 78c20b8 + 1a75044 commit a5bbc29

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+609
-594
lines changed

apply.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3180,7 +3180,7 @@ static int apply_binary(struct apply_state *state,
31803180
unsigned long size;
31813181
char *result;
31823182

3183-
result = read_sha1_file(oid.hash, &type, &size);
3183+
result = read_object_file(&oid, &type, &size);
31843184
if (!result)
31853185
return error(_("the necessary postimage %s for "
31863186
"'%s' cannot be read"),
@@ -3242,7 +3242,7 @@ static int read_blob_object(struct strbuf *buf, const struct object_id *oid, uns
32423242
unsigned long sz;
32433243
char *result;
32443244

3245-
result = read_sha1_file(oid->hash, &type, &sz);
3245+
result = read_object_file(oid, &type, &sz);
32463246
if (!result)
32473247
return -1;
32483248
/* XXX read_sha1_file NUL-terminates */

archive-tar.c

Lines changed: 14 additions & 14 deletions
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, &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+
oid_object_info(oid, &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 = object_file_to_archive(args, path, oid, 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;

archive-zip.c

Lines changed: 9 additions & 9 deletions
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 = oid_object_info(oid, &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, &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,
348-
&type, &size);
347+
buffer = object_file_to_archive(args, path, oid, mode,
348+
&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)

archive.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,16 @@ static void format_subst(const struct commit *commit,
6363
free(to_free);
6464
}
6565

66-
void *sha1_file_to_archive(const struct archiver_args *args,
67-
const char *path, const unsigned char *sha1,
68-
unsigned int mode, enum object_type *type,
69-
unsigned long *sizep)
66+
void *object_file_to_archive(const struct archiver_args *args,
67+
const char *path, const struct object_id *oid,
68+
unsigned int mode, enum object_type *type,
69+
unsigned long *sizep)
7070
{
7171
void *buffer;
7272
const struct commit *commit = args->convert ? args->commit : NULL;
7373

7474
path += args->baselen;
75-
buffer = read_sha1_file(sha1, type, sizep);
75+
buffer = read_object_file(oid, type, sizep);
7676
if (buffer && S_ISREG(mode)) {
7777
struct strbuf buf = STRBUF_INIT;
7878
size_t size = 0;
@@ -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,14 +191,14 @@ 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);
198198
return ret ? -1 : 0;
199199
}
200200

201-
static int queue_or_write_archive_entry(const unsigned char *sha1,
201+
static int queue_or_write_archive_entry(const struct object_id *oid,
202202
struct strbuf *base, const char *filename,
203203
unsigned mode, int stage, void *context)
204204
{
@@ -224,14 +224,14 @@ static int queue_or_write_archive_entry(const unsigned char *sha1,
224224

225225
if (check_attr_export_ignore(check))
226226
return 0;
227-
queue_directory(sha1, base, filename,
227+
queue_directory(oid->hash, base, filename,
228228
mode, stage, c);
229229
return READ_TREE_RECURSIVE;
230230
}
231231

232232
if (write_directory(c))
233233
return -1;
234-
return write_archive_entry(sha1, 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;
@@ -303,7 +303,7 @@ static const struct archiver *lookup_archiver(const char *name)
303303
return NULL;
304304
}
305305

306-
static int reject_entry(const unsigned char *sha1, struct strbuf *base,
306+
static int reject_entry(const struct object_id *oid, struct strbuf *base,
307307
const char *filename, unsigned mode,
308308
int stage, void *context)
309309
{
@@ -397,8 +397,8 @@ static void parse_treeish_arg(const char **argv,
397397
unsigned int mode;
398398
int err;
399399

400-
err = get_tree_entry(tree->object.oid.hash, prefix,
401-
tree_oid.hash, &mode);
400+
err = get_tree_entry(&tree->object.oid, prefix, &tree_oid,
401+
&mode);
402402
if (err || !S_ISDIR(mode))
403403
die("current working directory is untracked");
404404

archive.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@ 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

3838
extern int write_archive_entries(struct archiver_args *args, write_archive_entry_fn_t write_entry);
3939
extern int write_archive(int argc, const char **argv, const char *prefix, const char *name_hint, int remote);
4040

4141
const char *archive_format_from_filename(const char *filename);
42-
extern void *sha1_file_to_archive(const struct archiver_args *args,
43-
const char *path, const unsigned char *sha1,
44-
unsigned int mode, enum object_type *type,
45-
unsigned long *sizep);
42+
extern void *object_file_to_archive(const struct archiver_args *args,
43+
const char *path, const struct object_id *oid,
44+
unsigned int mode, enum object_type *type,
45+
unsigned long *sizep);
4646

4747
#endif /* ARCHIVE_H */

bisect.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ static void show_list(const char *debug, int counted, int nr,
132132
unsigned flags = commit->object.flags;
133133
enum object_type type;
134134
unsigned long size;
135-
char *buf = read_sha1_file(commit->object.oid.hash, &type, &size);
135+
char *buf = read_object_file(&commit->object.oid, &type,
136+
&size);
136137
const char *subject_start;
137138
int subject_len;
138139

blame.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ static void verify_working_tree_path(struct commit *work_tree, const char *path)
8080
struct object_id blob_oid;
8181
unsigned mode;
8282

83-
if (!get_tree_entry(commit_oid->hash, path, blob_oid.hash, &mode) &&
84-
sha1_object_info(blob_oid.hash, NULL) == OBJ_BLOB)
83+
if (!get_tree_entry(commit_oid, path, &blob_oid, &mode) &&
84+
oid_object_info(&blob_oid, NULL) == OBJ_BLOB)
8585
return;
8686
}
8787

@@ -297,8 +297,8 @@ static void fill_origin_blob(struct diff_options *opt,
297297
textconv_object(o->path, o->mode, &o->blob_oid, 1, &file->ptr, &file_size))
298298
;
299299
else
300-
file->ptr = read_sha1_file(o->blob_oid.hash, &type,
301-
&file_size);
300+
file->ptr = read_object_file(&o->blob_oid, &type,
301+
&file_size);
302302
file->size = file_size;
303303

304304
if (!file->ptr)
@@ -502,11 +502,9 @@ static int fill_blob_sha1_and_mode(struct blame_origin *origin)
502502
{
503503
if (!is_null_oid(&origin->blob_oid))
504504
return 0;
505-
if (get_tree_entry(origin->commit->object.oid.hash,
506-
origin->path,
507-
origin->blob_oid.hash, &origin->mode))
505+
if (get_tree_entry(&origin->commit->object.oid, origin->path, &origin->blob_oid, &origin->mode))
508506
goto error_out;
509-
if (sha1_object_info(origin->blob_oid.hash, NULL) != OBJ_BLOB)
507+
if (oid_object_info(&origin->blob_oid, NULL) != OBJ_BLOB)
510508
goto error_out;
511509
return 0;
512510
error_out:
@@ -1831,8 +1829,8 @@ void setup_scoreboard(struct blame_scoreboard *sb, const char *path, struct blam
18311829
&sb->final_buf_size))
18321830
;
18331831
else
1834-
sb->final_buf = read_sha1_file(o->blob_oid.hash, &type,
1835-
&sb->final_buf_size);
1832+
sb->final_buf = read_object_file(&o->blob_oid, &type,
1833+
&sb->final_buf_size);
18361834

18371835
if (!sb->final_buf)
18381836
die(_("cannot read blob %s for path %s"),

0 commit comments

Comments
 (0)