Skip to content

Commit c80d226

Browse files
avargitster
authored andcommitted
object-file API: have write_object_file() take "enum object_type"
Change the write_object_file() function to take an "enum object_type" instead of a "const char *type". Its callers either passed {commit,tree,blob,tag}_type and can pass the corresponding OBJ_* type instead, or were hardcoding strings like "blob". This avoids the back & forth fragility where the callers of write_object_file() would have the enum type, and convert it themselves via type_name(). We do have to now do that conversion ourselves before calling write_object_file_prepare(), but those codepaths will be similarly adjusted in subsequent commits. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b04cdea commit c80d226

19 files changed

+33
-33
lines changed

apply.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3589,7 +3589,7 @@ static int try_threeway(struct apply_state *state,
35893589

35903590
/* Preimage the patch was prepared for */
35913591
if (patch->is_new)
3592-
write_object_file("", 0, blob_type, &pre_oid);
3592+
write_object_file("", 0, OBJ_BLOB, &pre_oid);
35933593
else if (get_oid(patch->old_oid_prefix, &pre_oid) ||
35943594
read_blob_object(&buf, &pre_oid, patch->old_mode))
35953595
return error(_("repository lacks the necessary blob to perform 3-way merge."));
@@ -3605,7 +3605,7 @@ static int try_threeway(struct apply_state *state,
36053605
return -1;
36063606
}
36073607
/* post_oid is theirs */
3608-
write_object_file(tmp_image.buf, tmp_image.len, blob_type, &post_oid);
3608+
write_object_file(tmp_image.buf, tmp_image.len, OBJ_BLOB, &post_oid);
36093609
clear_image(&tmp_image);
36103610

36113611
/* our_oid is ours */
@@ -3618,7 +3618,7 @@ static int try_threeway(struct apply_state *state,
36183618
return error(_("cannot read the current contents of '%s'"),
36193619
patch->old_name);
36203620
}
3621-
write_object_file(tmp_image.buf, tmp_image.len, blob_type, &our_oid);
3621+
write_object_file(tmp_image.buf, tmp_image.len, OBJ_BLOB, &our_oid);
36223622
clear_image(&tmp_image);
36233623

36243624
/* in-core three-way merge between post and our using pre as base */
@@ -4346,7 +4346,7 @@ static int add_index_file(struct apply_state *state,
43464346
}
43474347
fill_stat_cache_info(state->repo->index, ce, &st);
43484348
}
4349-
if (write_object_file(buf, size, blob_type, &ce->oid) < 0) {
4349+
if (write_object_file(buf, size, OBJ_BLOB, &ce->oid) < 0) {
43504350
discard_cache_entry(ce);
43514351
return error(_("unable to create backing store "
43524352
"for newly created file %s"), path);

builtin/checkout.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ static int checkout_merged(int pos, const struct checkout *state,
298298
* (it also writes the merge result to the object database even
299299
* when it may contain conflicts).
300300
*/
301-
if (write_object_file(result_buf.ptr, result_buf.size, blob_type, &oid))
301+
if (write_object_file(result_buf.ptr, result_buf.size, OBJ_BLOB, &oid))
302302
die(_("Unable to add merge result for '%s'"), path);
303303
free(result_buf.ptr);
304304
ce = make_transient_cache_entry(mode, &oid, path, 2, ce_mem_pool);

builtin/mktag.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ int cmd_mktag(int argc, const char **argv, const char *prefix)
100100
if (verify_object_in_tag(&tagged_oid, &tagged_type))
101101
die(_("tag on stdin did not refer to a valid object"));
102102

103-
if (write_object_file(buf.buf, buf.len, tag_type, &result) < 0)
103+
if (write_object_file(buf.buf, buf.len, OBJ_TAG, &result) < 0)
104104
die(_("unable to write tag file"));
105105

106106
strbuf_release(&buf);

builtin/mktree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static void write_tree(struct object_id *oid)
5858
strbuf_add(&buf, ent->oid.hash, the_hash_algo->rawsz);
5959
}
6060

61-
write_object_file(buf.buf, buf.len, tree_type, oid);
61+
write_object_file(buf.buf, buf.len, OBJ_TREE, oid);
6262
strbuf_release(&buf);
6363
}
6464

builtin/notes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ static void prepare_note_data(const struct object_id *object, struct note_data *
199199

200200
static void write_note_data(struct note_data *d, struct object_id *oid)
201201
{
202-
if (write_object_file(d->buf.buf, d->buf.len, blob_type, oid)) {
202+
if (write_object_file(d->buf.buf, d->buf.len, OBJ_BLOB, oid)) {
203203
int status = die_message(_("unable to write note object"));
204204

205205
if (d->edit_path)

builtin/receive-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ static void prepare_push_cert_sha1(struct child_process *proc)
762762
int bogs /* beginning_of_gpg_sig */;
763763

764764
already_done = 1;
765-
if (write_object_file(push_cert.buf, push_cert.len, "blob",
765+
if (write_object_file(push_cert.buf, push_cert.len, OBJ_BLOB,
766766
&push_cert_oid))
767767
oidclr(&push_cert_oid);
768768

builtin/replace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ static int create_graft(int argc, const char **argv, int force, int gentle)
474474
return -1;
475475
}
476476

477-
if (write_object_file(buf.buf, buf.len, commit_type, &new_oid)) {
477+
if (write_object_file(buf.buf, buf.len, OBJ_COMMIT, &new_oid)) {
478478
strbuf_release(&buf);
479479
return error(_("could not write replacement commit for: '%s'"),
480480
old_ref);

builtin/tag.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ static int build_tag_object(struct strbuf *buf, int sign, struct object_id *resu
238238
{
239239
if (sign && do_sign(buf) < 0)
240240
return error(_("unable to sign the tag"));
241-
if (write_object_file(buf->buf, buf->len, tag_type, result) < 0)
241+
if (write_object_file(buf->buf, buf->len, OBJ_TAG, result) < 0)
242242
return error(_("unable to write tag file"));
243243
return 0;
244244
}

builtin/unpack-objects.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ static void write_cached_object(struct object *obj, struct obj_buffer *obj_buf)
177177
struct object_id oid;
178178

179179
if (write_object_file(obj_buf->buffer, obj_buf->size,
180-
type_name(obj->type), &oid) < 0)
180+
obj->type, &oid) < 0)
181181
die("failed to write object %s", oid_to_hex(&obj->oid));
182182
obj->flags |= FLAG_WRITTEN;
183183
}
@@ -243,15 +243,15 @@ static void write_object(unsigned nr, enum object_type type,
243243
void *buf, unsigned long size)
244244
{
245245
if (!strict) {
246-
if (write_object_file(buf, size, type_name(type),
246+
if (write_object_file(buf, size, type,
247247
&obj_list[nr].oid) < 0)
248248
die("failed to write object");
249249
added_object(nr, type, buf, size);
250250
free(buf);
251251
obj_list[nr].obj = NULL;
252252
} else if (type == OBJ_BLOB) {
253253
struct blob *blob;
254-
if (write_object_file(buf, size, type_name(type),
254+
if (write_object_file(buf, size, type,
255255
&obj_list[nr].oid) < 0)
256256
die("failed to write object");
257257
added_object(nr, type, buf, size);

cache-tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ static int update_one(struct cache_tree *it,
440440
} else if (dryrun) {
441441
hash_object_file(the_hash_algo, buffer.buf, buffer.len,
442442
tree_type, &it->oid);
443-
} else if (write_object_file_flags(buffer.buf, buffer.len, tree_type,
443+
} else if (write_object_file_flags(buffer.buf, buffer.len, OBJ_TREE,
444444
&it->oid, flags & WRITE_TREE_SILENT
445445
? HASH_SILENT : 0)) {
446446
strbuf_release(&buffer);

0 commit comments

Comments
 (0)