Merge branch 'tb/print-size-t-with-uintmax-format'

Code preparation to replace ulong vars with size_t vars where
appropriate.

* tb/print-size-t-with-uintmax-format:
  Upcast size_t variables to uintmax_t when printing
This commit is contained in:
Junio C Hamano 2018-11-19 16:24:41 +09:00
commit f5f0f68d61
11 changed files with 24 additions and 23 deletions

View File

@ -202,7 +202,7 @@ static void prepare_header(struct archiver_args *args,
unsigned int mode, unsigned long size)
{
xsnprintf(header->mode, sizeof(header->mode), "%07o", mode & 07777);
xsnprintf(header->size, sizeof(header->size), "%011lo", S_ISREG(mode) ? size : 0);
xsnprintf(header->size, sizeof(header->size), "%011"PRIoMAX , S_ISREG(mode) ? (uintmax_t)size : (uintmax_t)0);
xsnprintf(header->mtime, sizeof(header->mtime), "%011lo", (unsigned long) args->time);
xsnprintf(header->uid, sizeof(header->uid), "%07o", 0);

View File

@ -99,7 +99,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
oi.sizep = &size;
if (oid_object_info_extended(the_repository, &oid, &oi, flags) < 0)
die("git cat-file: could not get object info");
printf("%lu\n", size);
printf("%"PRIuMAX"\n", (uintmax_t)size);
return 0;
case 'e':
@ -245,7 +245,7 @@ static void expand_atom(struct strbuf *sb, const char *atom, int len,
if (data->mark_query)
data->info.sizep = &data->size;
else
strbuf_addf(sb, "%lu", data->size);
strbuf_addf(sb, "%"PRIuMAX , (uintmax_t)data->size);
} else if (is_atom("objectsize:disk", atom, len)) {
if (data->mark_query)
data->info.disk_sizep = &data->disk_size;

View File

@ -253,7 +253,7 @@ static void export_blob(const struct object_id *oid)
mark_next_object(object);
printf("blob\nmark :%"PRIu32"\ndata %lu\n", last_idnum, size);
printf("blob\nmark :%"PRIu32"\ndata %"PRIuMAX"\n", last_idnum, (uintmax_t)size);
if (size && fwrite(buf, size, 1, stdout) != 1)
die_errno("could not write blob '%s'", oid_to_hex(oid));
printf("\n");

View File

@ -424,7 +424,8 @@ static void *unpack_entry_data(off_t offset, unsigned long size,
int hdrlen;
if (!is_delta_type(type)) {
hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %lu", type_name(type), size) + 1;
hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %"PRIuMAX,
type_name(type),(uintmax_t)size) + 1;
the_hash_algo->init_fn(&c);
the_hash_algo->update_fn(&c, hdr, hdrlen);
} else
@ -1597,10 +1598,10 @@ static void show_pack_info(int stat_only)
chain_histogram[obj_stat[i].delta_depth - 1]++;
if (stat_only)
continue;
printf("%s %-6s %lu %lu %"PRIuMAX,
printf("%s %-6s %"PRIuMAX" %"PRIuMAX" %"PRIuMAX,
oid_to_hex(&obj->idx.oid),
type_name(obj->real_type), obj->size,
(unsigned long)(obj[1].idx.offset - obj->idx.offset),
type_name(obj->real_type), (uintmax_t)obj->size,
(uintmax_t)(obj[1].idx.offset - obj->idx.offset),
(uintmax_t)obj->idx.offset);
if (is_delta_type(obj->type)) {
struct object_entry *bobj = &objects[obj_stat[i].base_object_no];

View File

@ -100,7 +100,7 @@ static int show_tree(const struct object_id *oid, struct strbuf *base,
"BAD");
else
xsnprintf(size_text, sizeof(size_text),
"%lu", size);
"%"PRIuMAX, (uintmax_t)size);
} else
xsnprintf(size_text, sizeof(size_text), "-");
printf("%06o %s %s %7s\t", mode, type,

View File

@ -2083,9 +2083,9 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
die(_("object %s cannot be read"),
oid_to_hex(&trg_entry->idx.oid));
if (sz != trg_size)
die(_("object %s inconsistent object length (%lu vs %lu)"),
oid_to_hex(&trg_entry->idx.oid), sz,
trg_size);
die(_("object %s inconsistent object length (%"PRIuMAX" vs %"PRIuMAX")"),
oid_to_hex(&trg_entry->idx.oid), (uintmax_t)sz,
(uintmax_t)trg_size);
*mem_usage += sz;
}
if (!src->data) {
@ -2110,9 +2110,9 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
oid_to_hex(&src_entry->idx.oid));
}
if (sz != src_size)
die(_("object %s inconsistent object length (%lu vs %lu)"),
oid_to_hex(&src_entry->idx.oid), sz,
src_size);
die(_("object %s inconsistent object length (%"PRIuMAX" vs %"PRIuMAX")"),
oid_to_hex(&src_entry->idx.oid), (uintmax_t)sz,
(uintmax_t)src_size);
*mem_usage += sz;
}
if (!src->index) {

2
diff.c
View File

@ -3228,7 +3228,7 @@ static void emit_binary_diff_body(struct diff_options *o,
}
if (delta && delta_size < deflate_size) {
char *s = xstrfmt("%lu", orig_size);
char *s = xstrfmt("%"PRIuMAX , (uintmax_t)orig_size);
emit_diff_symbol(o, DIFF_SYMBOL_BINARY_DIFF_HEADER_DELTA,
s, strlen(s), 0);
free(s);

View File

@ -2955,8 +2955,8 @@ static void cat_blob(struct object_entry *oe, struct object_id *oid)
die("Object %s is a %s but a blob was expected.",
oid_to_hex(oid), type_name(type));
strbuf_reset(&line);
strbuf_addf(&line, "%s %s %lu\n", oid_to_hex(oid),
type_name(type), size);
strbuf_addf(&line, "%s %s %"PRIuMAX"\n", oid_to_hex(oid),
type_name(type), (uintmax_t)size);
cat_blob_write(line.buf, line.len);
strbuf_release(&line);
cat_blob_write(buf, size);

View File

@ -365,7 +365,7 @@ static void start_put(struct transfer_request *request)
git_zstream stream;
unpacked = read_object_file(&request->obj->oid, &type, &len);
hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %lu", type_name(type), len) + 1;
hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %"PRIuMAX , type_name(type), (uintmax_t)len) + 1;
/* Set it up */
git_deflate_init(&stream, zlib_compression_level);

View File

@ -882,7 +882,7 @@ static void grab_common_values(struct atom_value *val, int deref, struct expand_
v->s = xstrdup(type_name(oi->type));
else if (!strcmp(name, "objectsize")) {
v->value = oi->size;
v->s = xstrfmt("%lu", oi->size);
v->s = xstrfmt("%"PRIuMAX , (uintmax_t)oi->size);
}
else if (deref)
grab_objectname(name, &oi->oid, v, &used_atom[i]);

View File

@ -833,7 +833,7 @@ int check_object_signature(const struct object_id *oid, void *map,
return -1;
/* Generate the header */
hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %lu", type_name(obj_type), size) + 1;
hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %"PRIuMAX , type_name(obj_type), (uintmax_t)size) + 1;
/* Sha1.. */
the_hash_algo->init_fn(&c);
@ -1492,7 +1492,7 @@ static void write_object_file_prepare(const void *buf, unsigned long len,
git_hash_ctx c;
/* Generate the header */
*hdrlen = xsnprintf(hdr, *hdrlen, "%s %lu", type, len)+1;
*hdrlen = xsnprintf(hdr, *hdrlen, "%s %"PRIuMAX , type, (uintmax_t)len)+1;
/* Sha1.. */
the_hash_algo->init_fn(&c);
@ -1758,7 +1758,7 @@ int force_object_loose(const struct object_id *oid, time_t mtime)
buf = read_object(oid->hash, &type, &len);
if (!buf)
return error(_("cannot read sha1_file for %s"), oid_to_hex(oid));
hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %lu", type_name(type), len) + 1;
hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %"PRIuMAX , type_name(type), (uintmax_t)len) + 1;
ret = write_loose_object(oid, hdr, hdrlen, buf, len, mtime);
free(buf);