Skip to content

Commit

Permalink
streaming: add repository argument to open_istream
Browse files Browse the repository at this point in the history
Add a repository argument to allow the callers of open_istream
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.

As with the previous commits, use a macro to catch callers passing a
repository other than the_repository at compile time.

Add the cocci patch that converted the callers.

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 3dd5500 commit 141ba1f
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion archive-tar.c
Expand Up @@ -121,7 +121,7 @@ static int stream_blocked(const unsigned char *sha1)
char buf[BLOCKSIZE];
ssize_t readlen;

st = open_istream(sha1, &type, &sz, NULL);
st = open_istream(the_repository, sha1, &type, &sz, NULL);
if (!st)
return error("cannot stream blob %s", sha1_to_hex(sha1));
for (;;) {
Expand Down
3 changes: 2 additions & 1 deletion archive-zip.c
Expand Up @@ -340,7 +340,8 @@ static int write_zip_entry(struct archiver_args *args,

if (S_ISREG(mode) && type == OBJ_BLOB && !args->convert &&
size > big_file_threshold) {
stream = open_istream(sha1, &type, &size, NULL);
stream = open_istream(the_repository, sha1, &type,
&size, NULL);
if (!stream)
return error("cannot stream blob %s",
sha1_to_hex(sha1));
Expand Down
3 changes: 2 additions & 1 deletion builtin/index-pack.c
Expand Up @@ -774,7 +774,8 @@ static int check_collison(struct object_entry *entry)

memset(&data, 0, sizeof(data));
data.entry = entry;
data.st = open_istream(entry->idx.oid.hash, &type, &size, NULL);
data.st = open_istream(the_repository, entry->idx.oid.hash, &type,
&size, NULL);
if (!data.st)
return -1;
if (size != entry->size || type != entry->type)
Expand Down
2 changes: 1 addition & 1 deletion builtin/pack-objects.c
Expand Up @@ -270,7 +270,7 @@ static unsigned long write_no_reuse_object(struct sha1file *f, struct object_ent
if (!usable_delta) {
if (entry->type == OBJ_BLOB &&
entry->size > big_file_threshold &&
(st = open_istream(entry->idx.oid.hash, &type, &size, NULL)) != NULL)
(st = open_istream(the_repository, entry->idx.oid.hash, &type, &size, NULL)) != NULL)
buf = NULL;
else {
buf = read_sha1_file(the_repository,
Expand Down
10 changes: 10 additions & 0 deletions contrib/coccinelle/object_store.cocci
Expand Up @@ -34,3 +34,13 @@ expression G;
read_sha1_file(
+the_repository,
E, F, G)

@@
expression E;
expression F;
expression G;
expression H;
@@
open_istream(
+ the_repository,
E, F, G, H)
2 changes: 1 addition & 1 deletion sha1_file.c
Expand Up @@ -817,7 +817,7 @@ int check_sha1_signature_the_repository(const unsigned char *sha1, void *map,
return hashcmp(sha1, real_sha1) ? -1 : 0;
}

st = open_istream(sha1, &obj_type, &size, NULL);
st = open_istream(the_repository, sha1, &obj_type, &size, NULL);
if (!st)
return -1;

Expand Down
4 changes: 2 additions & 2 deletions streaming.c
Expand Up @@ -136,7 +136,7 @@ static enum input_source istream_source(const unsigned char *sha1,
}
}

struct git_istream *open_istream(const unsigned char *sha1,
struct git_istream *open_istream_the_repository(const unsigned char *sha1,
enum object_type *type,
unsigned long *size,
struct stream_filter *filter)
Expand Down Expand Up @@ -524,7 +524,7 @@ int stream_blob_to_fd(int fd, const struct object_id *oid, struct stream_filter
ssize_t kept = 0;
int result = -1;

st = open_istream(oid->hash, &type, &sz, filter);
st = open_istream(the_repository, oid->hash, &type, &sz, filter);
if (!st) {
if (filter)
free_stream_filter(filter);
Expand Down
3 changes: 2 additions & 1 deletion streaming.h
Expand Up @@ -8,7 +8,8 @@
/* opaque */
struct git_istream;

extern struct git_istream *open_istream(const unsigned char *, enum object_type *, unsigned long *, struct stream_filter *);
#define open_istream(r, s, t, sz, f) open_istream_##r(s, t, sz, f)
extern struct git_istream *open_istream_the_repository(const unsigned char *, enum object_type *, unsigned long *, struct stream_filter *);
extern int close_istream(struct git_istream *);
extern ssize_t read_istream(struct git_istream *, void *, size_t);

Expand Down

0 comments on commit 141ba1f

Please sign in to comment.