From 46176d77c9e0b219a78d64cb99d8dbf4d9bcde2d Mon Sep 17 00:00:00 2001 From: Victoria Dye Date: Thu, 8 Feb 2024 01:57:19 +0000 Subject: ref-filter.c: sort formatted dates by byte value Update the ref sorting functions of 'ref-filter.c' so that when date fields are specified with a format string (such as in 'git for-each-ref --sort=creatordate:'), they are sorted by their formatted string value rather than by the underlying numeric timestamp. Currently, date fields are always sorted by timestamp, regardless of whether formatting information is included in the '--sort' key. Leaving the default (unformatted) date sorting unchanged, sorting by the formatted date string adds some flexibility to 'for-each-ref' by allowing for behavior like "sort by year, then by refname within each year" or "sort by time of day". Because the inclusion of a format string previously had no effect on sort behavior, this change likely will not affect existing usage of 'for-each-ref' or other ref listing commands. Additionally, update documentation & tests to document the new sorting mechanism. Signed-off-by: Victoria Dye Signed-off-by: Junio C Hamano --- ref-filter.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'ref-filter.c') diff --git a/ref-filter.c b/ref-filter.c index 35b989e1df..be14b56e32 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -1611,6 +1611,12 @@ static void grab_date(const char *buf, struct atom_value *v, const char *atomnam if (formatp) { formatp++; parse_date_format(formatp, &date_mode); + + /* + * If this is a sort field and a format was specified, we'll + * want to compare formatted date by string value. + */ + v->atom->type = FIELD_STR; } if (!eoemail) -- cgit v1.2.3