Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
b2c40314
Commit
b2c40314
authored
Nov 18, 2021
by
Edward Thomson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
date: make it a proper `git_date` utility class
Instead of `git__date`, just use `git_date`.
parent
1604be06
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
47 additions
and
32 deletions
+47
-32
src/date.c
+2
-2
src/date.h
+33
-0
src/email.c
+2
-1
src/revparse.c
+2
-1
src/util.h
+0
-20
tests/date/date.c
+3
-3
tests/date/rfc2822.c
+5
-5
No files found.
src/date.c
View file @
b2c40314
...
@@ -857,7 +857,7 @@ static git_time_t approxidate_str(const char *date,
...
@@ -857,7 +857,7 @@ static git_time_t approxidate_str(const char *date,
return
update_tm
(
&
tm
,
&
now
,
0
);
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
;
time_t
time_sec
;
git_time_t
timestamp
;
git_time_t
timestamp
;
...
@@ -875,7 +875,7 @@ int git__date_parse(git_time_t *out, const char *date)
...
@@ -875,7 +875,7 @@ int git__date_parse(git_time_t *out, const char *date)
return
error_ret
;
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
;
int
written
;
struct
tm
gmt
;
struct
tm
gmt
;
...
...
src/date.h
0 → 100644
View file @
b2c40314
/*
* 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
src/email.c
View file @
b2c40314
...
@@ -12,6 +12,7 @@
...
@@ -12,6 +12,7 @@
#include "diff_generate.h"
#include "diff_generate.h"
#include "diff_stats.h"
#include "diff_stats.h"
#include "patch.h"
#include "patch.h"
#include "date.h"
#include "git2/email.h"
#include "git2/email.h"
#include "git2/patch.h"
#include "git2/patch.h"
...
@@ -123,7 +124,7 @@ static int append_header(
...
@@ -123,7 +124,7 @@ static int append_header(
if
((
error
=
git_oid_fmt
(
id
,
commit_id
))
<
0
||
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
"
,
GIT_OID_HEXSZ
,
id
,
EMAIL_TIMESTAMP
))
<
0
||
(
error
=
git_str_printf
(
out
,
"From: %s <%s>
\n
"
,
author
->
name
,
author
->
email
))
<
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
=
git_str_printf
(
out
,
"Date: %s
\n
"
,
date
))
<
0
||
(
error
=
append_subject
(
out
,
patch_idx
,
patch_count
,
summary
,
opts
))
<
0
)
(
error
=
append_subject
(
out
,
patch_idx
,
patch_count
,
summary
,
opts
))
<
0
)
return
error
;
return
error
;
...
...
src/revparse.c
View file @
b2c40314
...
@@ -11,6 +11,7 @@
...
@@ -11,6 +11,7 @@
#include "tree.h"
#include "tree.h"
#include "refdb.h"
#include "refdb.h"
#include "regexp.h"
#include "regexp.h"
#include "date.h"
#include "git2.h"
#include "git2.h"
...
@@ -344,7 +345,7 @@ static int handle_at_syntax(git_object **out, git_reference **ref, const char *s
...
@@ -344,7 +345,7 @@ static int handle_at_syntax(git_object **out, git_reference **ref, const char *s
goto
cleanup
;
goto
cleanup
;
}
}
if
(
git_
_
date_parse
(
&
timestamp
,
curly_braces_content
)
<
0
)
if
(
git_date_parse
(
&
timestamp
,
curly_braces_content
)
<
0
)
goto
cleanup
;
goto
cleanup
;
error
=
retrieve_revobject_from_reflog
(
out
,
ref
,
repo
,
git_str_cstr
(
&
identifier
),
(
size_t
)
timestamp
);
error
=
retrieve_revobject_from_reflog
(
out
,
ref
,
repo
,
git_str_cstr
(
&
identifier
),
(
size_t
)
timestamp
);
...
...
src/util.h
View file @
b2c40314
...
@@ -295,26 +295,6 @@ GIT_INLINE(bool) git__isxdigit(int c)
...
@@ -295,26 +295,6 @@ GIT_INLINE(bool) git__isxdigit(int c)
extern
int
git__parse_bool
(
int
*
out
,
const
char
*
value
);
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.
* Unescapes a string in-place.
*
*
* Edge cases behavior:
* Edge cases behavior:
...
...
tests/date/date.c
View file @
b2c40314
#include "clar_libgit2.h"
#include "clar_libgit2.h"
#include "
util
.h"
#include "
date
.h"
void
test_date_date__overflow
(
void
)
void
test_date_date__overflow
(
void
)
{
{
...
@@ -8,8 +8,8 @@ void test_date_date__overflow(void)
...
@@ -8,8 +8,8 @@ void test_date_date__overflow(void)
git_time_t
d2038
,
d2039
;
git_time_t
d2038
,
d2039
;
/* This is expected to fail on a 32-bit machine. */
/* 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
(
&
d2038
,
"2038-1-1"
));
cl_git_pass
(
git_
_
date_parse
(
&
d2039
,
"2039-1-1"
));
cl_git_pass
(
git_date_parse
(
&
d2039
,
"2039-1-1"
));
cl_assert
(
d2038
<
d2039
);
cl_assert
(
d2038
<
d2039
);
#endif
#endif
}
}
tests/date/rfc2822.c
View file @
b2c40314
#include "clar_libgit2.h"
#include "clar_libgit2.h"
#include "
util
.h"
#include "
date
.h"
void
test_date_rfc2822__format_rfc2822_no_offset
(
void
)
void
test_date_rfc2822__format_rfc2822_no_offset
(
void
)
{
{
git_time
t
=
{
1397031663
,
0
};
git_time
t
=
{
1397031663
,
0
};
char
buf
[
GIT_DATE_RFC2822_SZ
];
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
);
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)
...
@@ -16,7 +16,7 @@ void test_date_rfc2822__format_rfc2822_positive_offset(void)
git_time
t
=
{
1397031663
,
120
};
git_time
t
=
{
1397031663
,
120
};
char
buf
[
GIT_DATE_RFC2822_SZ
];
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
);
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)
...
@@ -25,7 +25,7 @@ void test_date_rfc2822__format_rfc2822_negative_offset(void)
git_time
t
=
{
1397031663
,
-
120
};
git_time
t
=
{
1397031663
,
-
120
};
char
buf
[
GIT_DATE_RFC2822_SZ
];
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
);
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)
...
@@ -35,6 +35,6 @@ void test_date_rfc2822__format_rfc2822_buffer_too_small(void)
git_time
t
=
{
1397031663
+
86400
,
0
};
git_time
t
=
{
1397031663
+
86400
,
0
};
char
buf
[
GIT_DATE_RFC2822_SZ
-
1
];
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
));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment