git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Outreachy][PATCH 1/2] date: refactor 64 bit prereq code into reusable functions
@ 2024-02-05 16:25 Achu Luma
  2024-02-05 16:25 ` [Outreachy][PATCH 2/2] Port helper/test-date.c to unit-tests/t-date.c Achu Luma
  2024-02-05 17:34 ` [Outreachy][PATCH 1/2] date: refactor 64 bit prereq code into reusable functions rsbecker
  0 siblings, 2 replies; 10+ messages in thread
From: Achu Luma @ 2024-02-05 16:25 UTC (permalink / raw)
  To: git; +Cc: christian.couder, Achu Luma, Christian Couder

In a following commit we are going to port code from
"t/helper/test-date.c" and "t/t0006-date.sh" to a new
"t/unit-tests/t-date.c" file using the recently added unit test
framework.

We cannot fully port all the code from "t/helper/test-date.c" though, as
the test-tool date helper is still used by a number of "t/*.sh" tests.
The TIME_IS_64BIT and TIME_T_IS_64BIT prereqs are especially used by
"t5000-tar-tree.sh", "t5318-commit-graph.sh" and
"t5328-commit-graph-64bit-time.sh" while checking those prereqs will be
required in the new "t/unit-tests/t-date.c" file too.

To avoid duplicating in both "t/helper/test-date.c" and
"t/unit-tests/t-date.c" the small amount of code checking these prereqs,
let's move it into inline functions in "date.h".

The names of these new inline functions contain "TIME_IS_64BIT" or
"TIME_T_IS_64BIT" as it will simplify the macros we will use when
we will port code to "t/unit-tests/t-date.c" in a following commit.

Mentored-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Achu Luma <ach.lumap@gmail.com>
---
 date.h               | 6 ++++++
 t/helper/test-date.c | 4 ++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/date.h b/date.h
index 6136212a19..fb70490a51 100644
--- a/date.h
+++ b/date.h
@@ -70,4 +70,10 @@ void datestamp(struct strbuf *out);
 timestamp_t approxidate_careful(const char *, int *);
 int date_overflows(timestamp_t date);
 time_t tm_to_time_t(const struct tm *tm);
+static inline int check_prereq_TIME_IS_64BIT(void) {
+	return sizeof(timestamp_t) == 8;
+}
+static inline int check_prereq_TIME_T_IS_64BIT(void) {
+	return sizeof(time_t) == 8;
+}
 #endif
diff --git a/t/helper/test-date.c b/t/helper/test-date.c
index 0683d46574..be0b8679c3 100644
--- a/t/helper/test-date.c
+++ b/t/helper/test-date.c
@@ -126,9 +126,9 @@ int cmd__date(int argc UNUSED, const char **argv)
 	else if (!strcmp(*argv, "getnanos"))
 		getnanos(argv+1);
 	else if (!strcmp(*argv, "is64bit"))
-		return sizeof(timestamp_t) == 8 ? 0 : 1;
+		return !check_prereq_TIME_IS_64BIT();
 	else if (!strcmp(*argv, "time_t-is64bit"))
-		return sizeof(time_t) == 8 ? 0 : 1;
+		return !check_prereq_TIME_T_IS_64BIT();
 	else
 		usage(usage_msg);
 	return 0;
--
2.43.0.windows.1


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

end of thread, other threads:[~2024-06-27  6:49 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-05 16:25 [Outreachy][PATCH 1/2] date: refactor 64 bit prereq code into reusable functions Achu Luma
2024-02-05 16:25 ` [Outreachy][PATCH 2/2] Port helper/test-date.c to unit-tests/t-date.c Achu Luma
2024-03-28 12:35   ` Ghanshyam Thakkar
2024-03-28 16:35     ` Junio C Hamano
2024-05-28 13:20       ` Patrick Steinhardt
2024-05-28 16:41         ` Junio C Hamano
2024-05-29  5:49           ` Patrick Steinhardt
2024-06-27  6:49             ` Johannes Schindelin
2024-02-05 17:34 ` [Outreachy][PATCH 1/2] date: refactor 64 bit prereq code into reusable functions rsbecker
2024-02-06  8:39   ` Christian Couder

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).