Skip to content

Commit b2c4031

Browse files
committed
date: make it a proper git_date utility class
Instead of `git__date`, just use `git_date`.
1 parent 1604be0 commit b2c4031

File tree

7 files changed

+47
-32
lines changed

7 files changed

+47
-32
lines changed

src/date.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,7 @@ static git_time_t approxidate_str(const char *date,
857857
return update_tm(&tm, &now, 0);
858858
}
859859

860-
int git__date_parse(git_time_t *out, const char *date)
860+
int git_date_parse(git_time_t *out, const char *date)
861861
{
862862
time_t time_sec;
863863
git_time_t timestamp;
@@ -875,7 +875,7 @@ int git__date_parse(git_time_t *out, const char *date)
875875
return error_ret;
876876
}
877877

878-
int git__date_rfc2822_fmt(char *out, size_t len, const git_time *date)
878+
int git_date_rfc2822_fmt(char *out, size_t len, const git_time *date)
879879
{
880880
int written;
881881
struct tm gmt;

src/date.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (C) the libgit2 contributors. All rights reserved.
3+
*
4+
* This file is part of libgit2, distributed under the GNU GPL v2 with
5+
* a Linking Exception. For full terms see the included COPYING file.
6+
*/
7+
#ifndef INCLUDE_date_h__
8+
#define INCLUDE_date_h__
9+
10+
#include "util.h"
11+
#include "str.h"
12+
13+
/*
14+
* Parse a string into a value as a git_time_t.
15+
*
16+
* Sample valid input:
17+
* - "yesterday"
18+
* - "July 17, 2003"
19+
* - "2003-7-17 08:23"
20+
*/
21+
extern int git_date_parse(git_time_t *out, const char *date);
22+
23+
/*
24+
* Format a git_time as a RFC2822 string
25+
*
26+
* @param out buffer to store formatted date; a '\\0' terminator will automatically be added.
27+
* @param len size of the buffer; should be atleast `GIT_DATE_RFC2822_SZ` in size;
28+
* @param date the date to be formatted
29+
* @return 0 if successful; -1 on error
30+
*/
31+
extern int git_date_rfc2822_fmt(char *out, size_t len, const git_time *date);
32+
33+
#endif

src/email.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "diff_generate.h"
1313
#include "diff_stats.h"
1414
#include "patch.h"
15+
#include "date.h"
1516

1617
#include "git2/email.h"
1718
#include "git2/patch.h"
@@ -123,7 +124,7 @@ static int append_header(
123124
if ((error = git_oid_fmt(id, commit_id)) < 0 ||
124125
(error = git_str_printf(out, "From %.*s %s\n", GIT_OID_HEXSZ, id, EMAIL_TIMESTAMP)) < 0 ||
125126
(error = git_str_printf(out, "From: %s <%s>\n", author->name, author->email)) < 0 ||
126-
(error = git__date_rfc2822_fmt(date, sizeof(date), &author->when)) < 0 ||
127+
(error = git_date_rfc2822_fmt(date, sizeof(date), &author->when)) < 0 ||
127128
(error = git_str_printf(out, "Date: %s\n", date)) < 0 ||
128129
(error = append_subject(out, patch_idx, patch_count, summary, opts)) < 0)
129130
return error;

src/revparse.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "tree.h"
1212
#include "refdb.h"
1313
#include "regexp.h"
14+
#include "date.h"
1415

1516
#include "git2.h"
1617

@@ -344,7 +345,7 @@ static int handle_at_syntax(git_object **out, git_reference **ref, const char *s
344345
goto cleanup;
345346
}
346347

347-
if (git__date_parse(&timestamp, curly_braces_content) < 0)
348+
if (git_date_parse(&timestamp, curly_braces_content) < 0)
348349
goto cleanup;
349350

350351
error = retrieve_revobject_from_reflog(out, ref, repo, git_str_cstr(&identifier), (size_t)timestamp);

src/util.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -294,26 +294,6 @@ GIT_INLINE(bool) git__isxdigit(int c)
294294
*/
295295
extern int git__parse_bool(int *out, const char *value);
296296

297-
/*
298-
* Parse a string into a value as a git_time_t.
299-
*
300-
* Sample valid input:
301-
* - "yesterday"
302-
* - "July 17, 2003"
303-
* - "2003-7-17 08:23"
304-
*/
305-
extern int git__date_parse(git_time_t *out, const char *date);
306-
307-
/*
308-
* Format a git_time as a RFC2822 string
309-
*
310-
* @param out buffer to store formatted date; a '\\0' terminator will automatically be added.
311-
* @param len size of the buffer; should be atleast `GIT_DATE_RFC2822_SZ` in size;
312-
* @param date the date to be formatted
313-
* @return 0 if successful; -1 on error
314-
*/
315-
extern int git__date_rfc2822_fmt(char *out, size_t len, const git_time *date);
316-
317297
/*
318298
* Unescapes a string in-place.
319299
*

tests/date/date.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#include "clar_libgit2.h"
22

3-
#include "util.h"
3+
#include "date.h"
44

55
void test_date_date__overflow(void)
66
{
77
#ifdef __LP64__
88
git_time_t d2038, d2039;
99

1010
/* This is expected to fail on a 32-bit machine. */
11-
cl_git_pass(git__date_parse(&d2038, "2038-1-1"));
12-
cl_git_pass(git__date_parse(&d2039, "2039-1-1"));
11+
cl_git_pass(git_date_parse(&d2038, "2038-1-1"));
12+
cl_git_pass(git_date_parse(&d2039, "2039-1-1"));
1313
cl_assert(d2038 < d2039);
1414
#endif
1515
}

tests/date/rfc2822.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#include "clar_libgit2.h"
22

3-
#include "util.h"
3+
#include "date.h"
44

55
void test_date_rfc2822__format_rfc2822_no_offset(void)
66
{
77
git_time t = {1397031663, 0};
88
char buf[GIT_DATE_RFC2822_SZ];
99

10-
cl_git_pass(git__date_rfc2822_fmt(buf, sizeof(buf), &t));
10+
cl_git_pass(git_date_rfc2822_fmt(buf, sizeof(buf), &t));
1111
cl_assert(strcmp(buf, "Wed, 9 Apr 2014 08:21:03 +0000") == 0);
1212
}
1313

@@ -16,7 +16,7 @@ void test_date_rfc2822__format_rfc2822_positive_offset(void)
1616
git_time t = {1397031663, 120};
1717
char buf[GIT_DATE_RFC2822_SZ];
1818

19-
cl_git_pass(git__date_rfc2822_fmt(buf, sizeof(buf), &t));
19+
cl_git_pass(git_date_rfc2822_fmt(buf, sizeof(buf), &t));
2020
cl_assert(strcmp(buf, "Wed, 9 Apr 2014 10:21:03 +0200") == 0);
2121
}
2222

@@ -25,7 +25,7 @@ void test_date_rfc2822__format_rfc2822_negative_offset(void)
2525
git_time t = {1397031663, -120};
2626
char buf[GIT_DATE_RFC2822_SZ];
2727

28-
cl_git_pass(git__date_rfc2822_fmt(buf, sizeof(buf), &t));
28+
cl_git_pass(git_date_rfc2822_fmt(buf, sizeof(buf), &t));
2929
cl_assert(strcmp(buf, "Wed, 9 Apr 2014 06:21:03 -0200") == 0);
3030
}
3131

@@ -35,6 +35,6 @@ void test_date_rfc2822__format_rfc2822_buffer_too_small(void)
3535
git_time t = {1397031663 + 86400, 0};
3636
char buf[GIT_DATE_RFC2822_SZ-1];
3737

38-
cl_git_fail(git__date_rfc2822_fmt(buf, sizeof(buf), &t));
38+
cl_git_fail(git_date_rfc2822_fmt(buf, sizeof(buf), &t));
3939
}
4040

0 commit comments

Comments
 (0)