Commit 4334b177 by Edward Thomson

blob: use `git_object_size_t` for object size

Instead of using a signed type (`off_t`) use a new `git_object_size_t`
for the sizes of objects.
parent bed9fc6b
...@@ -94,7 +94,7 @@ GIT_EXTERN(const void *) git_blob_rawcontent(const git_blob *blob); ...@@ -94,7 +94,7 @@ GIT_EXTERN(const void *) git_blob_rawcontent(const git_blob *blob);
* @param blob pointer to the blob * @param blob pointer to the blob
* @return size on bytes * @return size on bytes
*/ */
GIT_EXTERN(git_off_t) git_blob_rawsize(const git_blob *blob); GIT_EXTERN(git_object_size_t) git_blob_rawsize(const git_blob *blob);
/** /**
* Flags to control the functionality of `git_blob_filter`. * Flags to control the functionality of `git_blob_filter`.
......
...@@ -258,12 +258,12 @@ typedef enum { ...@@ -258,12 +258,12 @@ typedef enum {
* abbreviated to something reasonable, like 7 characters. * abbreviated to something reasonable, like 7 characters.
*/ */
typedef struct { typedef struct {
git_oid id; git_oid id;
const char *path; const char *path;
git_off_t size; git_object_size_t size;
uint32_t flags; uint32_t flags;
uint16_t mode; uint16_t mode;
uint16_t id_abbrev; uint16_t id_abbrev;
} git_diff_file; } git_diff_file;
/** /**
......
...@@ -120,7 +120,7 @@ int git_attr_file__load( ...@@ -120,7 +120,7 @@ int git_attr_file__load(
int bom_offset; int bom_offset;
git_bom_t bom; git_bom_t bom;
git_oid id; git_oid id;
git_off_t blobsize; git_object_size_t blobsize;
*out = NULL; *out = NULL;
......
...@@ -25,18 +25,18 @@ const void *git_blob_rawcontent(const git_blob *blob) ...@@ -25,18 +25,18 @@ const void *git_blob_rawcontent(const git_blob *blob)
return git_odb_object_data(blob->data.odb); return git_odb_object_data(blob->data.odb);
} }
git_off_t git_blob_rawsize(const git_blob *blob) git_object_size_t git_blob_rawsize(const git_blob *blob)
{ {
assert(blob); assert(blob);
if (blob->raw) if (blob->raw)
return blob->data.raw.size; return blob->data.raw.size;
else else
return (git_off_t)git_odb_object_size(blob->data.odb); return (git_object_size_t)git_odb_object_size(blob->data.odb);
} }
int git_blob__getbuf(git_buf *buffer, git_blob *blob) int git_blob__getbuf(git_buf *buffer, git_blob *blob)
{ {
git_off_t size = git_blob_rawsize(blob); git_object_size_t size = git_blob_rawsize(blob);
GIT_ERROR_CHECK_BLOBSIZE(size); GIT_ERROR_CHECK_BLOBSIZE(size);
return git_buf_set(buffer, git_blob_rawcontent(blob), (size_t)size); return git_buf_set(buffer, git_blob_rawcontent(blob), (size_t)size);
...@@ -91,13 +91,13 @@ int git_blob_create_from_buffer( ...@@ -91,13 +91,13 @@ int git_blob_create_from_buffer(
} }
static int write_file_stream( static int write_file_stream(
git_oid *id, git_odb *odb, const char *path, git_off_t file_size) git_oid *id, git_odb *odb, const char *path, git_object_size_t file_size)
{ {
int fd, error; int fd, error;
char buffer[FILEIO_BUFSIZE]; char buffer[FILEIO_BUFSIZE];
git_odb_stream *stream = NULL; git_odb_stream *stream = NULL;
ssize_t read_len = -1; ssize_t read_len = -1;
git_off_t written = 0; git_object_size_t written = 0;
if ((error = git_odb_open_wstream( if ((error = git_odb_open_wstream(
&stream, odb, file_size, GIT_OBJECT_BLOB)) < 0) &stream, odb, file_size, GIT_OBJECT_BLOB)) < 0)
...@@ -129,7 +129,7 @@ static int write_file_stream( ...@@ -129,7 +129,7 @@ static int write_file_stream(
static int write_file_filtered( static int write_file_filtered(
git_oid *id, git_oid *id,
git_off_t *size, git_object_size_t *size,
git_odb *odb, git_odb *odb,
const char *full_path, const char *full_path,
git_filter_list *fl) git_filter_list *fl)
...@@ -184,7 +184,7 @@ int git_blob__create_from_paths( ...@@ -184,7 +184,7 @@ int git_blob__create_from_paths(
int error; int error;
struct stat st; struct stat st;
git_odb *odb = NULL; git_odb *odb = NULL;
git_off_t size; git_object_size_t size;
mode_t mode; mode_t mode;
git_buf path = GIT_BUF_INIT; git_buf path = GIT_BUF_INIT;
...@@ -389,7 +389,7 @@ cleanup: ...@@ -389,7 +389,7 @@ cleanup:
int git_blob_is_binary(const git_blob *blob) int git_blob_is_binary(const git_blob *blob)
{ {
git_buf content = GIT_BUF_INIT; git_buf content = GIT_BUF_INIT;
git_off_t size; git_object_size_t size;
assert(blob); assert(blob);
......
...@@ -21,7 +21,7 @@ struct git_blob { ...@@ -21,7 +21,7 @@ struct git_blob {
git_odb_object *odb; git_odb_object *odb;
struct { struct {
const char *data; const char *data;
git_off_t size; git_object_size_t size;
} raw; } raw;
} data; } data;
unsigned int raw:1; unsigned int raw:1;
......
...@@ -78,7 +78,7 @@ static int has_cr_in_index(const git_filter_source *src) ...@@ -78,7 +78,7 @@ static int has_cr_in_index(const git_filter_source *src)
const git_index_entry *entry; const git_index_entry *entry;
git_blob *blob; git_blob *blob;
const void *blobcontent; const void *blobcontent;
git_off_t blobsize; git_object_size_t blobsize;
bool found_cr; bool found_cr;
if (!path) if (!path)
......
...@@ -62,7 +62,7 @@ static int diff_file_content_init_common( ...@@ -62,7 +62,7 @@ static int diff_file_content_init_common(
git_diff_driver_update_options(&fc->opts_flags, fc->driver); git_diff_driver_update_options(&fc->opts_flags, fc->driver);
/* make sure file is conceivable mmap-able */ /* make sure file is conceivable mmap-able */
if ((git_off_t)((size_t)fc->file->size) != fc->file->size) if ((size_t)fc->file->size != fc->file->size)
fc->file->flags |= GIT_DIFF_FLAG_BINARY; fc->file->flags |= GIT_DIFF_FLAG_BINARY;
/* check if user is forcing text diff the file */ /* check if user is forcing text diff the file */
else if (fc->opts_flags & GIT_DIFF_FORCE_TEXT) { else if (fc->opts_flags & GIT_DIFF_FORCE_TEXT) {
......
...@@ -20,7 +20,7 @@ typedef struct { ...@@ -20,7 +20,7 @@ typedef struct {
git_diff_driver *driver; git_diff_driver *driver;
uint32_t flags; uint32_t flags;
uint32_t opts_flags; uint32_t opts_flags;
git_off_t opts_max_size; git_object_size_t opts_max_size;
git_iterator_type_t src; git_iterator_type_t src;
const git_blob *blob; const git_blob *blob;
git_map map; git_map map;
......
...@@ -560,11 +560,11 @@ int git_diff__oid_for_file( ...@@ -560,11 +560,11 @@ int git_diff__oid_for_file(
git_diff *diff, git_diff *diff,
const char *path, const char *path,
uint16_t mode, uint16_t mode,
git_off_t size) git_object_size_t size)
{ {
git_index_entry entry; git_index_entry entry;
if (size < 0 || size > UINT32_MAX) { if (size > UINT32_MAX) {
git_error_set(GIT_ERROR_NOMEMORY, "file size overflow (for 32-bits) on '%s'", path); git_error_set(GIT_ERROR_NOMEMORY, "file size overflow (for 32-bits) on '%s'", path);
return -1; return -1;
} }
......
...@@ -88,7 +88,7 @@ extern int git_diff__oid_for_file( ...@@ -88,7 +88,7 @@ extern int git_diff__oid_for_file(
git_diff *diff, git_diff *diff,
const char *path, const char *path,
uint16_t mode, uint16_t mode,
git_off_t size); git_object_size_t size);
extern int git_diff__oid_for_entry( extern int git_diff__oid_for_entry(
git_oid *out, git_oid *out,
...@@ -120,7 +120,7 @@ GIT_INLINE(int) git_diff_file__resolve_zero_size( ...@@ -120,7 +120,7 @@ GIT_INLINE(int) git_diff_file__resolve_zero_size(
git_odb_free(odb); git_odb_free(odb);
if (!error) if (!error)
file->size = (git_off_t)len; file->size = (git_object_size_t)len;
return error; return error;
} }
......
...@@ -55,7 +55,7 @@ int git_diff_file_stats__full_to_buf( ...@@ -55,7 +55,7 @@ int git_diff_file_stats__full_to_buf(
{ {
const char *old_path = NULL, *new_path = NULL; const char *old_path = NULL, *new_path = NULL;
size_t padding; size_t padding;
git_off_t old_size, new_size; git_object_size_t old_size, new_size;
old_path = delta->old_file.path; old_path = delta->old_file.path;
new_path = delta->new_file.path; new_path = delta->new_file.path;
......
...@@ -510,7 +510,7 @@ static int similarity_sig( ...@@ -510,7 +510,7 @@ static int similarity_sig(
if (file->size != git_blob_rawsize(info->blob)) if (file->size != git_blob_rawsize(info->blob))
file->size = git_blob_rawsize(info->blob); file->size = git_blob_rawsize(info->blob);
sz = (size_t)(git__is_sizet(file->size) ? file->size : -1); sz = git__is_sizet(file->size) ? (size_t)file->size : (size_t)-1;
error = opts->metric->buffer_signature( error = opts->metric->buffer_signature(
&cache[info->idx], info->file, &cache[info->idx], info->file,
......
...@@ -764,7 +764,7 @@ int git_filter_list_apply_to_file( ...@@ -764,7 +764,7 @@ int git_filter_list_apply_to_file(
static int buf_from_blob(git_buf *out, git_blob *blob) static int buf_from_blob(git_buf *out, git_blob *blob)
{ {
git_off_t rawsize = git_blob_rawsize(blob); git_object_size_t rawsize = git_blob_rawsize(blob);
if (!git__is_sizet(rawsize)) { if (!git__is_sizet(rawsize)) {
git_error_set(GIT_ERROR_OS, "blob is too large to filter"); git_error_set(GIT_ERROR_OS, "blob is too large to filter");
......
...@@ -1024,7 +1024,7 @@ static int index_entry_similarity_calc( ...@@ -1024,7 +1024,7 @@ static int index_entry_similarity_calc(
{ {
git_blob *blob; git_blob *blob;
git_diff_file diff_file = {{{0}}}; git_diff_file diff_file = {{{0}}};
git_off_t blobsize; git_object_size_t blobsize;
int error; int error;
*out = NULL; *out = NULL;
......
...@@ -320,7 +320,7 @@ static int note_new( ...@@ -320,7 +320,7 @@ static int note_new(
git_blob *blob) git_blob *blob)
{ {
git_note *note = NULL; git_note *note = NULL;
git_off_t blobsize; git_object_size_t blobsize;
note = git__malloc(sizeof(git_note)); note = git__malloc(sizeof(git_note));
GIT_ERROR_CHECK_ALLOC(note); GIT_ERROR_CHECK_ALLOC(note);
......
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
#include "repository.h" #include "repository.h"
#define GIT_OBJECT_SIZE_MAX UINT64_MAX
extern bool git_object__strict_input_validation; extern bool git_object__strict_input_validation;
/** Base git object for inheritance */ /** Base git object for inheritance */
......
...@@ -32,7 +32,7 @@ static int tree_reader_read( ...@@ -32,7 +32,7 @@ static int tree_reader_read(
tree_reader *reader = (tree_reader *)_reader; tree_reader *reader = (tree_reader *)_reader;
git_tree_entry *tree_entry = NULL; git_tree_entry *tree_entry = NULL;
git_blob *blob = NULL; git_blob *blob = NULL;
git_off_t blobsize; git_object_size_t blobsize;
int error; int error;
if ((error = git_tree_entry_bypath(&tree_entry, reader->tree, filename)) < 0 || if ((error = git_tree_entry_bypath(&tree_entry, reader->tree, filename)) < 0 ||
......
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