Commit ba59a4a2 by lhchavez

Making get_delta_base() conform to the general error-handling pattern

This makes get_delta_base() return the error code as the return value
and the delta base as an out-parameter.
parent f3273725
...@@ -265,10 +265,11 @@ static int advance_delta_offset(git_indexer *idx, git_object_t type) ...@@ -265,10 +265,11 @@ static int advance_delta_offset(git_indexer *idx, git_object_t type)
if (type == GIT_OBJECT_REF_DELTA) { if (type == GIT_OBJECT_REF_DELTA) {
idx->off += GIT_OID_RAWSZ; idx->off += GIT_OID_RAWSZ;
} else { } else {
off64_t base_off = get_delta_base(idx->pack, &w, &idx->off, type, idx->entry_start); off64_t base_off;
int error = get_delta_base(&base_off, idx->pack, &w, &idx->off, type, idx->entry_start);
git_mwindow_close(&w); git_mwindow_close(&w);
if (base_off < 0) if (error < 0)
return (int)base_off; return error;
} }
return 0; return 0;
......
...@@ -488,13 +488,11 @@ int git_packfile_resolve_header( ...@@ -488,13 +488,11 @@ int git_packfile_resolve_header(
size_t base_size; size_t base_size;
git_packfile_stream stream; git_packfile_stream stream;
base_offset = get_delta_base(p, &w_curs, &curpos, type, offset); error = get_delta_base(&base_offset, p, &w_curs, &curpos, type, offset);
git_mwindow_close(&w_curs); git_mwindow_close(&w_curs);
if (base_offset < 0) { if (error < 0)
error = (int)base_offset;
return error; return error;
}
if ((error = git_packfile_stream_open(&stream, p, curpos)) < 0) if ((error = git_packfile_stream_open(&stream, p, curpos)) < 0)
return error; return error;
...@@ -515,13 +513,11 @@ int git_packfile_resolve_header( ...@@ -515,13 +513,11 @@ int git_packfile_resolve_header(
if (type != GIT_OBJECT_OFS_DELTA && type != GIT_OBJECT_REF_DELTA) if (type != GIT_OBJECT_OFS_DELTA && type != GIT_OBJECT_REF_DELTA)
break; break;
base_offset = get_delta_base(p, &w_curs, &curpos, type, base_offset); error = get_delta_base(&base_offset, p, &w_curs, &curpos, type, base_offset);
git_mwindow_close(&w_curs); git_mwindow_close(&w_curs);
if (base_offset < 0) { if (error < 0)
error = (int)base_offset;
return error; return error;
}
} }
*type_p = type; *type_p = type;
...@@ -595,13 +591,11 @@ static int pack_dependency_chain(git_dependency_chain *chain_out, ...@@ -595,13 +591,11 @@ static int pack_dependency_chain(git_dependency_chain *chain_out,
if (type != GIT_OBJECT_OFS_DELTA && type != GIT_OBJECT_REF_DELTA) if (type != GIT_OBJECT_OFS_DELTA && type != GIT_OBJECT_REF_DELTA)
break; break;
base_offset = get_delta_base(p, &w_curs, &curpos, type, obj_offset); error = get_delta_base(&base_offset, p, &w_curs, &curpos, type, obj_offset);
git_mwindow_close(&w_curs); git_mwindow_close(&w_curs);
if (base_offset < 0) { /* must actually be an error code */ if (error < 0)
error = (int)base_offset;
goto on_error; goto on_error;
}
/* we need to pass the pos *after* the delta-base bit */ /* we need to pass the pos *after* the delta-base bit */
elem->offset = curpos; elem->offset = curpos;
...@@ -886,18 +880,21 @@ out: ...@@ -886,18 +880,21 @@ out:
* curpos is where the data starts, delta_obj_offset is the where the * curpos is where the data starts, delta_obj_offset is the where the
* header starts * header starts
*/ */
off64_t get_delta_base( int get_delta_base(
struct git_pack_file *p, off64_t *delta_base_out,
git_mwindow **w_curs, struct git_pack_file *p,
off64_t *curpos, git_mwindow **w_curs,
git_object_t type, off64_t *curpos,
off64_t delta_obj_offset) git_object_t type,
off64_t delta_obj_offset)
{ {
unsigned int left = 0; unsigned int left = 0;
unsigned char *base_info; unsigned char *base_info;
off64_t base_offset; off64_t base_offset;
git_oid unused; git_oid unused;
assert(delta_base_out);
base_info = pack_window_open(p, w_curs, *curpos, &left); base_info = pack_window_open(p, w_curs, *curpos, &left);
/* Assumption: the only reason this would fail is because the file is too small */ /* Assumption: the only reason this would fail is because the file is too small */
if (base_info == NULL) if (base_info == NULL)
...@@ -934,7 +931,8 @@ off64_t get_delta_base( ...@@ -934,7 +931,8 @@ off64_t get_delta_base(
git_oid_fromraw(&oid, base_info); git_oid_fromraw(&oid, base_info);
if ((entry = git_oidmap_get(p->idx_cache, &oid)) != NULL) { if ((entry = git_oidmap_get(p->idx_cache, &oid)) != NULL) {
*curpos += 20; *curpos += 20;
return entry->offset; *delta_base_out = entry->offset;
return 0;
} else { } else {
/* If we're building an index, don't try to find the pack /* If we're building an index, don't try to find the pack
* entry; we just haven't seen it yet. We'll make * entry; we just haven't seen it yet. We'll make
...@@ -951,7 +949,8 @@ off64_t get_delta_base( ...@@ -951,7 +949,8 @@ off64_t get_delta_base(
} else } else
return packfile_error("unknown object type"); return packfile_error("unknown object type");
return base_offset; *delta_base_out = base_offset;
return 0;
} }
/*********************************************************** /***********************************************************
......
...@@ -143,8 +143,12 @@ int git_packfile_stream_open(git_packfile_stream *obj, struct git_pack_file *p, ...@@ -143,8 +143,12 @@ int git_packfile_stream_open(git_packfile_stream *obj, struct git_pack_file *p,
ssize_t git_packfile_stream_read(git_packfile_stream *obj, void *buffer, size_t len); ssize_t git_packfile_stream_read(git_packfile_stream *obj, void *buffer, size_t len);
void git_packfile_stream_dispose(git_packfile_stream *obj); void git_packfile_stream_dispose(git_packfile_stream *obj);
off64_t get_delta_base(struct git_pack_file *p, git_mwindow **w_curs, int get_delta_base(
off64_t *curpos, git_object_t type, off64_t *delta_base_out,
struct git_pack_file *p,
git_mwindow **w_curs,
off64_t *curpos,
git_object_t type,
off64_t delta_obj_offset); off64_t delta_obj_offset);
void git_packfile_close(struct git_pack_file *p, bool unlink_packfile); void git_packfile_close(struct git_pack_file *p, bool unlink_packfile);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment