#define PACK_ID_BITS 16
#define MAX_PACK_ID ((1<<PACK_ID_BITS)-1)
-#if !defined(NO_C99_FORMAT)
-#define UM_FMT "%ju"
-#define UM10_FMT "%10ju"
-#else
-/* Assumes unsigned long long exists. */
-#define UM_FMT "%llu"
-#define UM10_FMT "%10llu"
+#ifndef PRIuMAX
+#define PRIuMAX "llu"
#endif
struct object_entry
oe = s->data.marked[idnum];
}
if (!oe)
- die("mark :" UM_FMT " not declared", orig_idnum);
+ die("mark :%" PRIuMAX " not declared", orig_idnum);
return oe;
}
} else {
for (k = 0; k < 1024; k++) {
if (m->data.marked[k])
- fprintf(f, ":" UM_FMT " %s\n", base + k,
+ fprintf(f, ":%" PRIuMAX " %s\n", base + k,
sha1_to_hex(m->data.marked[k]->sha1));
}
}
static void cmd_mark(void)
{
- if (!strncmp("mark :", command_buf.buf, 6)) {
+ if (!prefixcmp(command_buf.buf, "mark :")) {
next_mark = strtoumax(command_buf.buf + 6, NULL, 10);
read_next_command();
}
size_t length;
char *buffer;
- if (strncmp("data ", command_buf.buf, 5))
+ if (prefixcmp(command_buf.buf, "data "))
die("Expected 'data n' command, found: %s", command_buf.buf);
- if (!strncmp("<<", command_buf.buf + 5, 2)) {
+ if (!prefixcmp(command_buf.buf + 5, "<<")) {
char *term = xstrdup(command_buf.buf + 5 + 2);
size_t sz = 8192, term_len = command_buf.len - 5 - 2;
length = 0;
oe = find_mark(strtoumax(p + 1, &x, 10));
hashcpy(sha1, oe->sha1);
p = x;
- } else if (!strncmp("inline", p, 6)) {
+ } else if (!prefixcmp(p, "inline")) {
inline_data = 1;
p += 6;
} else {
const char *from;
struct branch *s;
- if (strncmp("from ", command_buf.buf, 5))
+ if (prefixcmp(command_buf.buf, "from "))
return;
if (b->branch_tree.tree) {
unsigned long size;
char *buf;
if (oe->type != OBJ_COMMIT)
- die("Mark :" UM_FMT " not a commit", idnum);
+ die("Mark :%" PRIuMAX " not a commit", idnum);
hashcpy(b->sha1, oe->sha1);
buf = gfi_unpack_entry(oe, &size);
if (!buf || size < 46)
struct branch *s;
*count = 0;
- while (!strncmp("merge ", command_buf.buf, 6)) {
+ while (!prefixcmp(command_buf.buf, "merge ")) {
from = strchr(command_buf.buf, ' ') + 1;
n = xmalloc(sizeof(*n));
s = lookup_branch(from);
uintmax_t idnum = strtoumax(from + 1, NULL, 10);
struct object_entry *oe = find_mark(idnum);
if (oe->type != OBJ_COMMIT)
- die("Mark :" UM_FMT " not a commit", idnum);
+ die("Mark :%" PRIuMAX " not a commit", idnum);
hashcpy(n->sha1, oe->sha1);
} else if (get_sha1(from, n->sha1))
die("Invalid ref name or SHA1 expression: %s", from);
read_next_command();
cmd_mark();
- if (!strncmp("author ", command_buf.buf, 7)) {
+ if (!prefixcmp(command_buf.buf, "author ")) {
author = parse_ident(command_buf.buf + 7);
read_next_command();
}
- if (!strncmp("committer ", command_buf.buf, 10)) {
+ if (!prefixcmp(command_buf.buf, "committer ")) {
committer = parse_ident(command_buf.buf + 10);
read_next_command();
}
for (;;) {
if (1 == command_buf.len)
break;
- else if (!strncmp("M ", command_buf.buf, 2))
+ else if (!prefixcmp(command_buf.buf, "M "))
file_change_m(b);
- else if (!strncmp("D ", command_buf.buf, 2))
+ else if (!prefixcmp(command_buf.buf, "D "))
file_change_d(b);
else if (!strcmp("deleteall", command_buf.buf))
file_change_deleteall(b);
read_next_command();
/* from ... */
- if (strncmp("from ", command_buf.buf, 5))
+ if (prefixcmp(command_buf.buf, "from "))
die("Expected from command, got %s", command_buf.buf);
from = strchr(command_buf.buf, ' ') + 1;
s = lookup_branch(from);
from_mark = strtoumax(from + 1, NULL, 10);
oe = find_mark(from_mark);
if (oe->type != OBJ_COMMIT)
- die("Mark :" UM_FMT " not a commit", from_mark);
+ die("Mark :%" PRIuMAX " not a commit", from_mark);
hashcpy(sha1, oe->sha1);
} else if (!get_sha1(from, sha1)) {
unsigned long size;
read_next_command();
/* tagger ... */
- if (strncmp("tagger ", command_buf.buf, 7))
+ if (prefixcmp(command_buf.buf, "tagger "))
die("Expected tagger command, got %s", command_buf.buf);
tagger = parse_ident(command_buf.buf + 7);
if (*a != '-' || !strcmp(a, "--"))
break;
- else if (!strncmp(a, "--date-format=", 14)) {
+ else if (!prefixcmp(a, "--date-format=")) {
const char *fmt = a + 14;
if (!strcmp(fmt, "raw"))
whenspec = WHENSPEC_RAW;
else
die("unknown --date-format argument %s", fmt);
}
- else if (!strncmp(a, "--max-pack-size=", 16))
+ else if (!prefixcmp(a, "--max-pack-size="))
max_packsize = strtoumax(a + 16, NULL, 0) * 1024 * 1024;
- else if (!strncmp(a, "--depth=", 8))
+ else if (!prefixcmp(a, "--depth="))
max_depth = strtoul(a + 8, NULL, 0);
- else if (!strncmp(a, "--active-branches=", 18))
+ else if (!prefixcmp(a, "--active-branches="))
max_active_branches = strtoul(a + 18, NULL, 0);
- else if (!strncmp(a, "--export-marks=", 15))
+ else if (!prefixcmp(a, "--export-marks="))
mark_file = a + 15;
- else if (!strncmp(a, "--export-pack-edges=", 20)) {
+ else if (!prefixcmp(a, "--export-pack-edges=")) {
if (pack_edges)
fclose(pack_edges);
pack_edges = fopen(a + 20, "a");
break;
else if (!strcmp("blob", command_buf.buf))
cmd_new_blob();
- else if (!strncmp("commit ", command_buf.buf, 7))
+ else if (!prefixcmp(command_buf.buf, "commit "))
cmd_new_commit();
- else if (!strncmp("tag ", command_buf.buf, 4))
+ else if (!prefixcmp(command_buf.buf, "tag "))
cmd_new_tag();
- else if (!strncmp("reset ", command_buf.buf, 6))
+ else if (!prefixcmp(command_buf.buf, "reset "))
cmd_reset_branch();
else if (!strcmp("checkpoint", command_buf.buf))
cmd_checkpoint();
fprintf(stderr, "%s statistics:\n", argv[0]);
fprintf(stderr, "---------------------------------------------------------------------\n");
- fprintf(stderr, "Alloc'd objects: " UM10_FMT "\n", alloc_count);
- fprintf(stderr, "Total objects: " UM10_FMT " (" UM10_FMT " duplicates )\n", total_count, duplicate_count);
- fprintf(stderr, " blobs : " UM10_FMT " (" UM10_FMT " duplicates " UM10_FMT " deltas)\n", object_count_by_type[OBJ_BLOB], duplicate_count_by_type[OBJ_BLOB], delta_count_by_type[OBJ_BLOB]);
- fprintf(stderr, " trees : " UM10_FMT " (" UM10_FMT " duplicates " UM10_FMT " deltas)\n", object_count_by_type[OBJ_TREE], duplicate_count_by_type[OBJ_TREE], delta_count_by_type[OBJ_TREE]);
- fprintf(stderr, " commits: " UM10_FMT " (" UM10_FMT " duplicates " UM10_FMT " deltas)\n", object_count_by_type[OBJ_COMMIT], duplicate_count_by_type[OBJ_COMMIT], delta_count_by_type[OBJ_COMMIT]);
- fprintf(stderr, " tags : " UM10_FMT " (" UM10_FMT " duplicates " UM10_FMT " deltas)\n", object_count_by_type[OBJ_TAG], duplicate_count_by_type[OBJ_TAG], delta_count_by_type[OBJ_TAG]);
+ fprintf(stderr, "Alloc'd objects: %10" PRIuMAX "\n", alloc_count);
+ fprintf(stderr, "Total objects: %10" PRIuMAX " (%10" PRIuMAX " duplicates )\n", total_count, duplicate_count);
+ fprintf(stderr, " blobs : %10" PRIuMAX " (%10" PRIuMAX " duplicates %10" PRIuMAX " deltas)\n", object_count_by_type[OBJ_BLOB], duplicate_count_by_type[OBJ_BLOB], delta_count_by_type[OBJ_BLOB]);
+ fprintf(stderr, " trees : %10" PRIuMAX " (%10" PRIuMAX " duplicates %10" PRIuMAX " deltas)\n", object_count_by_type[OBJ_TREE], duplicate_count_by_type[OBJ_TREE], delta_count_by_type[OBJ_TREE]);
+ fprintf(stderr, " commits: %10" PRIuMAX " (%10" PRIuMAX " duplicates %10" PRIuMAX " deltas)\n", object_count_by_type[OBJ_COMMIT], duplicate_count_by_type[OBJ_COMMIT], delta_count_by_type[OBJ_COMMIT]);
+ fprintf(stderr, " tags : %10" PRIuMAX " (%10" PRIuMAX " duplicates %10" PRIuMAX " deltas)\n", object_count_by_type[OBJ_TAG], duplicate_count_by_type[OBJ_TAG], delta_count_by_type[OBJ_TAG]);
fprintf(stderr, "Total branches: %10lu (%10lu loads )\n", branch_count, branch_load_count);
- fprintf(stderr, " marks: " UM10_FMT " (" UM10_FMT " unique )\n", (((uintmax_t)1) << marks->shift) * 1024, marks_set_count);
+ fprintf(stderr, " marks: %10" PRIuMAX " (%10" PRIuMAX " unique )\n", (((uintmax_t)1) << marks->shift) * 1024, marks_set_count);
fprintf(stderr, " atoms: %10u\n", atom_cnt);
- fprintf(stderr, "Memory total: " UM10_FMT " KiB\n", (total_allocd + alloc_count*sizeof(struct object_entry))/1024);
+ fprintf(stderr, "Memory total: %10" PRIuMAX " KiB\n", (total_allocd + alloc_count*sizeof(struct object_entry))/1024);
fprintf(stderr, " pools: %10lu KiB\n", (unsigned long)(total_allocd/1024));
- fprintf(stderr, " objects: " UM10_FMT " KiB\n", (alloc_count*sizeof(struct object_entry))/1024);
+ fprintf(stderr, " objects: %10" PRIuMAX " KiB\n", (alloc_count*sizeof(struct object_entry))/1024);
fprintf(stderr, "---------------------------------------------------------------------\n");
pack_report();
fprintf(stderr, "---------------------------------------------------------------------\n");