Skip to content

Commit

Permalink
Merge branch 'eb/limit-bulk-checkin-to-blobs'
Browse files Browse the repository at this point in the history
The "streaming" interface used for bulk-checkin codepath has been
narrowed to take only blob objects for now, with no real loss of
functionality.

* eb/limit-bulk-checkin-to-blobs:
  bulk-checkin: only support blobs in index_bulk_checkin
  • Loading branch information
gitster committed Oct 10, 2023
2 parents 3a06386 + 9eb5419 commit 3df51ea
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 27 deletions.
35 changes: 17 additions & 18 deletions bulk-checkin.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ static int already_written(struct bulk_checkin_packfile *state, struct object_id
* status before calling us just in case we ask it to call us again
* with a new pack.
*/
static int stream_to_pack(struct bulk_checkin_packfile *state,
git_hash_ctx *ctx, off_t *already_hashed_to,
int fd, size_t size, enum object_type type,
const char *path, unsigned flags)
static int stream_blob_to_pack(struct bulk_checkin_packfile *state,
git_hash_ctx *ctx, off_t *already_hashed_to,
int fd, size_t size, const char *path,
unsigned flags)
{
git_zstream s;
unsigned char ibuf[16384];
Expand All @@ -170,7 +170,7 @@ static int stream_to_pack(struct bulk_checkin_packfile *state,

git_deflate_init(&s, pack_compression_level);

hdrlen = encode_in_pack_object_header(obuf, sizeof(obuf), type, size);
hdrlen = encode_in_pack_object_header(obuf, sizeof(obuf), OBJ_BLOB, size);
s.next_out = obuf + hdrlen;
s.avail_out = sizeof(obuf) - hdrlen;

Expand Down Expand Up @@ -247,11 +247,10 @@ static void prepare_to_stream(struct bulk_checkin_packfile *state,
die_errno("unable to write pack header");
}

static int deflate_to_pack(struct bulk_checkin_packfile *state,
struct object_id *result_oid,
int fd, size_t size,
enum object_type type, const char *path,
unsigned flags)
static int deflate_blob_to_pack(struct bulk_checkin_packfile *state,
struct object_id *result_oid,
int fd, size_t size,
const char *path, unsigned flags)
{
off_t seekback, already_hashed_to;
git_hash_ctx ctx;
Expand All @@ -265,7 +264,7 @@ static int deflate_to_pack(struct bulk_checkin_packfile *state,
return error("cannot find the current offset");

header_len = format_object_header((char *)obuf, sizeof(obuf),
type, size);
OBJ_BLOB, size);
the_hash_algo->init_fn(&ctx);
the_hash_algo->update_fn(&ctx, obuf, header_len);
the_hash_algo->init_fn(&checkpoint.ctx);
Expand All @@ -283,8 +282,8 @@ static int deflate_to_pack(struct bulk_checkin_packfile *state,
idx->offset = state->offset;
crc32_begin(state->f);
}
if (!stream_to_pack(state, &ctx, &already_hashed_to,
fd, size, type, path, flags))
if (!stream_blob_to_pack(state, &ctx, &already_hashed_to,
fd, size, path, flags))
break;
/*
* Writing this object to the current pack will make
Expand Down Expand Up @@ -351,12 +350,12 @@ void fsync_loose_object_bulk_checkin(int fd, const char *filename)
}
}

int index_bulk_checkin(struct object_id *oid,
int fd, size_t size, enum object_type type,
const char *path, unsigned flags)
int index_blob_bulk_checkin(struct object_id *oid,
int fd, size_t size,
const char *path, unsigned flags)
{
int status = deflate_to_pack(&bulk_checkin_packfile, oid, fd, size, type,
path, flags);
int status = deflate_blob_to_pack(&bulk_checkin_packfile, oid, fd, size,
path, flags);
if (!odb_transaction_nesting)
flush_bulk_checkin_packfile(&bulk_checkin_packfile);
return status;
Expand Down
6 changes: 3 additions & 3 deletions bulk-checkin.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
void prepare_loose_object_bulk_checkin(void);
void fsync_loose_object_bulk_checkin(int fd, const char *filename);

int index_bulk_checkin(struct object_id *oid,
int fd, size_t size, enum object_type type,
const char *path, unsigned flags);
int index_blob_bulk_checkin(struct object_id *oid,
int fd, size_t size,
const char *path, unsigned flags);

/*
* Tell the object database to optimize for adding
Expand Down
12 changes: 6 additions & 6 deletions object-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -2446,11 +2446,11 @@ static int index_core(struct index_state *istate,
* binary blobs, they generally do not want to get any conversion, and
* callers should avoid this code path when filters are requested.
*/
static int index_stream(struct object_id *oid, int fd, size_t size,
enum object_type type, const char *path,
unsigned flags)
static int index_blob_stream(struct object_id *oid, int fd, size_t size,
const char *path,
unsigned flags)
{
return index_bulk_checkin(oid, fd, size, type, path, flags);
return index_blob_bulk_checkin(oid, fd, size, path, flags);
}

int index_fd(struct index_state *istate, struct object_id *oid,
Expand All @@ -2472,8 +2472,8 @@ int index_fd(struct index_state *istate, struct object_id *oid,
ret = index_core(istate, oid, fd, xsize_t(st->st_size),
type, path, flags);
else
ret = index_stream(oid, fd, xsize_t(st->st_size), type, path,
flags);
ret = index_blob_stream(oid, fd, xsize_t(st->st_size), path,
flags);
close(fd);
return ret;
}
Expand Down

0 comments on commit 3df51ea

Please sign in to comment.