Skip to content

Commit a09c985

Browse files
dreamergitster
authored andcommitted
sha1_file: convert write_sha1_file to object_id
Convert the definition and declaration of write_sha1_file to struct object_id and adjust usage of this function. This commit also converts static function write_sha1_file_prepare, as it is closely related. Rename these functions to write_object_file and write_object_file_prepare respectively. Replace sha1_to_hex, hashcpy and hashclr with their oid equivalents wherever possible. Signed-off-by: Patryk Obara <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bbca96d commit a09c985

18 files changed

+65
-58
lines changed

apply.c

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

35553555
/* Preimage the patch was prepared for */
35563556
if (patch->is_new)
3557-
write_sha1_file("", 0, blob_type, pre_oid.hash);
3557+
write_object_file("", 0, blob_type, &pre_oid);
35583558
else if (get_oid(patch->old_sha1_prefix, &pre_oid) ||
35593559
read_blob_object(&buf, &pre_oid, patch->old_mode))
35603560
return error(_("repository lacks the necessary blob to fall back on 3-way merge."));
@@ -3570,7 +3570,7 @@ static int try_threeway(struct apply_state *state,
35703570
return -1;
35713571
}
35723572
/* post_oid is theirs */
3573-
write_sha1_file(tmp_image.buf, tmp_image.len, blob_type, post_oid.hash);
3573+
write_object_file(tmp_image.buf, tmp_image.len, blob_type, &post_oid);
35743574
clear_image(&tmp_image);
35753575

35763576
/* our_oid is ours */
@@ -3583,7 +3583,7 @@ static int try_threeway(struct apply_state *state,
35833583
return error(_("cannot read the current contents of '%s'"),
35843584
patch->old_name);
35853585
}
3586-
write_sha1_file(tmp_image.buf, tmp_image.len, blob_type, our_oid.hash);
3586+
write_object_file(tmp_image.buf, tmp_image.len, blob_type, &our_oid);
35873587
clear_image(&tmp_image);
35883588

35893589
/* in-core three-way merge between post and our using pre as base */
@@ -4291,7 +4291,7 @@ static int add_index_file(struct apply_state *state,
42914291
}
42924292
fill_stat_cache_info(ce, &st);
42934293
}
4294-
if (write_sha1_file(buf, size, blob_type, ce->oid.hash) < 0) {
4294+
if (write_object_file(buf, size, blob_type, &ce->oid) < 0) {
42954295
free(ce);
42964296
return error(_("unable to create backing store "
42974297
"for newly created file %s"), path);

builtin/checkout.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,7 @@ static int checkout_merged(int pos, const struct checkout *state)
227227
* (it also writes the merge result to the object database even
228228
* when it may contain conflicts).
229229
*/
230-
if (write_sha1_file(result_buf.ptr, result_buf.size,
231-
blob_type, oid.hash))
230+
if (write_object_file(result_buf.ptr, result_buf.size, blob_type, &oid))
232231
die(_("Unable to add merge result for '%s'"), path);
233232
free(result_buf.ptr);
234233
ce = make_cache_entry(mode, oid.hash, path, 2, 0);

builtin/mktag.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ static int verify_tag(char *buffer, unsigned long size)
151151
int cmd_mktag(int argc, const char **argv, const char *prefix)
152152
{
153153
struct strbuf buf = STRBUF_INIT;
154-
unsigned char result_sha1[20];
154+
struct object_id result;
155155

156156
if (argc != 1)
157157
usage("git mktag");
@@ -165,10 +165,10 @@ int cmd_mktag(int argc, const char **argv, const char *prefix)
165165
if (verify_tag(buf.buf, buf.len) < 0)
166166
die("invalid tag signature file");
167167

168-
if (write_sha1_file(buf.buf, buf.len, tag_type, result_sha1) < 0)
168+
if (write_object_file(buf.buf, buf.len, tag_type, &result) < 0)
169169
die("unable to write tag file");
170170

171171
strbuf_release(&buf);
172-
printf("%s\n", sha1_to_hex(result_sha1));
172+
printf("%s\n", oid_to_hex(&result));
173173
return 0;
174174
}

builtin/mktree.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static int ent_compare(const void *a_, const void *b_)
4040
b->name, b->len, b->mode);
4141
}
4242

43-
static void write_tree(unsigned char *sha1)
43+
static void write_tree(struct object_id *oid)
4444
{
4545
struct strbuf buf;
4646
size_t size;
@@ -57,7 +57,7 @@ static void write_tree(unsigned char *sha1)
5757
strbuf_add(&buf, ent->sha1, 20);
5858
}
5959

60-
write_sha1_file(buf.buf, buf.len, tree_type, sha1);
60+
write_object_file(buf.buf, buf.len, tree_type, oid);
6161
strbuf_release(&buf);
6262
}
6363

@@ -142,7 +142,7 @@ static void mktree_line(char *buf, size_t len, int nul_term_line, int allow_miss
142142
int cmd_mktree(int ac, const char **av, const char *prefix)
143143
{
144144
struct strbuf sb = STRBUF_INIT;
145-
unsigned char sha1[20];
145+
struct object_id oid;
146146
int nul_term_line = 0;
147147
int allow_missing = 0;
148148
int is_batch_mode = 0;
@@ -181,8 +181,8 @@ int cmd_mktree(int ac, const char **av, const char *prefix)
181181
*/
182182
; /* skip creating an empty tree */
183183
} else {
184-
write_tree(sha1);
185-
puts(sha1_to_hex(sha1));
184+
write_tree(&oid);
185+
puts(oid_to_hex(&oid));
186186
fflush(stdout);
187187
}
188188
used=0; /* reset tree entry buffer for re-use in batch mode */

builtin/notes.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,9 @@ static void prepare_note_data(const struct object_id *object, struct note_data *
198198
}
199199
}
200200

201-
static void write_note_data(struct note_data *d, unsigned char *sha1)
201+
static void write_note_data(struct note_data *d, struct object_id *oid)
202202
{
203-
if (write_sha1_file(d->buf.buf, d->buf.len, blob_type, sha1)) {
203+
if (write_object_file(d->buf.buf, d->buf.len, blob_type, oid)) {
204204
error(_("unable to write note object"));
205205
if (d->edit_path)
206206
error(_("the note contents have been left in %s"),
@@ -459,7 +459,7 @@ static int add(int argc, const char **argv, const char *prefix)
459459

460460
prepare_note_data(&object, &d, note ? note->hash : NULL);
461461
if (d.buf.len || allow_empty) {
462-
write_note_data(&d, new_note.hash);
462+
write_note_data(&d, &new_note);
463463
if (add_note(t, &object, &new_note, combine_notes_overwrite))
464464
die("BUG: combine_notes_overwrite failed");
465465
commit_notes(t, "Notes added by 'git notes add'");
@@ -619,7 +619,7 @@ static int append_edit(int argc, const char **argv, const char *prefix)
619619
}
620620

621621
if (d.buf.len || allow_empty) {
622-
write_note_data(&d, new_note.hash);
622+
write_note_data(&d, &new_note);
623623
if (add_note(t, &object, &new_note, combine_notes_overwrite))
624624
die("BUG: combine_notes_overwrite failed");
625625
logmsg = xstrfmt("Notes added by 'git notes %s'", argv[0]);

builtin/receive-pack.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ static int sent_capabilities;
6969
static int shallow_update;
7070
static const char *alt_shallow_file;
7171
static struct strbuf push_cert = STRBUF_INIT;
72-
static unsigned char push_cert_sha1[20];
72+
static struct object_id push_cert_oid;
7373
static struct signature_check sigcheck;
7474
static const char *push_cert_nonce;
7575
static const char *cert_nonce_seed;
@@ -633,8 +633,9 @@ static void prepare_push_cert_sha1(struct child_process *proc)
633633
int bogs /* beginning_of_gpg_sig */;
634634

635635
already_done = 1;
636-
if (write_sha1_file(push_cert.buf, push_cert.len, "blob", push_cert_sha1))
637-
hashclr(push_cert_sha1);
636+
if (write_object_file(push_cert.buf, push_cert.len, "blob",
637+
&push_cert_oid))
638+
oidclr(&push_cert_oid);
638639

639640
memset(&sigcheck, '\0', sizeof(sigcheck));
640641
sigcheck.result = 'N';
@@ -655,9 +656,9 @@ static void prepare_push_cert_sha1(struct child_process *proc)
655656
strbuf_release(&gpg_status);
656657
nonce_status = check_nonce(push_cert.buf, bogs);
657658
}
658-
if (!is_null_sha1(push_cert_sha1)) {
659+
if (!is_null_oid(&push_cert_oid)) {
659660
argv_array_pushf(&proc->env_array, "GIT_PUSH_CERT=%s",
660-
sha1_to_hex(push_cert_sha1));
661+
oid_to_hex(&push_cert_oid));
661662
argv_array_pushf(&proc->env_array, "GIT_PUSH_CERT_SIGNER=%s",
662663
sigcheck.signer ? sigcheck.signer : "");
663664
argv_array_pushf(&proc->env_array, "GIT_PUSH_CERT_KEY=%s",

builtin/replace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ static int create_graft(int argc, const char **argv, int force)
410410

411411
check_mergetags(commit, argc, argv);
412412

413-
if (write_sha1_file(buf.buf, buf.len, commit_type, new.hash))
413+
if (write_object_file(buf.buf, buf.len, commit_type, &new))
414414
die(_("could not write replacement commit for: '%s'"), old_ref);
415415

416416
strbuf_release(&buf);

builtin/tag.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ static int build_tag_object(struct strbuf *buf, int sign, struct object_id *resu
187187
{
188188
if (sign && do_sign(buf) < 0)
189189
return error(_("unable to sign the tag"));
190-
if (write_sha1_file(buf->buf, buf->len, tag_type, result->hash) < 0)
190+
if (write_object_file(buf->buf, buf->len, tag_type, result) < 0)
191191
return error(_("unable to write tag file"));
192192
return 0;
193193
}

builtin/unpack-objects.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ static void write_cached_object(struct object *obj, struct obj_buffer *obj_buf)
172172
{
173173
struct object_id oid;
174174

175-
if (write_sha1_file(obj_buf->buffer, obj_buf->size, typename(obj->type), oid.hash) < 0)
175+
if (write_object_file(obj_buf->buffer, obj_buf->size,
176+
typename(obj->type), &oid) < 0)
176177
die("failed to write object %s", oid_to_hex(&obj->oid));
177178
obj->flags |= FLAG_WRITTEN;
178179
}
@@ -237,14 +238,16 @@ static void write_object(unsigned nr, enum object_type type,
237238
void *buf, unsigned long size)
238239
{
239240
if (!strict) {
240-
if (write_sha1_file(buf, size, typename(type), obj_list[nr].oid.hash) < 0)
241+
if (write_object_file(buf, size, typename(type),
242+
&obj_list[nr].oid) < 0)
241243
die("failed to write object");
242244
added_object(nr, type, buf, size);
243245
free(buf);
244246
obj_list[nr].obj = NULL;
245247
} else if (type == OBJ_BLOB) {
246248
struct blob *blob;
247-
if (write_sha1_file(buf, size, typename(type), obj_list[nr].oid.hash) < 0)
249+
if (write_object_file(buf, size, typename(type),
250+
&obj_list[nr].oid) < 0)
248251
die("failed to write object");
249252
added_object(nr, type, buf, size);
250253
free(buf);

cache-tree.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,9 +406,10 @@ static int update_one(struct cache_tree *it,
406406
oidcpy(&it->oid, &oid);
407407
else
408408
to_invalidate = 1;
409-
} else if (dryrun)
409+
} else if (dryrun) {
410410
hash_object_file(buffer.buf, buffer.len, tree_type, &it->oid);
411-
else if (write_sha1_file(buffer.buf, buffer.len, tree_type, it->oid.hash)) {
411+
} else if (write_object_file(buffer.buf, buffer.len, tree_type,
412+
&it->oid)) {
412413
strbuf_release(&buffer);
413414
return -1;
414415
}

0 commit comments

Comments
 (0)