All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Obey NO_C99_FORMAT in fast-import.c.
@ 2007-02-20  0:27 Jason Riedy
  2007-02-20 12:57 ` Simon 'corecode' Schubert
  0 siblings, 1 reply; 3+ messages in thread
From: Jason Riedy @ 2007-02-20  0:27 UTC (permalink / raw)
  To: git

Define UM_FMT and UM10_FMT and use in place of %ju and %10ju,
respectively.  Both format as unsigned long long, so this
assumes the compiler supports long long.

Signed-off-by: Jason Riedy <jason@acm.org>
---
   If there's need, I could add a NO_LONGLONG.

 fast-import.c |   37 +++++++++++++++++++++++--------------
 1 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/fast-import.c b/fast-import.c
index 404d911..ad32300 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -133,6 +133,15 @@ Format of STDIN stream:
 #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"
+#endif
+
 struct object_entry
 {
 	struct object_entry *next;
@@ -475,7 +484,7 @@ static struct object_entry *find_mark(uintmax_t idnum)
 			oe = s->data.marked[idnum];
 	}
 	if (!oe)
-		die("mark :%ju not declared", orig_idnum);
+		die("mark :" UM_FMT " not declared", orig_idnum);
 	return oe;
 }
 
@@ -1361,7 +1370,7 @@ static void dump_marks_helper(FILE *f,
 	} else {
 		for (k = 0; k < 1024; k++) {
 			if (m->data.marked[k])
-				fprintf(f, ":%ju %s\n", base + k,
+				fprintf(f, ":" UM_FMT " %s\n", base + k,
 					sha1_to_hex(m->data.marked[k]->sha1));
 		}
 	}
@@ -1687,7 +1696,7 @@ static void cmd_from(struct branch *b)
 		unsigned long size;
 		char *buf;
 		if (oe->type != OBJ_COMMIT)
-			die("Mark :%ju not a commit", idnum);
+			die("Mark :" UM_FMT " not a commit", idnum);
 		hashcpy(b->sha1, oe->sha1);
 		buf = gfi_unpack_entry(oe, &size);
 		if (!buf || size < 46)
@@ -1740,7 +1749,7 @@ static struct hash_list *cmd_merge(unsigned int *count)
 			uintmax_t idnum = strtoumax(from + 1, NULL, 10);
 			struct object_entry *oe = find_mark(idnum);
 			if (oe->type != OBJ_COMMIT)
-				die("Mark :%ju not a commit", idnum);
+				die("Mark :" UM_FMT " 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);
@@ -1884,7 +1893,7 @@ static void cmd_new_tag(void)
 		from_mark = strtoumax(from + 1, NULL, 10);
 		oe = find_mark(from_mark);
 		if (oe->type != OBJ_COMMIT)
-			die("Mark :%ju not a commit", from_mark);
+			die("Mark :" UM_FMT " not a commit", from_mark);
 		hashcpy(sha1, oe->sha1);
 	} else if (!get_sha1(from, sha1)) {
 		unsigned long size;
@@ -2059,18 +2068,18 @@ int main(int argc, const char **argv)
 
 		fprintf(stderr, "%s statistics:\n", argv[0]);
 		fprintf(stderr, "---------------------------------------------------------------------\n");
-		fprintf(stderr, "Alloc'd objects: %10ju\n", alloc_count);
-		fprintf(stderr, "Total objects:   %10ju (%10ju duplicates                  )\n", total_count, duplicate_count);
-		fprintf(stderr, "      blobs  :   %10ju (%10ju duplicates %10ju deltas)\n", object_count_by_type[OBJ_BLOB], duplicate_count_by_type[OBJ_BLOB], delta_count_by_type[OBJ_BLOB]);
-		fprintf(stderr, "      trees  :   %10ju (%10ju duplicates %10ju deltas)\n", object_count_by_type[OBJ_TREE], duplicate_count_by_type[OBJ_TREE], delta_count_by_type[OBJ_TREE]);
-		fprintf(stderr, "      commits:   %10ju (%10ju duplicates %10ju deltas)\n", object_count_by_type[OBJ_COMMIT], duplicate_count_by_type[OBJ_COMMIT], delta_count_by_type[OBJ_COMMIT]);
-		fprintf(stderr, "      tags   :   %10ju (%10ju duplicates %10ju 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: " 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, "Total branches:  %10lu (%10lu loads     )\n", branch_count, branch_load_count);
-		fprintf(stderr, "      marks:     %10ju (%10ju unique    )\n", (((uintmax_t)1) << marks->shift) * 1024, marks_set_count);
+		fprintf(stderr, "      marks:     " UM10_FMT " (" UM10_FMT " unique    )\n", (((uintmax_t)1) << marks->shift) * 1024, marks_set_count);
 		fprintf(stderr, "      atoms:     %10u\n", atom_cnt);
-		fprintf(stderr, "Memory total:    %10ju KiB\n", (total_allocd + alloc_count*sizeof(struct object_entry))/1024);
+		fprintf(stderr, "Memory total:    " UM10_FMT " 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:    %10ju KiB\n", (alloc_count*sizeof(struct object_entry))/1024);
+		fprintf(stderr, "     objects:    " UM10_FMT " KiB\n", (alloc_count*sizeof(struct object_entry))/1024);
 		fprintf(stderr, "---------------------------------------------------------------------\n");
 		pack_report();
 		fprintf(stderr, "---------------------------------------------------------------------\n");
-- 
1.5.0.rc1.g6f729

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] Obey NO_C99_FORMAT in fast-import.c.
  2007-02-20  0:27 [PATCH] Obey NO_C99_FORMAT in fast-import.c Jason Riedy
@ 2007-02-20 12:57 ` Simon 'corecode' Schubert
  0 siblings, 0 replies; 3+ messages in thread
From: Simon 'corecode' Schubert @ 2007-02-20 12:57 UTC (permalink / raw)
  To: Jason Riedy; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 1480 bytes --]

Jason Riedy wrote:
> Define UM_FMT and UM10_FMT and use in place of %ju and %10ju,
> respectively.  Both format as unsigned long long, so this
> assumes the compiler supports long long.

So there are really systems which do not support the "j" (standardized) size modifier, but support "long long" (unstandardized) integers?  Oh my.

> +#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"
> +#endif

I think this should read something like

#ifndef PRIuMAX
#define PRIuMAX		"llu"	/* Assumes unsigned long long exists */
#endif

After all, these macros are standardized (<inttypes.h>)

Hunks like this should of course read differently then:

> -		die("mark :%ju not declared", orig_idnum);
> +		die("mark :" UM_FMT " not declared", orig_idnum);

die("mark :%"PRIuMAX" not declared", orig_idnum);

> +		fprintf(stderr, "Alloc'd objects: " UM10_FMT "\n", alloc_count);

And then this UM10_FMT stunt isn't needed either:

fprintf(stderr, "Alloc'd objects: %10"PRIuMAX"\n", alloc_count);

cheers
  simon

-- 
Serve - BSD     +++  RENT this banner advert  +++    ASCII Ribbon   /"\
Work - Mac      +++  space for low €€€ NOW!1  +++      Campaign     \ /
Party Enjoy Relax   |   http://dragonflybsd.org      Against  HTML   \
Dude 2c 2 the max   !   http://golden-apple.biz       Mail + News   / \


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 252 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Obey NO_C99_FORMAT in fast-import.c.
@ 2007-02-20 20:17 Jason Riedy
  0 siblings, 0 replies; 3+ messages in thread
From: Jason Riedy @ 2007-02-20 20:17 UTC (permalink / raw)
  To: Simon 'corecode' Schubert; +Cc: git

And Simon 'corecode' Schubert writes:
> I think this should read something like
> 
> #ifndef PRIuMAX
> #define PRIuMAX		"llu"	/* Assumes unsigned long long exists */
> #endif

You're right, that's much cleaner.  I'll try it and test it.
(Takes many hours to run a test on this poor machine, so the
patch won't be sent until tomorrow.)

Jason

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-02-20 20:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-20  0:27 [PATCH] Obey NO_C99_FORMAT in fast-import.c Jason Riedy
2007-02-20 12:57 ` Simon 'corecode' Schubert
2007-02-20 20:17 Jason Riedy

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.