Skip to content

Commit

Permalink
streaming: add repository argument to open_istream_fn
Browse files Browse the repository at this point in the history
Add a repository argument to allow the callers of open_istream_fn
to be more specific about which repository to act on. This is a small
mechanical change; it doesn't change the implementation to handle
repositories other than the_repository yet.

Unlike the previous commits, this uses a run time check to make sure
the passed repository is the_repository instead of a compile time check.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
  • Loading branch information
stefanbeller committed Feb 5, 2018
1 parent eb5f134 commit 3dd5500
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions streaming.c
Expand Up @@ -15,7 +15,8 @@ enum input_source {
pack_non_delta = 2
};

typedef int (*open_istream_fn)(struct git_istream *,
typedef int (*open_istream_fn)(struct repository *,
struct git_istream *,
struct object_info *,
const unsigned char *,
enum object_type *);
Expand All @@ -29,7 +30,9 @@ struct stream_vtbl {

#define open_method_decl(name) \
int open_istream_ ##name \
(struct git_istream *st, struct object_info *oi, \
(struct repository *r, \
struct git_istream *st, \
struct object_info *oi, \
const unsigned char *sha1, \
enum object_type *type)

Expand Down Expand Up @@ -147,8 +150,8 @@ struct git_istream *open_istream(const unsigned char *sha1,
return NULL;

st = xmalloc(sizeof(*st));
if (open_istream_tbl[src](st, &oi, real, type)) {
if (open_istream_incore(st, &oi, real, type)) {
if (open_istream_tbl[src](the_repository, st, &oi, real, type)) {
if (open_istream_incore(the_repository, st, &oi, real, type)) {
free(st);
return NULL;
}
Expand Down Expand Up @@ -338,6 +341,9 @@ static struct stream_vtbl loose_vtbl = {

static open_method_decl(loose)
{
if (r != the_repository)
BUG("r != the_repository");

st->u.loose.mapped = map_sha1_file(the_repository,
sha1, &st->u.loose.mapsize);
if (!st->u.loose.mapped)
Expand Down Expand Up @@ -433,6 +439,9 @@ static open_method_decl(pack_non_delta)
struct pack_window *window;
enum object_type in_pack_type;

if (r != the_repository)
BUG("r != the_repository");

st->u.in_pack.pack = oi->u.packed.pack;
st->u.in_pack.pos = oi->u.packed.offset;
window = NULL;
Expand Down Expand Up @@ -490,6 +499,9 @@ static struct stream_vtbl incore_vtbl = {

static open_method_decl(incore)
{
if (r != the_repository)
BUG("r != the_repository");

st->u.incore.buf = read_sha1_file_extended(the_repository, sha1,
type, &st->size, 0);
st->u.incore.read_ptr = 0;
Expand Down

0 comments on commit 3dd5500

Please sign in to comment.