date: make it a proper `git_date` utility class Instead of `git__date`, just use `git_date`.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
diff --git a/src/date.c b/src/date.c
index 2297ee6..f7498e7 100644
--- a/src/date.c
+++ b/src/date.c
@@ -857,7 +857,7 @@ static git_time_t approxidate_str(const char *date,
return update_tm(&tm, &now, 0);
}
-int git__date_parse(git_time_t *out, const char *date)
+int git_date_parse(git_time_t *out, const char *date)
{
time_t time_sec;
git_time_t timestamp;
@@ -875,7 +875,7 @@ int git__date_parse(git_time_t *out, const char *date)
return error_ret;
}
-int git__date_rfc2822_fmt(char *out, size_t len, const git_time *date)
+int git_date_rfc2822_fmt(char *out, size_t len, const git_time *date)
{
int written;
struct tm gmt;
diff --git a/src/date.h b/src/date.h
new file mode 100644
index 0000000..133f20b
--- /dev/null
+++ b/src/date.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
+#ifndef INCLUDE_date_h__
+#define INCLUDE_date_h__
+
+#include "util.h"
+#include "str.h"
+
+/*
+ * Parse a string into a value as a git_time_t.
+ *
+ * Sample valid input:
+ * - "yesterday"
+ * - "July 17, 2003"
+ * - "2003-7-17 08:23"
+ */
+extern int git_date_parse(git_time_t *out, const char *date);
+
+/*
+ * Format a git_time as a RFC2822 string
+ *
+ * @param out buffer to store formatted date; a '\\0' terminator will automatically be added.
+ * @param len size of the buffer; should be atleast `GIT_DATE_RFC2822_SZ` in size;
+ * @param date the date to be formatted
+ * @return 0 if successful; -1 on error
+ */
+extern int git_date_rfc2822_fmt(char *out, size_t len, const git_time *date);
+
+#endif
diff --git a/src/email.c b/src/email.c
index 3459c05..66ed2dd 100644
--- a/src/email.c
+++ b/src/email.c
@@ -12,6 +12,7 @@
#include "diff_generate.h"
#include "diff_stats.h"
#include "patch.h"
+#include "date.h"
#include "git2/email.h"
#include "git2/patch.h"
@@ -123,7 +124,7 @@ static int append_header(
if ((error = git_oid_fmt(id, commit_id)) < 0 ||
(error = git_str_printf(out, "From %.*s %s\n", GIT_OID_HEXSZ, id, EMAIL_TIMESTAMP)) < 0 ||
(error = git_str_printf(out, "From: %s <%s>\n", author->name, author->email)) < 0 ||
- (error = git__date_rfc2822_fmt(date, sizeof(date), &author->when)) < 0 ||
+ (error = git_date_rfc2822_fmt(date, sizeof(date), &author->when)) < 0 ||
(error = git_str_printf(out, "Date: %s\n", date)) < 0 ||
(error = append_subject(out, patch_idx, patch_count, summary, opts)) < 0)
return error;
diff --git a/src/revparse.c b/src/revparse.c
index cf39936..52dd072 100644
--- a/src/revparse.c
+++ b/src/revparse.c
@@ -11,6 +11,7 @@
#include "tree.h"
#include "refdb.h"
#include "regexp.h"
+#include "date.h"
#include "git2.h"
@@ -344,7 +345,7 @@ static int handle_at_syntax(git_object **out, git_reference **ref, const char *s
goto cleanup;
}
- if (git__date_parse(×tamp, curly_braces_content) < 0)
+ if (git_date_parse(×tamp, curly_braces_content) < 0)
goto cleanup;
error = retrieve_revobject_from_reflog(out, ref, repo, git_str_cstr(&identifier), (size_t)timestamp);
diff --git a/src/util.h b/src/util.h
index 30cdd0d..3d6ee12 100644
--- a/src/util.h
+++ b/src/util.h
@@ -295,26 +295,6 @@ GIT_INLINE(bool) git__isxdigit(int c)
extern int git__parse_bool(int *out, const char *value);
/*
- * Parse a string into a value as a git_time_t.
- *
- * Sample valid input:
- * - "yesterday"
- * - "July 17, 2003"
- * - "2003-7-17 08:23"
- */
-extern int git__date_parse(git_time_t *out, const char *date);
-
-/*
- * Format a git_time as a RFC2822 string
- *
- * @param out buffer to store formatted date; a '\\0' terminator will automatically be added.
- * @param len size of the buffer; should be atleast `GIT_DATE_RFC2822_SZ` in size;
- * @param date the date to be formatted
- * @return 0 if successful; -1 on error
- */
-extern int git__date_rfc2822_fmt(char *out, size_t len, const git_time *date);
-
-/*
* Unescapes a string in-place.
*
* Edge cases behavior:
diff --git a/tests/date/date.c b/tests/date/date.c
index 88881d1..f70b4fe 100644
--- a/tests/date/date.c
+++ b/tests/date/date.c
@@ -1,6 +1,6 @@
#include "clar_libgit2.h"
-#include "util.h"
+#include "date.h"
void test_date_date__overflow(void)
{
@@ -8,8 +8,8 @@ void test_date_date__overflow(void)
git_time_t d2038, d2039;
/* This is expected to fail on a 32-bit machine. */
- cl_git_pass(git__date_parse(&d2038, "2038-1-1"));
- cl_git_pass(git__date_parse(&d2039, "2039-1-1"));
+ cl_git_pass(git_date_parse(&d2038, "2038-1-1"));
+ cl_git_pass(git_date_parse(&d2039, "2039-1-1"));
cl_assert(d2038 < d2039);
#endif
}
diff --git a/tests/date/rfc2822.c b/tests/date/rfc2822.c
index d98c1f0..c94c840 100644
--- a/tests/date/rfc2822.c
+++ b/tests/date/rfc2822.c
@@ -1,13 +1,13 @@
#include "clar_libgit2.h"
-#include "util.h"
+#include "date.h"
void test_date_rfc2822__format_rfc2822_no_offset(void)
{
git_time t = {1397031663, 0};
char buf[GIT_DATE_RFC2822_SZ];
- cl_git_pass(git__date_rfc2822_fmt(buf, sizeof(buf), &t));
+ cl_git_pass(git_date_rfc2822_fmt(buf, sizeof(buf), &t));
cl_assert(strcmp(buf, "Wed, 9 Apr 2014 08:21:03 +0000") == 0);
}
@@ -16,7 +16,7 @@ void test_date_rfc2822__format_rfc2822_positive_offset(void)
git_time t = {1397031663, 120};
char buf[GIT_DATE_RFC2822_SZ];
- cl_git_pass(git__date_rfc2822_fmt(buf, sizeof(buf), &t));
+ cl_git_pass(git_date_rfc2822_fmt(buf, sizeof(buf), &t));
cl_assert(strcmp(buf, "Wed, 9 Apr 2014 10:21:03 +0200") == 0);
}
@@ -25,7 +25,7 @@ void test_date_rfc2822__format_rfc2822_negative_offset(void)
git_time t = {1397031663, -120};
char buf[GIT_DATE_RFC2822_SZ];
- cl_git_pass(git__date_rfc2822_fmt(buf, sizeof(buf), &t));
+ cl_git_pass(git_date_rfc2822_fmt(buf, sizeof(buf), &t));
cl_assert(strcmp(buf, "Wed, 9 Apr 2014 06:21:03 -0200") == 0);
}
@@ -35,6 +35,6 @@ void test_date_rfc2822__format_rfc2822_buffer_too_small(void)
git_time t = {1397031663 + 86400, 0};
char buf[GIT_DATE_RFC2822_SZ-1];
- cl_git_fail(git__date_rfc2822_fmt(buf, sizeof(buf), &t));
+ cl_git_fail(git_date_rfc2822_fmt(buf, sizeof(buf), &t));
}