333
return ret;
334
}
335
336
-static void fill_sha1_path(struct strbuf *buf, const unsigned char *sha1)
336
+static void fill_loose_path(struct strbuf *buf, const struct object_id *oid)
337
{
338
int i;
339
for (i = 0; i < the_hash_algo->rawsz; i++) {
340
static char hex[] = "0123456789abcdef";
341
- unsigned int val = sha1[i];
341
+ unsigned int val = oid->hash[i];
342
strbuf_addch(buf, hex[val >> 4]);
343
strbuf_addch(buf, hex[val & 0xf]);
344
if (!i)
348
349
static const char *odb_loose_path(struct object_directory *odb,
350
struct strbuf *buf,
351
- const unsigned char *sha1)
351
+ const struct object_id *oid)
352
{
353
strbuf_reset(buf);
354
strbuf_addstr(buf, odb->path);
355
strbuf_addch(buf, '/');
356
- fill_sha1_path(buf, sha1);
356
+ fill_loose_path(buf, oid);
357
return buf->buf;
358
}
359
360
const char *loose_object_path(struct repository *r, struct strbuf *buf,
361
- const unsigned char *sha1)
361
+ const struct object_id *oid)
362
{
363
- return odb_loose_path(r->objects->odb, buf, sha1);
363
+ return odb_loose_path(r->objects->odb, buf, oid);
364
}
365
366
/*
721
int freshen)
722
{
723
static struct strbuf path = STRBUF_INIT;
724
- odb_loose_path(odb, &path, oid->hash);
724
+ odb_loose_path(odb, &path, oid);
725
return check_and_freshen_file(path.buf, freshen);
726
}
727
872
}
873
874
/*
875
- * Find "sha1" as a loose object in the local repository or in an alternate.
875
+ * Find "oid" as a loose object in the local repository or in an alternate.
876
* Returns 0 on success, negative on failure.
877
*
878
* The "path" out-parameter will give the path of the object we found (if any).
879
* Note that it may point to static storage and is only valid until another
880
- * call to stat_sha1_file().
880
+ * call to stat_loose_object().
881
*/
882
-static int stat_sha1_file(struct repository *r, const unsigned char *sha1,
883
- struct stat *st, const char **path)
882
+static int stat_loose_object(struct repository *r, const struct object_id *oid,
883
+ struct stat *st, const char **path)
884
{
885
struct object_directory *odb;
886
static struct strbuf buf = STRBUF_INIT;
887
888
prepare_alt_odb(r);
889
for (odb = r->objects->odb; odb; odb = odb->next) {
890
- *path = odb_loose_path(odb, &buf, sha1);
890
+ *path = odb_loose_path(odb, &buf, oid);
891
if (!lstat(*path, st))
892
return 0;
893
}
896
}
897
898
/*
899
- * Like stat_sha1_file(), but actually open the object and return the
899
+ * Like stat_loose_object(), but actually open the object and return the
900
* descriptor. See the caveats on the "path" parameter above.
901
*/
902
-static int open_sha1_file(struct repository *r,
903
- const unsigned char *sha1, const char **path)
902
+static int open_loose_object(struct repository *r,
903
+ const struct object_id *oid, const char **path)
904
{
905
int fd;
906
struct object_directory *odb;
909
910
prepare_alt_odb(r);
911
for (odb = r->objects->odb; odb; odb = odb->next) {
912
- *path = odb_loose_path(odb, &buf, sha1);
912
+ *path = odb_loose_path(odb, &buf, oid);
913
fd = git_open(*path);
914
if (fd >= 0)
915
return fd;
939
940
/*
941
* Map the loose object at "path" if it is not NULL, or the path found by
942
- * searching for a loose object named "sha1".
942
+ * searching for a loose object named "oid".
943
*/
944
-static void *map_sha1_file_1(struct repository *r, const char *path,
945
- const unsigned char *sha1, unsigned long *size)
944
+static void *map_loose_object_1(struct repository *r, const char *path,
945
+ const struct object_id *oid, unsigned long *size)
946
{
947
void *map;
948
int fd;
950
if (path)
951
fd = git_open(path);
952
else
953
- fd = open_sha1_file(r, sha1, &path);
953
+ fd = open_loose_object(r, oid, &path);
954
map = NULL;
955
if (fd >= 0) {
956
struct stat st;
969
return map;
970
}
971
972
-void *map_sha1_file(struct repository *r,
973
- const unsigned char *sha1, unsigned long *size)
972
+void *map_loose_object(struct repository *r,
973
+ const struct object_id *oid,
974
+ unsigned long *size)
975
{
975
- return map_sha1_file_1(r, NULL, sha1, size);
976
+ return map_loose_object_1(r, NULL, oid, size);
977
}
978
979
static int unpack_sha1_short_header(git_zstream *stream,
1162
return parse_sha1_header_extended(hdr, &oi, 0);
1163
}
1164
1164
-static int sha1_loose_object_info(struct repository *r,
1165
- const unsigned char *sha1,
1166
- struct object_info *oi, int flags)
1165
+static int loose_object_info(struct repository *r,
1166
+ const struct object_id *oid,
1167
+ struct object_info *oi, int flags)
1168
{
1169
int status = 0;
1170
unsigned long mapsize;
1189
const char *path;
1190
struct stat st;
1191
if (!oi->disk_sizep && (flags & OBJECT_INFO_QUICK))
1191
- return quick_has_loose(r, sha1) ? 0 : -1;
1192
- if (stat_sha1_file(r, sha1, &st, &path) < 0)
1192
+ return quick_has_loose(r, oid->hash) ? 0 : -1;
1193
+ if (stat_loose_object(r, oid, &st, &path) < 0)
1194
return -1;
1195
if (oi->disk_sizep)
1196
*oi->disk_sizep = st.st_size;
1197
return 0;
1198
}
1199
1199
- map = map_sha1_file(r, sha1, &mapsize);
1200
+ map = map_loose_object(r, oid, &mapsize);
1201
if (!map)
1202
return -1;
1203
1209
if ((flags & OBJECT_INFO_ALLOW_UNKNOWN_TYPE)) {
1210
if (unpack_sha1_header_to_strbuf(&stream, map, mapsize, hdr, sizeof(hdr), &hdrbuf) < 0)
1211
status = error(_("unable to unpack %s header with --allow-unknown-type"),
1211
- sha1_to_hex(sha1));
1212
+ oid_to_hex(oid));
1213
} else if (unpack_sha1_header(&stream, map, mapsize, hdr, sizeof(hdr)) < 0)
1214
status = error(_("unable to unpack %s header"),
1214
- sha1_to_hex(sha1));
1215
+ oid_to_hex(oid));
1216
if (status < 0)
1217
; /* Do nothing */
1218
else if (hdrbuf.len) {
1219
if ((status = parse_sha1_header_extended(hdrbuf.buf, oi, flags)) < 0)
1220
status = error(_("unable to parse %s header with --allow-unknown-type"),
1220
- sha1_to_hex(sha1));
1221
+ oid_to_hex(oid));
1222
} else if ((status = parse_sha1_header_extended(hdr, oi, flags)) < 0)
1222
- status = error(_("unable to parse %s header"), sha1_to_hex(sha1));
1223
+ status = error(_("unable to parse %s header"), oid_to_hex(oid));
1224
1225
if (status >= 0 && oi->contentp) {
1226
*oi->contentp = unpack_sha1_rest(&stream, hdr,
1226
- *oi->sizep, sha1);
1227
+ *oi->sizep, oid->hash);
1228
if (!*oi->contentp) {
1229
git_inflate_end(&stream);
1230
status = -1;
1290
return -1;
1291
1292
/* Most likely it's a loose object. */
1292
- if (!sha1_loose_object_info(r, real->hash, oi, flags))
1293
+ if (!loose_object_info(r, real, oi, flags))
1294
return 0;
1295
1296
/* Not a loose object; someone else may have just packed it. */
1418
die(_("replacement %s not found for %s"),
1419
oid_to_hex(repl), oid_to_hex(oid));
1420
1420
- if (!stat_sha1_file(the_repository, repl->hash, &st, &path))
1421
+ if (!stat_loose_object(the_repository, repl, &st, &path))
1422
die(_("loose object %s (stored in %s) is corrupt"),
1423
oid_to_hex(repl), path);
1424
1553
}
1554
1555
/* Finalize a file on disk, and close it. */
1555
-static void close_sha1_file(int fd)
1556
+static void close_loose_object(int fd)
1557
{
1558
if (fsync_object_files)
1559
fsync_or_die(fd, "sha1 file");
1618
static struct strbuf tmp_file = STRBUF_INIT;
1619
static struct strbuf filename = STRBUF_INIT;
1620
1620
- loose_object_path(the_repository, &filename, oid->hash);
1621
+ loose_object_path(the_repository, &filename, oid);
1622
1623
fd = create_tmpfile(&tmp_file, filename.buf);
1624
if (fd < 0) {
1666
die(_("confused by unstable object source data for %s"),
1667
oid_to_hex(oid));
1668
1668
- close_sha1_file(fd);
1669
+ close_loose_object(fd);
1670
1671
if (mtime) {
1672
struct utimbuf utb;
2256
2257
*contents = NULL;
2258
2258
- map = map_sha1_file_1(the_repository, path, NULL, &mapsize);
2259
+ map = map_loose_object_1(the_repository, path, NULL, &mapsize);
2260
if (!map) {
2261
error_errno(_("unable to mmap %s"), path);
2262
goto out;