Switch from time_t to git_time_t git_time_t is defined as a signed 64 integer. This allows a true predictable multiplatform behavior.
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
diff --git a/include/git2/commit.h b/include/git2/commit.h
index ba18a5b..8306eb1 100644
--- a/include/git2/commit.h
+++ b/include/git2/commit.h
@@ -83,7 +83,7 @@ GIT_EXTERN(const char *) git_commit_message(git_commit *commit);
* @param commit a previously loaded commit.
* @return the time of a commit
*/
-GIT_EXTERN(time_t) git_commit_time(git_commit *commit);
+GIT_EXTERN(git_time_t) git_commit_time(git_commit *commit);
/**
* Get the commit timezone offset (i.e. committer's preferred timezone) of a commit.
diff --git a/include/git2/signature.h b/include/git2/signature.h
index 96275aa..200397a 100644
--- a/include/git2/signature.h
+++ b/include/git2/signature.h
@@ -47,7 +47,7 @@ GIT_BEGIN_DECL
* @offset timezone offset in minutes for the time
* @return the new sig, NULl on out of memory
*/
-GIT_EXTERN(git_signature *) git_signature_new(const char *name, const char *email, time_t time, int offset);
+GIT_EXTERN(git_signature *) git_signature_new(const char *name, const char *email, git_time_t time, int offset);
/**
* Create a copy of an existing signature.
diff --git a/include/git2/types.h b/include/git2/types.h
index 64f7fc7..db09f38 100644
--- a/include/git2/types.h
+++ b/include/git2/types.h
@@ -52,12 +52,12 @@ GIT_BEGIN_DECL
#if defined(_MSC_VER)
typedef __int64 git_off_t;
-typedef __time64_t git_time_t;
+typedef __time64_t git_time_t;
#elif defined(__MINGW32__)
typedef off64_t git_off_t;
-typedef time_t git_time_t;
+typedef time64_t git_time_t;
#else /* POSIX */
@@ -66,8 +66,8 @@ typedef time_t git_time_t;
* before us (directly or indirectly), they'll get 32 bit off_t in their client
* app, even though /we/ define _FILE_OFFSET_BITS=64.
*/
-typedef long long git_off_t;
-typedef time_t git_time_t;
+typedef int64_t git_off_t;
+typedef int64_t git_time_t;
#endif
@@ -129,7 +129,7 @@ typedef struct git_index git_index;
/** Time in a signature */
typedef struct git_time {
- time_t time; /** time in seconds from epoch */
+ git_time_t time; /** time in seconds from epoch */
int offset; /** timezone offset, in minutes */
} git_time;
diff --git a/src/commit.c b/src/commit.c
index d5d6ebd..03b111d 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -315,7 +315,7 @@ GIT_COMMIT_GETTER(const git_signature *, author, commit->author)
GIT_COMMIT_GETTER(const git_signature *, committer, commit->committer)
GIT_COMMIT_GETTER(const char *, message, commit->message)
GIT_COMMIT_GETTER(const char *, message_short, commit->message_short)
-GIT_COMMIT_GETTER(time_t, time, commit->committer->when.time)
+GIT_COMMIT_GETTER(git_time_t, time, commit->committer->when.time)
GIT_COMMIT_GETTER(int, time_offset, commit->committer->when.offset)
GIT_COMMIT_GETTER(unsigned int, parentcount, commit->parent_oids.length)
diff --git a/src/index.c b/src/index.c
index 6a355e1..3420873 100644
--- a/src/index.c
+++ b/src/index.c
@@ -312,8 +312,8 @@ int git_index_add(git_index *index, const char *rel_path, int stage)
memset(&entry, 0x0, sizeof(git_index_entry));
- entry.ctime.seconds = st.st_ctime;
- entry.mtime.seconds = st.st_mtime;
+ entry.ctime.seconds = (git_time_t)st.st_ctime;
+ entry.mtime.seconds = (git_time_t)st.st_mtime;
/* entry.mtime.nanoseconds = st.st_mtimensec; */
/* entry.ctime.nanoseconds = st.st_ctimensec; */
entry.dev= st.st_rdev;
@@ -491,10 +491,10 @@ static size_t read_entry(git_index_entry *dest, const void *buffer, size_t buffe
source = (const struct entry_short *)(buffer);
- dest->ctime.seconds = (time_t)ntohl(source->ctime.seconds);
- dest->ctime.nanoseconds = (time_t)ntohl(source->ctime.nanoseconds);
- dest->mtime.seconds = (time_t)ntohl(source->mtime.seconds);
- dest->mtime.nanoseconds = (time_t)ntohl(source->mtime.nanoseconds);
+ dest->ctime.seconds = (git_time_t)ntohl(source->ctime.seconds);
+ dest->ctime.nanoseconds = ntohl(source->ctime.nanoseconds);
+ dest->mtime.seconds = (git_time_t)ntohl(source->mtime.seconds);
+ dest->mtime.nanoseconds = ntohl(source->mtime.nanoseconds);
dest->dev = ntohl(source->dev);
dest->ino = ntohl(source->ino);
dest->mode = ntohl(source->mode);
diff --git a/src/odb_pack.c b/src/odb_pack.c
index 65210f0..8c527bc 100644
--- a/src/odb_pack.c
+++ b/src/odb_pack.c
@@ -93,7 +93,7 @@ struct pack_file {
git_oid *bad_object_sha1; /* array of git_oid */
int index_version;
- time_t mtime;
+ git_time_t mtime;
int pack_fd;
unsigned pack_local:1, pack_keep:1;
git_oid sha1;
@@ -827,7 +827,7 @@ static int packfile_check(struct pack_file **pack_out, const char *path, int loc
*/
p->pack_size = (off_t)st.st_size;
p->pack_local = local;
- p->mtime = st.st_mtime;
+ p->mtime = (git_time_t)st.st_mtime;
/* see if we can parse the sha1 oid in the packfile name */
if (path_len < 40 ||
diff --git a/src/signature.c b/src/signature.c
index 13816c3..4126376 100644
--- a/src/signature.c
+++ b/src/signature.c
@@ -38,7 +38,7 @@ void git_signature_free(git_signature *sig)
free(sig);
}
-git_signature *git_signature_new(const char *name, const char *email, time_t time, int offset)
+git_signature *git_signature_new(const char *name, const char *email, git_time_t time, int offset)
{
git_signature *p = NULL;
diff --git a/tests/t04-commit.c b/tests/t04-commit.c
index 1140d33..e928424 100644
--- a/tests/t04-commit.c
+++ b/tests/t04-commit.c
@@ -366,7 +366,7 @@ BEGIN_TEST(details0, "query the details on a parsed commit")
const git_signature *author, *committer;
const char *message, *message_short;
- time_t commit_time;
+ git_time_t commit_time;
unsigned int parents, p;
git_commit *parent;
diff --git a/tests/t06-index.c b/tests/t06-index.c
index 19b4da5..93ca2c0 100644
--- a/tests/t06-index.c
+++ b/tests/t06-index.c
@@ -34,7 +34,7 @@ struct test_entry {
unsigned int index;
char path[128];
git_off_t file_size;
- time_t mtime;
+ git_time_t mtime;
};
struct test_entry TEST_ENTRIES[] = {