]> git.ipfire.org Git - thirdparty/git.git/commitdiff
date API: create a date.h, split from cache.h
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Wed, 16 Feb 2022 08:14:02 +0000 (09:14 +0100)
committerJunio C Hamano <gitster@pobox.com>
Wed, 16 Feb 2022 17:40:00 +0000 (09:40 -0800)
Move the declaration of the date.c functions from cache.h, and adjust
the relevant users to include the new date.h header.

The show_ident_date() function belonged in pretty.h (it's defined in
pretty.c), its two users outside of pretty.c didn't strictly need to
include pretty.h, as they get it indirectly, but let's add it to them
anyway.

Similarly, the change to "builtin/{fast-import,show-branch,tag}.c"
isn't needed as far as the compiler is concerned, but since they all
use the "DATE_MODE()" macro we now define in date.h, let's have them
include it.

We could simply include this new header in "cache.h", but as this
change shows these functions weren't common enough to warrant
including in it in the first place. By moving them out of cache.h
changes to this API will no longer cause a (mostly) full re-build of
the project when "make" is run.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
18 files changed:
archive-zip.c
builtin/am.c
builtin/commit.c
builtin/fast-import.c
builtin/show-branch.c
builtin/tag.c
cache.h
config.c
date.c
date.h [new file with mode: 0644]
http-backend.c
ident.c
object-name.c
pretty.h
reflog-walk.h
refs.c
strbuf.c
t/helper/test-date.c

index 2961e01c754fc4641af62f7d45e63458eb4f942d..8ea9d1a5dae0c4ecabd13886885e391ebeb3c7da 100644 (file)
@@ -9,6 +9,7 @@
 #include "object-store.h"
 #include "userdiff.h"
 #include "xdiff-interface.h"
+#include "date.h"
 
 static int zip_date;
 static int zip_time;
index 7de2c89ef22c7f9a4292f34ddb3278547791ebeb..eb24bc89bb57fbe16ad9f0d2c98a766c560ab748 100644 (file)
@@ -34,6 +34,7 @@
 #include "string-list.h"
 #include "packfile.h"
 #include "repository.h"
+#include "pretty.h"
 
 /**
  * Returns the length of the first line of msg.
index b9ed0374e301ae958906435fa6592e9d3bbe52fa..6b99ac276d8b5bf55756284c21c506f251a88b8d 100644 (file)
@@ -37,6 +37,7 @@
 #include "help.h"
 #include "commit-reach.h"
 #include "commit-graph.h"
+#include "pretty.h"
 
 static const char * const builtin_commit_usage[] = {
        N_("git commit [<options>] [--] <pathspec>..."),
index 2b2e28bad79cbaef25b4eb8fea4c0f800ba4a89d..28f2b9cc91f8fcfe4917ad03bbf2f56e9d642260 100644 (file)
@@ -19,6 +19,7 @@
 #include "mem-pool.h"
 #include "commit-reach.h"
 #include "khash.h"
+#include "date.h"
 
 #define PACK_ID_BITS 16
 #define MAX_PACK_ID ((1<<PACK_ID_BITS)-1)
index e12c5e80e3e4425831b9803c334245eaedf3bd9a..330b0553b9d72d9befb0ecf1f3c58540b6f26877 100644 (file)
@@ -8,6 +8,7 @@
 #include "parse-options.h"
 #include "dir.h"
 #include "commit-slab.h"
+#include "date.h"
 
 static const char* show_branch_usage[] = {
     N_("git show-branch [-a | --all] [-r | --remotes] [--topo-order | --date-order]\n"
index 134b3f1edf06246aed1eed1e5890a27fff22a3bf..2479da07049ace8c64c0461210ab6d77798f73aa 100644 (file)
@@ -20,6 +20,7 @@
 #include "oid-array.h"
 #include "column.h"
 #include "ref-filter.h"
+#include "date.h"
 
 static const char * const git_tag_usage[] = {
        N_("git tag [-a | -s | -u <key-id>] [-f] [-m <msg> | -F <file>]\n"
diff --git a/cache.h b/cache.h
index 703a474e5a737db0cca1d8396f361ead8f4d2f14..48e77aa06977b46126e25b1cbc26f3d0b8916771 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -1559,46 +1559,6 @@ struct object *repo_peel_to_type(struct repository *r,
 #define peel_to_type(name, namelen, obj, type) \
        repo_peel_to_type(the_repository, name, namelen, obj, type)
 
-enum date_mode_type {
-       DATE_NORMAL = 0,
-       DATE_HUMAN,
-       DATE_RELATIVE,
-       DATE_SHORT,
-       DATE_ISO8601,
-       DATE_ISO8601_STRICT,
-       DATE_RFC2822,
-       DATE_STRFTIME,
-       DATE_RAW,
-       DATE_UNIX
-};
-
-struct date_mode {
-       enum date_mode_type type;
-       const char *strftime_fmt;
-       int local;
-};
-
-/*
- * Convenience helper for passing a constant type, like:
- *
- *   show_date(t, tz, DATE_MODE(NORMAL));
- */
-#define DATE_MODE(t) date_mode_from_type(DATE_##t)
-struct date_mode *date_mode_from_type(enum date_mode_type type);
-
-const char *show_date(timestamp_t time, int timezone, const struct date_mode *mode);
-void show_date_relative(timestamp_t time, struct strbuf *timebuf);
-int parse_date(const char *date, struct strbuf *out);
-int parse_date_basic(const char *date, timestamp_t *timestamp, int *offset);
-int parse_expiry_date(const char *date, timestamp_t *timestamp);
-void datestamp(struct strbuf *out);
-#define approxidate(s) approxidate_careful((s), NULL)
-timestamp_t approxidate_careful(const char *, int *);
-timestamp_t approxidate_relative(const char *date);
-void parse_date_format(const char *format, struct date_mode *mode);
-int date_overflows(timestamp_t date);
-time_t tm_to_time_t(const struct tm *tm);
-
 #define IDENT_STRICT          1
 #define IDENT_NO_DATE         2
 #define IDENT_NO_NAME         4
@@ -1644,14 +1604,6 @@ struct ident_split {
  */
 int split_ident_line(struct ident_split *, const char *, int);
 
-/*
- * Like show_date, but pull the timestamp and tz parameters from
- * the ident_split. It will also sanity-check the values and produce
- * a well-known sentinel date if they appear bogus.
- */
-const char *show_ident_date(const struct ident_split *id,
-                           const struct date_mode *mode);
-
 /*
  * Compare split idents for equality or strict ordering. Note that we
  * compare only the ident part of the line, ignoring any timestamp.
index e0c03d154c916225d30fd87d7008c91582ac4409..430868f1ec0ec217e9f862a16325cdd3fe539dff 100644 (file)
--- a/config.c
+++ b/config.c
@@ -6,6 +6,7 @@
  *
  */
 #include "cache.h"
+#include "date.h"
 #include "branch.h"
 #include "config.h"
 #include "environment.h"
diff --git a/date.c b/date.c
index 84bb4451c1ae167cfd88ae4a4b936a69b1c9296c..863b07e9e63fb80ec3de71b9338b3a01dcba8655 100644 (file)
--- a/date.c
+++ b/date.c
@@ -5,6 +5,7 @@
  */
 
 #include "cache.h"
+#include "date.h"
 
 /*
  * This is like mktime, but without normalization of tm_wday and tm_yday.
diff --git a/date.h b/date.h
new file mode 100644 (file)
index 0000000..5db9ec8
--- /dev/null
+++ b/date.h
@@ -0,0 +1,43 @@
+#ifndef DATE_H
+#define DATE_H
+
+enum date_mode_type {
+       DATE_NORMAL = 0,
+       DATE_HUMAN,
+       DATE_RELATIVE,
+       DATE_SHORT,
+       DATE_ISO8601,
+       DATE_ISO8601_STRICT,
+       DATE_RFC2822,
+       DATE_STRFTIME,
+       DATE_RAW,
+       DATE_UNIX
+};
+
+struct date_mode {
+       enum date_mode_type type;
+       const char *strftime_fmt;
+       int local;
+};
+
+/*
+ * Convenience helper for passing a constant type, like:
+ *
+ *   show_date(t, tz, DATE_MODE(NORMAL));
+ */
+#define DATE_MODE(t) date_mode_from_type(DATE_##t)
+struct date_mode *date_mode_from_type(enum date_mode_type type);
+
+const char *show_date(timestamp_t time, int timezone, const struct date_mode *mode);
+void show_date_relative(timestamp_t time, struct strbuf *timebuf);
+int parse_date(const char *date, struct strbuf *out);
+int parse_date_basic(const char *date, timestamp_t *timestamp, int *offset);
+int parse_expiry_date(const char *date, timestamp_t *timestamp);
+void datestamp(struct strbuf *out);
+#define approxidate(s) approxidate_careful((s), NULL)
+timestamp_t approxidate_careful(const char *, int *);
+timestamp_t approxidate_relative(const char *date);
+void parse_date_format(const char *format, struct date_mode *mode);
+int date_overflows(timestamp_t date);
+time_t tm_to_time_t(const struct tm *tm);
+#endif
index 807fb8839e7859ca4e9af298f28a74e5bb7455ec..81a7229ece00addacc4b2edce12dc79810c06c02 100644 (file)
@@ -13,6 +13,7 @@
 #include "packfile.h"
 #include "object-store.h"
 #include "protocol.h"
+#include "date.h"
 
 static const char content_type[] = "Content-Type";
 static const char content_length[] = "Content-Length";
diff --git a/ident.c b/ident.c
index 6aba4b5cb6f2cb3bf469f4f9111845a70a0e5031..89ca5b47008ee50749744914dd80a009d9adcaff 100644 (file)
--- a/ident.c
+++ b/ident.c
@@ -7,6 +7,7 @@
  */
 #include "cache.h"
 #include "config.h"
+#include "date.h"
 
 static struct strbuf git_default_name = STRBUF_INIT;
 static struct strbuf git_default_email = STRBUF_INIT;
index 92862eeb1ac74f0a3eeaca91ffac9771331bbf22..060d892a97f775b6be3132c57b8b1e7e0ffb9007 100644 (file)
@@ -15,6 +15,7 @@
 #include "submodule.h"
 #include "midx.h"
 #include "commit-reach.h"
+#include "date.h"
 
 static int get_oid_oneline(struct repository *r, const char *, struct object_id *, struct commit_list *);
 
index 2f16acd213d6d70c6055472f4f4d6b0e3e4b6f9e..f34e24c53a4925aec51cd62117654fdd5f7f980e 100644 (file)
--- a/pretty.h
+++ b/pretty.h
@@ -2,6 +2,7 @@
 #define PRETTY_H
 
 #include "cache.h"
+#include "date.h"
 #include "string-list.h"
 
 struct commit;
@@ -163,4 +164,13 @@ int format_set_trailers_options(struct process_trailer_options *opts,
                        const char **arg,
                        char **invalid_arg);
 
+/*
+ * Like show_date, but pull the timestamp and tz parameters from
+ * the ident_split. It will also sanity-check the values and produce
+ * a well-known sentinel date if they appear bogus.
+ */
+const char *show_ident_date(const struct ident_split *id,
+                           const struct date_mode *mode);
+
+
 #endif /* PRETTY_H */
index f26408f6cc1caffd93949ebc95d74426c2a9db25..e9e00ffd479475a6a887b04ae685a64d3b251db7 100644 (file)
@@ -5,6 +5,7 @@
 
 struct commit;
 struct reflog_walk_info;
+struct date_mode;
 
 void init_reflog_walk(struct reflog_walk_info **info);
 int add_reflog_for_walk(struct reflog_walk_info *info,
diff --git a/refs.c b/refs.c
index 7017ae598041bb1eda4ef5f95a6880be7c54ff71..b74f3815a527b77a34957b4ccb86fdfec533d335 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -19,6 +19,7 @@
 #include "strvec.h"
 #include "repository.h"
 #include "sigchain.h"
+#include "date.h"
 
 /*
  * List of all available backends
index 613fee8c82e0f1682e99b5facee338c5e14cd28a..00abeb55afdd68089676d2007fbfd248b5a45e79 100644 (file)
--- a/strbuf.c
+++ b/strbuf.c
@@ -2,6 +2,7 @@
 #include "refs.h"
 #include "string-list.h"
 #include "utf8.h"
+#include "date.h"
 
 int starts_with(const char *str, const char *prefix)
 {
index 099eff4f0fc880689d06c0b8b6301c3e83dff747..ded3d059f56ddc73982cee3338acc6397399bd56 100644 (file)
@@ -1,5 +1,6 @@
 #include "test-tool.h"
 #include "cache.h"
+#include "date.h"
 
 static const char *usage_msg = "\n"
 "  test-tool date relative [time_t]...\n"