130
return check_and_freshen(oid, 0);
131
}
132
133
-static int format_object_header_literally(char *str, size_t size,
134
- const char *type, size_t objsize)
135
-{
136
- return xsnprintf(str, size, "%s %"PRIuMAX, type, (uintmax_t)objsize) + 1;
137
-}
138
-
133
int format_object_header(char *str, size_t size, enum object_type type,
134
size_t objsize)
135
{
138
if (!name)
139
BUG("could not get a type name for 'enum object_type' value %d", type);
140
147
- return format_object_header_literally(str, size, name, objsize);
141
+ return xsnprintf(str, size, "%s %"PRIuMAX, name, (uintmax_t)objsize) + 1;
142
}
143
144
int check_object_signature(struct repository *r, const struct object_id *oid,
552
hash_object_body(algo, &c, buf, len, oid, hdr, hdrlen);
553
}
554
561
-static void write_object_file_prepare_literally(const struct git_hash_algo *algo,
562
- const void *buf, unsigned long len,
563
- const char *type, struct object_id *oid,
564
- char *hdr, int *hdrlen)
565
-{
566
- struct git_hash_ctx c;
567
-
568
- *hdrlen = format_object_header_literally(hdr, *hdrlen, type, len);
569
- hash_object_body(algo, &c, buf, len, oid, hdr, hdrlen);
570
-}
571
-
555
#define CHECK_COLLISION_DEST_VANISHED -2
556
557
static int check_collision(const char *source, const char *dest)
681
return 0;
682
}
683
701
-static void hash_object_file_literally(const struct git_hash_algo *algo,
702
- const void *buf, unsigned long len,
703
- const char *type, struct object_id *oid)
704
-{
705
- char hdr[MAX_HEADER_LEN];
706
- int hdrlen = sizeof(hdr);
707
-
708
- write_object_file_prepare_literally(algo, buf, len, type, oid, hdr, &hdrlen);
709
-}
710
-
684
void hash_object_file(const struct git_hash_algo *algo, const void *buf,
685
unsigned long len, enum object_type type,
686
struct object_id *oid)
687
{
715
- hash_object_file_literally(algo, buf, len, type_name(type), oid);
688
+ char hdr[MAX_HEADER_LEN];
689
+ int hdrlen = sizeof(hdr);
690
+
691
+ write_object_file_prepare(algo, buf, len, type, oid, hdr, &hdrlen);
692
}
693
694
/* Finalize a file on disk, and close it. */
1090
return 0;
1091
}
1092
1117
-int write_object_file_literally(const void *buf, unsigned long len,
1118
- const char *type, struct object_id *oid,
1119
- unsigned flags)
1120
-{
1121
- char *header;
1122
- struct repository *repo = the_repository;
1123
- const struct git_hash_algo *algo = repo->hash_algo;
1124
- const struct git_hash_algo *compat = repo->compat_hash_algo;
1125
- struct object_id compat_oid;
1126
- int hdrlen, status = 0;
1127
- int compat_type = -1;
1128
-
1129
- if (compat) {
1130
- compat_type = type_from_string_gently(type, -1, 1);
1131
- if (compat_type == OBJ_BLOB)
1132
- hash_object_file(compat, buf, len, compat_type,
1133
- &compat_oid);
1134
- else if (compat_type != -1) {
1135
- struct strbuf converted = STRBUF_INIT;
1136
- convert_object_file(the_repository,
1137
- &converted, algo, compat,
1138
- buf, len, compat_type, 0);
1139
- hash_object_file(compat, converted.buf, converted.len,
1140
- compat_type, &compat_oid);
1141
- strbuf_release(&converted);
1142
- }
1143
- }
1144
-
1145
- /* type string, SP, %lu of the length plus NUL must fit this */
1146
- hdrlen = strlen(type) + MAX_HEADER_LEN;
1147
- header = xmalloc(hdrlen);
1148
- write_object_file_prepare_literally(the_hash_algo, buf, len, type,
1149
- oid, header, &hdrlen);
1150
-
1151
- if (!(flags & WRITE_OBJECT_FILE_PERSIST))
1152
- goto cleanup;
1153
- if (freshen_packed_object(oid) || freshen_loose_object(oid))
1154
- goto cleanup;
1155
- status = write_loose_object(oid, header, hdrlen, buf, len, 0, 0);
1156
- if (compat_type != -1)
1157
- return repo_add_loose_object_map(repo, oid, &compat_oid);
1158
-
1159
-cleanup:
1160
- free(header);
1161
- return status;
1162
-}
1163
-
1093
int force_object_loose(const struct object_id *oid, time_t mtime)
1094
{
1095
struct repository *repo = the_repository;