Commit 494ae940 by nulltoken

revparse: fix parsing of date specifiers

parent e560aa8f
...@@ -267,31 +267,18 @@ static int walk_ref_history(git_object **out, git_repository *repo, const char * ...@@ -267,31 +267,18 @@ static int walk_ref_history(git_object **out, git_repository *repo, const char *
int numentries = git_reflog_entrycount(reflog); int numentries = git_reflog_entrycount(reflog);
int i; int i;
/* TODO: clunky. Factor "now" into a utility */ for (i = numentries - 1; i >= 0; i--) {
git_signature *sig;
git_time as_of;
git_signature_now(&sig, "blah", "blah");
as_of = sig->when;
git_signature_free(sig);
as_of.time = (timestamp > 0)
? timestamp
: sig->when.time + timestamp;
for (i=numentries-1; i>0; i--) {
const git_reflog_entry *entry = git_reflog_entry_byindex(reflog, i); const git_reflog_entry *entry = git_reflog_entry_byindex(reflog, i);
git_time commit_time = git_reflog_entry_committer(entry)->when; git_time commit_time = git_reflog_entry_committer(entry)->when;
if (git__time_cmp(&commit_time, &as_of) <= 0 ) { if (commit_time.time - timestamp <= 0) {
retcode = git_object_lookup(out, repo, git_reflog_entry_oidnew(entry), GIT_OBJ_ANY); retcode = git_object_lookup(out, repo, git_reflog_entry_oidnew(entry), GIT_OBJ_ANY);
break; break;
} }
} }
if (!i) { if (i == -1) {
/* Didn't find a match. Use the oldest revision in the reflog. */ /* Didn't find a match */
const git_reflog_entry *entry = git_reflog_entry_byindex(reflog, 0); retcode = GIT_ENOTFOUND;
retcode = git_object_lookup(out, repo, git_reflog_entry_oidnew(entry), GIT_OBJ_ANY);
} }
git_reflog_free(reflog); git_reflog_free(reflog);
......
...@@ -209,13 +209,6 @@ GIT_INLINE(bool) git__isspace(int c) ...@@ -209,13 +209,6 @@ GIT_INLINE(bool) git__isspace(int c)
return (c == ' ' || c == '\t' || c == '\n' || c == '\f' || c == '\r' || c == '\v'); return (c == ' ' || c == '\t' || c == '\n' || c == '\f' || c == '\r' || c == '\v');
} }
GIT_INLINE(int) git__time_cmp(const git_time *a, const git_time *b)
{
/* Adjust for time zones. Times are in seconds, offsets are in minutes. */
git_time_t adjusted_a = a->time + ((b->offset - a->offset) * 60);
return (int)(adjusted_a - b->time);
}
GIT_INLINE(bool) git__iswildcard(int c) GIT_INLINE(bool) git__iswildcard(int c)
{ {
return (c == '*' || c == '?' || c == '['); return (c == '*' || c == '?' || c == '[');
......
...@@ -155,14 +155,73 @@ void test_refs_revparse__revwalk(void) ...@@ -155,14 +155,73 @@ void test_refs_revparse__revwalk(void)
void test_refs_revparse__date(void) void test_refs_revparse__date(void)
{ {
test_object("HEAD@{10 years ago}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"); /*
test_object("HEAD@{1 second}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); * $ git reflog HEAD --date=iso
test_object("master@{2012-4-30 10:23:20 -0800}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"); * a65fedf HEAD@{2012-04-30 08:23:41 -0900}: checkout: moving from br2 to master
test_object("master@{2012-4-30 18:24 -0800}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); * a4a7dce HEAD@{2012-04-30 08:23:37 -0900}: commit: checking in
test_object("master@{2012-4-30 23:24 -0300}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); * c47800c HEAD@{2012-04-30 08:23:28 -0900}: checkout: moving from master to br2
* a65fedf HEAD@{2012-04-30 08:23:23 -0900}: commit:
* be3563a HEAD@{2012-04-30 10:22:43 -0700}: clone: from /Users/ben/src/libgit2/tes
*
* $ git reflog HEAD --date=raw
* a65fedf HEAD@{1335806621 -0900}: checkout: moving from br2 to master
* a4a7dce HEAD@{1335806617 -0900}: commit: checking in
* c47800c HEAD@{1335806608 -0900}: checkout: moving from master to br2
* a65fedf HEAD@{1335806603 -0900}: commit:
* be3563a HEAD@{1335806563 -0700}: clone: from /Users/ben/src/libgit2/tests/resour
*/
cl_assert_equal_i(GIT_ENOTFOUND, git_revparse_single(&g_obj, g_repo, "HEAD@{10 years ago}"));
/* Core git gives a65fedf, because they don't take time zones into account. */ test_object("HEAD@{1 second}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
test_object("master@{1335806640}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"); test_object("HEAD@{1 second ago}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
test_object("HEAD@{2 days ago}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
/*
* $ git reflog master --date=iso
* a65fedf master@{2012-04-30 09:23:23 -0800}: commit: checking in
* be3563a master@{2012-04-30 09:22:43 -0800}: clone: from /Users/ben/src...
*
* $ git reflog master --date=raw
* a65fedf master@{1335806603 -0800}: commit: checking in
* be3563a master@{1335806563 -0800}: clone: from /Users/ben/src/libgit2/tests/reso
*/
/*
* $ git reflog -1 "master@{2012-04-30 17:22:42 +0000}"
* warning: Log for 'master' only goes back to Mon, 30 Apr 2012 09:22:43 -0800.
*/
cl_assert_equal_i(GIT_ENOTFOUND, git_revparse_single(&g_obj, g_repo, "master@{2012-04-30 17:22:42 +0000}"));
cl_assert_equal_i(GIT_ENOTFOUND, git_revparse_single(&g_obj, g_repo, "master@{2012-04-30 09:22:42 -0800}"));
/*
* $ git reflog -1 "master@{2012-04-30 17:22:43 +0000}"
* be3563a master@{Mon Apr 30 09:22:43 2012 -0800}: clone: from /Users/ben/src/libg
*/
test_object("master@{2012-04-30 17:22:43 +0000}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
test_object("master@{2012-04-30 09:22:43 -0800}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
/*
* $ git reflog -1 "master@{2012-4-30 09:23:27 -0800}"
* a65fedf master@{Mon Apr 30 09:23:23 2012 -0800}: commit: checking in
*/
test_object("master@{2012-4-30 09:23:27 -0800}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
/*
* $ git reflog -1 master@{2012-05-03}
* a65fedf master@{Mon Apr 30 09:23:23 2012 -0800}: commit: checking in
*/
test_object("master@{2012-05-03}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
/*
* $ git reflog -1 "master@{1335806603}"
* a65fedf
*
* $ git reflog -1 "master@{1335806602}"
* be3563a
*/
test_object("master@{1335806603}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
test_object("master@{1335806602}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
} }
void test_refs_revparse__colon(void) void test_refs_revparse__colon(void)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment