add got_packidx_get_packfile_path() for library-internal use
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
diff --git a/lib/got_lib_pack.h b/lib/got_lib_pack.h
index 39aa433..8ba2e5d 100644
--- a/lib/got_lib_pack.h
+++ b/lib/got_lib_pack.h
@@ -170,6 +170,7 @@ const struct got_error *got_packidx_init_hdr(struct got_packidx *, int);
const struct got_error *got_packidx_open(struct got_packidx **,
int, const char *, int);
const struct got_error *got_packidx_close(struct got_packidx *);
+const struct got_error *got_packidx_get_packfile_path(char **, struct got_packidx *);
int got_packidx_get_object_idx(struct got_packidx *, struct got_object_id *);
const struct got_error *got_packidx_match_id_str_prefix(
struct got_object_id_queue *, struct got_packidx *, const char *);
diff --git a/lib/object.c b/lib/object.c
index 6941187..45d8d17 100644
--- a/lib/object.c
+++ b/lib/object.c
@@ -146,31 +146,6 @@ done:
}
static const struct got_error *
-get_packfile_path(char **path_packfile, struct got_packidx *packidx)
-{
- size_t size;
-
- /* Packfile path contains ".pack" instead of ".idx", so add one byte. */
- size = strlen(packidx->path_packidx) + 2;
- if (size < GOT_PACKFILE_NAMELEN + 1)
- return got_error_path(packidx->path_packidx, GOT_ERR_BAD_PATH);
-
- *path_packfile = malloc(size);
- if (*path_packfile == NULL)
- return got_error_from_errno("malloc");
-
- /* Copy up to and excluding ".idx". */
- if (strlcpy(*path_packfile, packidx->path_packidx,
- size - strlen(GOT_PACKIDX_SUFFIX) - 1) >= size)
- return got_error(GOT_ERR_NO_SPACE);
-
- if (strlcat(*path_packfile, GOT_PACKFILE_SUFFIX, size) >= size)
- return got_error(GOT_ERR_NO_SPACE);
-
- return NULL;
-}
-
-static const struct got_error *
request_packed_object(struct got_object **obj, struct got_pack *pack, int idx,
struct got_object_id *id)
{
@@ -371,7 +346,7 @@ open_packed_object(struct got_object **obj, struct got_object_id *id,
if (err)
return err;
- err = get_packfile_path(&path_packfile, packidx);
+ err = got_packidx_get_packfile_path(&path_packfile, packidx);
if (err)
return err;
@@ -580,7 +555,7 @@ got_object_raw_open(struct got_raw_object **obj, struct got_repository *repo,
if (err == NULL) {
struct got_pack *pack = NULL;
- err = get_packfile_path(&path_packfile, packidx);
+ err = got_packidx_get_packfile_path(&path_packfile, packidx);
if (err)
goto done;
@@ -867,7 +842,7 @@ open_commit(struct got_commit_object **commit,
if (err == NULL) {
struct got_pack *pack = NULL;
- err = get_packfile_path(&path_packfile, packidx);
+ err = got_packidx_get_packfile_path(&path_packfile, packidx);
if (err)
return err;
@@ -1056,7 +1031,7 @@ open_tree(struct got_tree_object **tree, struct got_repository *repo,
if (err == NULL) {
struct got_pack *pack = NULL;
- err = get_packfile_path(&path_packfile, packidx);
+ err = got_packidx_get_packfile_path(&path_packfile, packidx);
if (err)
return err;
@@ -1420,7 +1395,7 @@ open_blob(struct got_blob_object **blob, struct got_repository *repo,
if (err == NULL) {
struct got_pack *pack = NULL;
- err = get_packfile_path(&path_packfile, packidx);
+ err = got_packidx_get_packfile_path(&path_packfile, packidx);
if (err)
goto done;
@@ -1770,7 +1745,7 @@ open_tag(struct got_tag_object **tag, struct got_repository *repo,
if (err == NULL) {
struct got_pack *pack = NULL;
- err = get_packfile_path(&path_packfile, packidx);
+ err = got_packidx_get_packfile_path(&path_packfile, packidx);
if (err)
return err;
@@ -2274,7 +2249,7 @@ got_traverse_packed_commits(struct got_object_id_queue *traversed_commits,
return NULL;
}
- err = get_packfile_path(&path_packfile, packidx);
+ err = got_packidx_get_packfile_path(&path_packfile, packidx);
if (err)
return err;
diff --git a/lib/pack.c b/lib/pack.c
index ee37e10..1372173 100644
--- a/lib/pack.c
+++ b/lib/pack.c
@@ -415,6 +415,31 @@ got_packidx_close(struct got_packidx *packidx)
return err;
}
+const struct got_error *
+got_packidx_get_packfile_path(char **path_packfile, struct got_packidx *packidx)
+{
+ size_t size;
+
+ /* Packfile path contains ".pack" instead of ".idx", so add one byte. */
+ size = strlen(packidx->path_packidx) + 2;
+ if (size < GOT_PACKFILE_NAMELEN + 1)
+ return got_error_path(packidx->path_packidx, GOT_ERR_BAD_PATH);
+
+ *path_packfile = malloc(size);
+ if (*path_packfile == NULL)
+ return got_error_from_errno("malloc");
+
+ /* Copy up to and excluding ".idx". */
+ if (strlcpy(*path_packfile, packidx->path_packidx,
+ size - strlen(GOT_PACKIDX_SUFFIX) - 1) >= size)
+ return got_error(GOT_ERR_NO_SPACE);
+
+ if (strlcat(*path_packfile, GOT_PACKFILE_SUFFIX, size) >= size)
+ return got_error(GOT_ERR_NO_SPACE);
+
+ return NULL;
+}
+
static off_t
get_object_offset(struct got_packidx *packidx, int idx)
{