Skip to content
Snippets Groups Projects
Commit cba595ab authored by Junio C Hamano's avatar Junio C Hamano
Browse files

Merge branch 'jk/loose-object-cache-oid'

Code clean-up.

* jk/loose-object-cache-oid:
  prefer "hash mismatch" to "sha1 mismatch"
  sha1-file: avoid "sha1 file" for generic use in messages
  sha1-file: prefer "loose object file" to "sha1 file" in messages
  sha1-file: drop has_sha1_file()
  convert has_sha1_file() callers to has_object_file()
  sha1-file: convert pass-through functions to object_id
  sha1-file: modernize loose header/stream functions
  sha1-file: modernize loose object file functions
  http: use struct object_id instead of bare sha1
  update comment references to sha1_object_info()
  sha1-file: fix outdated sha1 comment references
parents 96e6547c 01f8d594
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -140,9 +140,9 @@ dangling <type> <object>::
The <type> object <object>, is present in the database but never
'directly' used. A dangling commit could be a root node.
 
sha1 mismatch <object>::
The database has an object who's sha1 doesn't match the
database value.
hash mismatch <object>::
The database has an object whose hash doesn't match the
object database value.
This indicates a serious data integrity problem.
 
Environment Variables
Loading
Loading
Loading
Loading
@@ -3182,7 +3182,7 @@ static int apply_binary(struct apply_state *state,
return 0; /* deletion patch */
}
 
if (has_sha1_file(oid.hash)) {
if (has_object_file(&oid)) {
/* We already have the postimage */
enum object_type type;
unsigned long size;
Loading
Loading
Loading
Loading
@@ -211,14 +211,14 @@ struct expand_data {
 
/*
* After a mark_query run, this object_info is set up to be
* passed to sha1_object_info_extended. It will point to the data
* passed to oid_object_info_extended. It will point to the data
* elements above, so you can retrieve the response from there.
*/
struct object_info info;
 
/*
* This flag will be true if the requested batch format and options
* don't require us to call sha1_object_info, which can then be
* don't require us to call oid_object_info, which can then be
* optimized out.
*/
unsigned skip_object_info : 1;
Loading
Loading
@@ -496,7 +496,7 @@ static int batch_objects(struct batch_options *opt)
 
/*
* Expand once with our special mark_query flag, which will prime the
* object_info to be handed to sha1_object_info_extended for each
* object_info to be handed to oid_object_info_extended for each
* object.
*/
memset(&data, 0, sizeof(data));
Loading
Loading
Loading
Loading
@@ -317,8 +317,7 @@ static void find_non_local_tags(const struct ref *refs,
!has_object_file_with_flags(&ref->old_oid,
OBJECT_INFO_QUICK) &&
!will_fetch(head, ref->old_oid.hash) &&
!has_sha1_file_with_flags(item->oid.hash,
OBJECT_INFO_QUICK) &&
!has_object_file_with_flags(&item->oid, OBJECT_INFO_QUICK) &&
!will_fetch(head, item->oid.hash))
oidclr(&item->oid);
item = NULL;
Loading
Loading
@@ -332,7 +331,7 @@ static void find_non_local_tags(const struct ref *refs,
* fetch.
*/
if (item &&
!has_sha1_file_with_flags(item->oid.hash, OBJECT_INFO_QUICK) &&
!has_object_file_with_flags(&item->oid, OBJECT_INFO_QUICK) &&
!will_fetch(head, item->oid.hash))
oidclr(&item->oid);
 
Loading
Loading
@@ -353,7 +352,7 @@ static void find_non_local_tags(const struct ref *refs,
* checked to see if it needs fetching.
*/
if (item &&
!has_sha1_file_with_flags(item->oid.hash, OBJECT_INFO_QUICK) &&
!has_object_file_with_flags(&item->oid, OBJECT_INFO_QUICK) &&
!will_fetch(head, item->oid.hash))
oidclr(&item->oid);
 
Loading
Loading
Loading
Loading
@@ -772,7 +772,7 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
if (startup_info->have_repository) {
read_lock();
collision_test_needed =
has_sha1_file_with_flags(oid->hash, OBJECT_INFO_QUICK);
has_object_file_with_flags(oid, OBJECT_INFO_QUICK);
read_unlock();
}
 
Loading
Loading
Loading
Loading
@@ -1643,7 +1643,7 @@ static void check_object(struct object_entry *entry)
 
/*
* No choice but to fall back to the recursive delta walk
* with sha1_object_info() to find about the object type
* with oid_object_info() to find about the object type
* at this point...
*/
give_up:
Loading
Loading
@@ -1719,7 +1719,7 @@ static void drop_reused_delta(struct object_entry *entry)
if (packed_object_info(the_repository, IN_PACK(entry), entry->in_pack_offset, &oi) < 0) {
/*
* We failed to get the info from this pack for some reason;
* fall back to sha1_object_info, which may find another copy.
* fall back to oid_object_info, which may find another copy.
* And if that fails, the error will be recorded in oe_type(entry)
* and dealt with in prepare_pack().
*/
Loading
Loading
Loading
Loading
@@ -94,7 +94,7 @@ static int tree_is_complete(const struct object_id *oid)
init_tree_desc(&desc, tree->buffer, tree->size);
complete = 1;
while (tree_entry(&desc, &entry)) {
if (!has_sha1_file(entry.oid.hash) ||
if (!has_object_file(&entry.oid) ||
(S_ISDIR(entry.mode) && !tree_is_complete(&entry.oid))) {
tree->object.flags |= INCOMPLETE;
complete = 0;
Loading
Loading
Loading
Loading
@@ -23,7 +23,7 @@ static void show_one(const char *refname, const struct object_id *oid)
const char *hex;
struct object_id peeled;
 
if (!has_sha1_file(oid->hash))
if (!has_object_file(oid))
die("git show-ref: bad ref %s (%s)", refname,
oid_to_hex(oid));
 
Loading
Loading
Loading
Loading
@@ -67,7 +67,7 @@ static int already_written(struct bulk_checkin_state *state, struct object_id *o
int i;
 
/* The object may already exist in the repository */
if (has_sha1_file(oid->hash))
if (has_object_file(oid))
return 1;
 
/* Might want to keep the list sorted */
Loading
Loading
Loading
Loading
@@ -225,7 +225,7 @@ int cache_tree_fully_valid(struct cache_tree *it)
int i;
if (!it)
return 0;
if (it->entry_count < 0 || !has_sha1_file(it->oid.hash))
if (it->entry_count < 0 || !has_object_file(&it->oid))
return 0;
for (i = 0; i < it->subtree_nr; i++) {
if (!cache_tree_fully_valid(it->down[i]->cache_tree))
Loading
Loading
@@ -253,7 +253,7 @@ static int update_one(struct cache_tree *it,
 
*skip_count = 0;
 
if (0 <= it->entry_count && has_sha1_file(it->oid.hash))
if (0 <= it->entry_count && has_object_file(&it->oid))
return it->entry_count;
 
/*
Loading
Loading
Loading
Loading
@@ -1271,8 +1271,8 @@ extern char *xdg_cache_home(const char *filename);
 
extern int git_open_cloexec(const char *name, int flags);
#define git_open(name) git_open_cloexec(name, O_RDONLY)
extern int unpack_sha1_header(git_zstream *stream, unsigned char *map, unsigned long mapsize, void *buffer, unsigned long bufsiz);
extern int parse_sha1_header(const char *hdr, unsigned long *sizep);
extern int unpack_loose_header(git_zstream *stream, unsigned char *map, unsigned long mapsize, void *buffer, unsigned long bufsiz);
extern int parse_loose_header(const char *hdr, unsigned long *sizep);
 
extern int check_object_signature(const struct object_id *oid, void *buf, unsigned long size, const char *type);
 
Loading
Loading
@@ -1619,7 +1619,7 @@ extern int odb_mkstemp(struct strbuf *temp_filename, const char *pattern);
extern int odb_pack_keep(const char *name);
 
/*
* Set this to 0 to prevent sha1_object_info_extended() from fetching missing
* Set this to 0 to prevent oid_object_info_extended() from fetching missing
* blobs. This has a difference only if extensions.partialClone is set.
*
* Its default value is 1.
Loading
Loading
Loading
Loading
@@ -255,7 +255,7 @@ static void start_fetch_loose(struct transfer_request *request)
struct active_request_slot *slot;
struct http_object_request *obj_req;
 
obj_req = new_http_object_request(repo->url, request->obj->oid.hash);
obj_req = new_http_object_request(repo->url, &request->obj->oid);
if (obj_req == NULL) {
request->state = ABORTED;
return;
Loading
Loading
Loading
Loading
@@ -58,7 +58,7 @@ static void start_object_request(struct walker *walker,
struct active_request_slot *slot;
struct http_object_request *req;
 
req = new_http_object_request(obj_req->repo->base, obj_req->oid.hash);
req = new_http_object_request(obj_req->repo->base, &obj_req->oid);
if (req == NULL) {
obj_req->state = ABORTED;
return;
Loading
Loading
@@ -131,7 +131,7 @@ static int fill_active_slot(struct walker *walker)
list_for_each_safe(pos, tmp, head) {
obj_req = list_entry(pos, struct object_request, node);
if (obj_req->state == WAITING) {
if (has_sha1_file(obj_req->oid.hash))
if (has_object_file(&obj_req->oid))
obj_req->state = COMPLETE;
else {
start_object_request(walker, obj_req);
Loading
Loading
@@ -489,7 +489,7 @@ static int fetch_object(struct walker *walker, unsigned char *sha1)
if (obj_req == NULL)
return error("Couldn't find request for %s in the queue", hex);
 
if (has_sha1_file(obj_req->oid.hash)) {
if (has_object_file(&obj_req->oid)) {
if (obj_req->req != NULL)
abort_http_object_request(obj_req->req);
abort_object_request(obj_req);
Loading
Loading
@@ -543,11 +543,11 @@ static int fetch_object(struct walker *walker, unsigned char *sha1)
} else if (req->zret != Z_STREAM_END) {
walker->corrupt_object_found++;
ret = error("File %s (%s) corrupt", hex, req->url);
} else if (!hasheq(obj_req->oid.hash, req->real_sha1)) {
} else if (!oideq(&obj_req->oid, &req->real_oid)) {
ret = error("File %s has bad hash", hex);
} else if (req->rename < 0) {
struct strbuf buf = STRBUF_INIT;
loose_object_path(the_repository, &buf, req->sha1);
loose_object_path(the_repository, &buf, &req->oid);
ret = error("unable to write sha1 filename %s", buf.buf);
strbuf_release(&buf);
}
Loading
Loading
Loading
Loading
@@ -2343,9 +2343,9 @@ static size_t fwrite_sha1_file(char *ptr, size_t eltsize, size_t nmemb,
}
 
struct http_object_request *new_http_object_request(const char *base_url,
unsigned char *sha1)
const struct object_id *oid)
{
char *hex = sha1_to_hex(sha1);
char *hex = oid_to_hex(oid);
struct strbuf filename = STRBUF_INIT;
struct strbuf prevfile = STRBUF_INIT;
int prevlocal;
Loading
Loading
@@ -2356,10 +2356,10 @@ struct http_object_request *new_http_object_request(const char *base_url,
 
freq = xcalloc(1, sizeof(*freq));
strbuf_init(&freq->tmpfile, 0);
hashcpy(freq->sha1, sha1);
oidcpy(&freq->oid, oid);
freq->localfile = -1;
 
loose_object_path(the_repository, &filename, sha1);
loose_object_path(the_repository, &filename, oid);
strbuf_addf(&freq->tmpfile, "%s.temp", filename.buf);
 
strbuf_addf(&prevfile, "%s.prev", filename.buf);
Loading
Loading
@@ -2501,16 +2501,16 @@ int finish_http_object_request(struct http_object_request *freq)
}
 
git_inflate_end(&freq->stream);
git_SHA1_Final(freq->real_sha1, &freq->c);
git_SHA1_Final(freq->real_oid.hash, &freq->c);
if (freq->zret != Z_STREAM_END) {
unlink_or_warn(freq->tmpfile.buf);
return -1;
}
if (!hasheq(freq->sha1, freq->real_sha1)) {
if (!oideq(&freq->oid, &freq->real_oid)) {
unlink_or_warn(freq->tmpfile.buf);
return -1;
}
loose_object_path(the_repository, &filename, freq->sha1);
loose_object_path(the_repository, &filename, &freq->oid);
freq->rename = finalize_object_file(freq->tmpfile.buf, filename.buf);
strbuf_release(&filename);
 
Loading
Loading
Loading
Loading
@@ -223,8 +223,8 @@ struct http_object_request {
CURLcode curl_result;
char errorstr[CURL_ERROR_SIZE];
long http_code;
unsigned char sha1[20];
unsigned char real_sha1[20];
struct object_id oid;
struct object_id real_oid;
git_SHA_CTX c;
git_zstream stream;
int zret;
Loading
Loading
@@ -233,7 +233,7 @@ struct http_object_request {
};
 
extern struct http_object_request *new_http_object_request(
const char *base_url, unsigned char *sha1);
const char *base_url, const struct object_id *oid);
extern void process_http_object_request(struct http_object_request *freq);
extern int finish_http_object_request(struct http_object_request *freq);
extern void abort_http_object_request(struct http_object_request *freq);
Loading
Loading
Loading
Loading
@@ -154,11 +154,13 @@ void raw_object_store_clear(struct raw_object_store *o);
 
/*
* Put in `buf` the name of the file in the local object database that
* would be used to store a loose object with the specified sha1.
* would be used to store a loose object with the specified oid.
*/
const char *loose_object_path(struct repository *r, struct strbuf *buf, const unsigned char *sha1);
const char *loose_object_path(struct repository *r, struct strbuf *buf,
const struct object_id *oid);
 
void *map_sha1_file(struct repository *r, const unsigned char *sha1, unsigned long *size);
void *map_loose_object(struct repository *r, const struct object_id *oid,
unsigned long *size);
 
extern void *read_object_file_extended(struct repository *r,
const struct object_id *oid,
Loading
Loading
@@ -206,19 +208,6 @@ int read_loose_object(const char *path,
unsigned long *size,
void **contents);
 
/*
* Convenience for sha1_object_info_extended() with a NULL struct
* object_info. OBJECT_INFO_SKIP_CACHED is automatically set; pass
* nonzero flags to also set other flags.
*/
int repo_has_sha1_file_with_flags(struct repository *r,
const unsigned char *sha1, int flags);
static inline int repo_has_sha1_file(struct repository *r,
const unsigned char *sha1)
{
return repo_has_sha1_file_with_flags(r, sha1, 0);
}
#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS
#define has_sha1_file_with_flags(sha1, flags) repo_has_sha1_file_with_flags(the_repository, sha1, flags)
#define has_sha1_file(sha1) repo_has_sha1_file(the_repository, sha1)
Loading
Loading
Loading
Loading
@@ -264,7 +264,7 @@ struct object *parse_object(struct repository *r, const struct object_id *oid)
(!obj && repo_has_object_file(r, oid) &&
oid_object_info(r, oid, NULL) == OBJ_BLOB)) {
if (check_object_signature(repl, NULL, 0, NULL) < 0) {
error(_("sha1 mismatch %s"), oid_to_hex(oid));
error(_("hash mismatch %s"), oid_to_hex(oid));
return NULL;
}
parse_blob_buffer(lookup_blob(r, oid), NULL, 0);
Loading
Loading
@@ -275,7 +275,7 @@ struct object *parse_object(struct repository *r, const struct object_id *oid)
if (buffer) {
if (check_object_signature(repl, buffer, size, type_name(type)) < 0) {
free(buffer);
error(_("sha1 mismatch %s"), oid_to_hex(repl));
error(_("hash mismatch %s"), oid_to_hex(repl));
return NULL;
}
 
Loading
Loading
Loading
Loading
@@ -188,7 +188,7 @@ int ref_resolves_to_object(const char *refname,
{
if (flags & REF_ISBROKEN)
return 0;
if (!has_sha1_file(oid->hash)) {
if (!has_object_file(oid)) {
error(_("%s does not point to a valid object!"), refname);
return 0;
}
Loading
Loading
Loading
Loading
@@ -40,7 +40,7 @@ int option_parse_push_signed(const struct option *opt,
 
static void feed_object(const struct object_id *oid, FILE *fh, int negative)
{
if (negative && !has_sha1_file(oid->hash))
if (negative && !has_object_file(oid))
return;
 
if (negative)
Loading
Loading
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment