ref-filter: avoid using `unsigned long` for catch-all data type

In its `atom_value` struct, the ref-filter source code wants to store different values in a field called `ul` (for `unsigned long`), e.g. timestamps. However, as we are about to switch the data type of timestamps away from `unsigned long` (because it may be 32-bit even when `time_t` is 64-bit), that data type is not large enough. Simply change that field to use `uintmax_t` instead. This patch is a bit larger than the mere change of the data type because the field's name was tied to its data type, which has been fixed at the same time. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Apr 20, 2017 at 22:52 UTC e467dc148d0375ed83300589281f749fcbdd690d
1 file changed +8 -8
ref-filter.c
+8 -8
@@ -351,7 +351,7 @@ struct ref_formatting_state {
351 struct atom_value {
352 const char *s;
353 void (*handler)(struct atom_value *atomv, struct ref_formatting_state *state);
354 - unsigned long ul; /* used for sorting when not FIELD_STR */
354 + uintmax_t value; /* used for sorting when not FIELD_STR */
355 struct used_atom *atom;
356 };
357
@@ -723,7 +723,7 @@ static void grab_common_values(struct atom_value *val, int deref, struct object
723 if (!strcmp(name, "objecttype"))
724 v->s = typename(obj->type);
725 else if (!strcmp(name, "objectsize")) {
726 - v->ul = sz;
726 + v->value = sz;
727 v->s = xstrfmt("%lu", sz);
728 }
729 else if (deref)
@@ -770,8 +770,8 @@ static void grab_commit_values(struct atom_value *val, int deref, struct object
770 v->s = xstrdup(oid_to_hex(&commit->tree->object.oid));
771 }
772 else if (!strcmp(name, "numparent")) {
773 - v->ul = commit_list_count(commit->parents);
774 - v->s = xstrfmt("%lu", v->ul);
773 + v->value = commit_list_count(commit->parents);
774 + v->s = xstrfmt("%lu", (unsigned long)v->value);
775 }
776 else if (!strcmp(name, "parent")) {
777 struct commit_list *parents;
@@ -875,11 +875,11 @@ static void grab_date(const char *buf, struct atom_value *v, const char *atomnam
875 if ((tz == LONG_MIN || tz == LONG_MAX) && errno == ERANGE)
876 goto bad;
877 v->s = xstrdup(show_date(timestamp, tz, &date_mode));
878 - v->ul = timestamp;
878 + v->value = timestamp;
879 return;
880 bad:
881 v->s = "";
882 - v->ul = 0;
882 + v->value = 0;
883 }
884
885 /* See grab_values */
@@ -1941,9 +1941,9 @@ static int cmp_ref_sorting(struct ref_sorting *s, struct ref_array_item *a, stru
1941 else if (cmp_type == FIELD_STR)
1942 cmp = cmp_fn(va->s, vb->s);
1943 else {
1944 - if (va->ul < vb->ul)
1944 + if (va->value < vb->value)
1945 cmp = -1;
1946 - else if (va->ul == vb->ul)
1946 + else if (va->value == vb->value)
1947 cmp = cmp_fn(a->refname, b->refname);
1948 else
1949 cmp = 1;