move parse_commit_time() to object.c and make public API
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
diff --git a/include/got_object.h b/include/got_object.h
index 54d808e..6a104bb 100644
--- a/include/got_object.h
+++ b/include/got_object.h
@@ -122,6 +122,14 @@ const struct got_error *got_object_commit_open(struct got_commit_object **,
/* Dispose of a commit object. */
void got_object_commit_close(struct got_commit_object *);
+/* Get the commit's committer timestamp (in UTC). */
+const struct got_error *got_object_commit_get_committer_time(time_t *,
+ struct got_commit_object *);
+
+/* Get the commit's author timestamp (in UTC). */
+const struct got_error *got_object_commit_get_committer_time(time_t *,
+ struct got_commit_object *);
+
/*
* Attempt to open a tree object in a repository.
* The provided object must be of type GOT_OBJ_TYPE_TREE.
diff --git a/lib/commit_graph.c b/lib/commit_graph.c
index 7dd5b8b..5d6edcf 100644
--- a/lib/commit_graph.c
+++ b/lib/commit_graph.c
@@ -135,53 +135,17 @@ is_root_node(struct got_commit_graph_node *node)
}
static const struct got_error *
-parse_commit_time(int64_t *time, struct got_commit_object *commit)
-{
- const struct got_error *err = NULL;
- const char *errstr;
- char *committer, *space;
-
- *time = 0;
-
- committer = strdup(commit->committer);
- if (committer == NULL)
- return got_error_from_errno();
-
- /* Strip off trailing timezone indicator. */
- space = strrchr(committer, ' ');
- if (space == NULL) {
- err = got_error(GOT_ERR_BAD_OBJ_DATA);
- goto done;
- }
- *space = '\0';
-
- /* Timestamp is separated from committer name + email by space. */
- space = strrchr(committer, ' ');
- if (space == NULL) {
- err = got_error(GOT_ERR_BAD_OBJ_DATA);
- goto done;
- }
-
- *time = strtonum(space + 1, 0, INT64_MAX, &errstr);
- if (errstr)
- err = got_error(GOT_ERR_BAD_OBJ_DATA);
-
-done:
- free(committer);
- return err;
-}
-
-static const struct got_error *
compare_commits(int *cmp, struct got_commit_object *c1,
struct got_commit_object *c2)
{
const struct got_error *err;
int64_t t1, t2;
- err = parse_commit_time(&t1, c1);
+ err = got_object_commit_get_committer_time(&t1, c1);
if (err)
return err;
- err = parse_commit_time(&t2, c2);
+ err = got_object_commit_get_committer_time(&t2, c2);
+
if (err)
return err;
diff --git a/lib/object.c b/lib/object.c
index fd3ef97..679abec 100644
--- a/lib/object.c
+++ b/lib/object.c
@@ -581,6 +581,57 @@ done:
return err;
}
+static const struct got_error *
+parse_commit_time(time_t *time, const char *author_str)
+{
+ const struct got_error *err = NULL;
+ const char *errstr;
+ char *committer, *space;
+
+ *time = 0;
+
+ committer = strdup(author_str);
+ if (committer == NULL)
+ return got_error_from_errno();
+
+ /* Strip off trailing timezone indicator. */
+ space = strrchr(committer, ' ');
+ if (space == NULL) {
+ err = got_error(GOT_ERR_BAD_OBJ_DATA);
+ goto done;
+ }
+ *space = '\0';
+
+ /* Timestamp is separated from committer name + email by space. */
+ space = strrchr(committer, ' ');
+ if (space == NULL) {
+ err = got_error(GOT_ERR_BAD_OBJ_DATA);
+ goto done;
+ }
+
+ *time = strtonum(space + 1, 0, INT64_MAX, &errstr);
+ if (errstr)
+ err = got_error(GOT_ERR_BAD_OBJ_DATA);
+
+done:
+ free(committer);
+ return err;
+}
+
+const struct got_error *
+got_object_commit_get_committer_time(time_t *time,
+ struct got_commit_object *commit)
+{
+ return parse_commit_time(time, commit->committer);
+}
+
+const struct got_error *
+got_object_commit_get_author_time(time_t *time,
+ struct got_commit_object *commit)
+{
+ return parse_commit_time(time, commit->committer);
+}
+
static void
tree_entry_close(struct got_tree_entry *te)
{