commit - 1365c7b749c6f35bdb2fe998f0fbf2f4764ad2a88357beacb6b856a846d37e15
commit + cd09e882304a191d841c7e06a5270322e38507bae5c40735890cb7695f4dc965
blob - 466de69000e375badc1529f54563086b9c3918212a251c7d701be8f835b8599b
blob + ea71a0e6eb48907657929762e8eee02762de3dda8e69bff7c6a72f7dfb07b2ad
--- lib/got_lib_object.h
+++ lib/got_lib_object.h
char name[NAME_MAX + 1 /* NUL */];
struct got_object_id id;
int idx;
+ uint32_t path_hash;
};
struct got_tree_object {
struct got_repository *, struct got_object *);
const struct got_error *got_object_tree_entry_dup(struct got_tree_entry **,
struct got_tree_entry *);
+uint32_t got_tree_entry_get_path_hash(struct got_tree_entry *);
const struct got_error *got_traverse_packed_commits(
struct got_object_id_queue *, struct got_object_id *, const char *,
typedef const struct got_error *(*got_object_enumerate_commit_cb)(void *,
time_t, struct got_object_id *, struct got_repository *);
typedef const struct got_error *(*got_object_enumerate_tree_cb)(void *,
- struct got_tree_object *, time_t, struct got_object_id *, const char *,
+ struct got_tree_object *, time_t, struct got_object_id *, uint32_t,
struct got_repository *);
const struct got_error *got_object_enumerate(int *,
got_object_enumerate_commit_cb, got_object_enumerate_tree_cb, void *,
struct got_object_id **, int, struct got_object_id **, int,
- struct got_packidx *, struct got_repository *);
+ struct got_packidx *, uint32_t, struct got_repository *);
const struct got_error *got_object_raw_alloc(struct got_raw_object **,
uint8_t *, int *, size_t, size_t, off_t);
blob - e9f1e54db514d0bd77135e022b9353b6d4ed77cff511badfcc6c5f8833452fa5
blob + 2497d379ee67dc4c40ea9258a43c970fac8d05dea51ab32cde4bd3e8245792dd
--- lib/got_lib_object_parse.h
+++ lib/got_lib_object_parse.h
uint8_t *id; /* Points to ID in parsed tree buffer. */
size_t digest_len;
int algo;
+ uint32_t path_hash;
};
const struct got_error *got_object_parse_tree_entry(
struct got_parsed_tree_entry *, size_t *, char *, size_t, size_t, enum got_hash_algorithm);
blob - 2e29868d22b9f1a66c18c61a91f47618a0bd745f8d36a74d0f102a8b8b2cfa8c
blob + b1f5176058c506ef45503786438fbd2f46a6c7adb64a3237837dfd57f7e28a6f
--- lib/got_lib_pack_create.h
+++ lib/got_lib_pack_create.h
const struct got_error *
got_pack_add_object(int want_meta, struct got_object_idset *idset,
- struct got_object_id *id, const char *path, int obj_type,
+ struct got_object_id *id, uint32_t path_hash, int obj_type,
time_t mtime, uint32_t seed, int loose_obj_only,
struct got_repository *repo, int *ncolored, int *nfound, int *ntrees,
got_pack_progress_cb progress_cb, void *progress_arg,
blob - ade7a6256532fd819e304c6e7900937a8d39bd80934bb499c9d5f026e2cf3350
blob + d412683b9daab3a372fb45922d7782bd5dfc329576a82deaff0b10b5c3313a91
--- lib/got_lib_privsep.h
+++ lib/got_lib_privsep.h
GOT_IMSG_OBJECT_ENUMERATION_REQUEST,
GOT_IMSG_ENUMERATED_COMMIT,
GOT_IMSG_ENUMERATED_TREE,
+ GOT_IMSG_ENUMERATED_TREE_ENTRIES,
GOT_IMSG_TREE_ENUMERATION_DONE,
GOT_IMSG_OBJECT_ENUMERATION_DONE,
GOT_IMSG_OBJECT_ENUMERATION_INCOMPLETE,
struct got_imsg_enumerated_tree {
struct got_object_id id; /* tree ID */
int nentries; /* number of tree entries */
+ uint32_t path_hash;
- /* Followed by tree's path in remaining data of imsg buffer. */
+ /* Followed by nentries tree-entries in subsequent messages. */
+} __attribute__((__packed__));
- /* Followed by nentries * GOT_IMSG_TREE_ENTRY messages. */
+/* Structure for GOT_IMSG_ENUMERATED_TREE_ENTRIES */
+struct got_imsg_enumerated_tree_entries {
+ size_t nentries; /* Number of tree entries contained in this message. */
+
+ /* Followed by nentries * struct got_imsg_enumerated_tree_entry */
+};
+
+struct got_imsg_enumerated_tree_entry {
+ char id[GOT_HASH_DIGEST_MAXLEN];
+ mode_t mode;
+ uint32_t path_hash;
} __attribute__((__packed__));
/*
struct got_commit_object **, struct got_object_id_queue *,
struct imsgbuf *);
const struct got_error *got_privsep_send_enumerated_tree(size_t *,
- struct imsgbuf *, struct got_object_id *, const char *,
+ struct imsgbuf *, struct got_object_id *, const char *, uint32_t,
struct got_parsed_tree_entry *, int);
const struct got_error *got_privsep_send_object_enumeration_request(
- struct imsgbuf *);
+ struct imsgbuf *, uint32_t);
const struct got_error *got_privsep_send_object_enumeration_done(
struct imsgbuf *);
const struct got_error *got_privsep_send_object_enumeration_incomplete(
struct got_object_id *, time_t);
const struct got_error *got_privsep_recv_enumerated_objects(int *,
struct imsgbuf *, got_object_enumerate_commit_cb,
- got_object_enumerate_tree_cb, void *, struct got_repository *);
+ got_object_enumerate_tree_cb, void *, struct got_repository *,
+ enum got_hash_algorithm);
const struct got_error *got_privsep_send_raw_delta_req(struct imsgbuf *, int,
struct got_object_id *);
blob - 444fc618d9c701f076fdb776ddaf8bcfa69bc5e3fad8b660b6ed49c6410a689d
blob + 4f685b225db3af133fb4a65a4c81d41cada812668c8184b237d06185458257ba
--- lib/object.c
+++ lib/object.c
return &te->id;
}
+uint32_t
+got_tree_entry_get_path_hash(struct got_tree_entry *te)
+{
+ return te->path_hash;
+}
+
const struct got_error *
got_object_blob_read_to_str(char **s, struct got_blob_object *blob)
{
blob - b3a1d145a308f92d8a155c08904fb679735e22c3e661c90248ed7ab96ae534bc
blob + 0e174251d607ace24ec639e21fe05b9a504191110dc41be3da5ad7280d6a4834
--- lib/object_open_privsep.c
+++ lib/object_open_privsep.c
got_object_enumerate_tree_cb cb_tree, void *cb_arg,
struct got_object_id **ours, int nours,
struct got_object_id **theirs, int ntheirs,
- struct got_packidx *packidx, struct got_repository *repo)
+ struct got_packidx *packidx, uint32_t seed, struct got_repository *repo)
{
const struct got_error *err = NULL;
struct got_pack *pack;
}
err = got_privsep_send_object_enumeration_request(
- pack->privsep_child->ibuf);
+ pack->privsep_child->ibuf, seed);
if (err)
goto done;
goto done;
err = got_privsep_recv_enumerated_objects(found_all_objects,
- pack->privsep_child->ibuf, cb_commit, cb_tree, cb_arg, repo);
+ pack->privsep_child->ibuf, cb_commit, cb_tree, cb_arg, repo,
+ got_repo_get_hash_algo(repo));
done:
free(path_packfile);
return err;
blob - 2ea2ba8a4bdaa85426537bb42be2a2c0999043202f43bc9ad53c97a9cd7b4720
blob + dd575c1631431af968b06f6a2549cdcf84edfb90b1237997af92febb33fadf94
--- lib/pack_create.c
+++ lib/pack_create.c
static const struct got_error *
alloc_meta(struct got_pack_meta **new, struct got_object_id *id,
- const char *path, int obj_type, time_t mtime, uint32_t seed)
+ uint32_t path_hash, int obj_type, time_t mtime, uint32_t seed)
{
struct got_pack_meta *m;
memcpy(&m->id, id, sizeof(m->id));
- m->path_hash = murmurhash2(path, strlen(path), seed);
+ m->path_hash = path_hash;
m->obj_type = obj_type;
m->mtime = mtime;
*new = m;
const struct got_error *
got_pack_add_object(int want_meta, struct got_object_idset *idset,
- struct got_object_id *id, const char *path, int obj_type,
+ struct got_object_id *id, uint32_t path_hash, int obj_type,
time_t mtime, uint32_t seed, int loose_obj_only,
struct got_repository *repo, int *ncolored, int *nfound, int *ntrees,
got_pack_progress_cb progress_cb, void *progress_arg,
}
if (want_meta) {
- err = alloc_meta(&m, id, path, obj_type, mtime, seed);
+ err = alloc_meta(&m, id, path_hash, obj_type, mtime, seed);
if (err)
return err;
got_object_idset_contains(idset_exclude, id))
continue;
- /*
- * If got-read-pack is crawling trees for us then
- * we are only here to collect blob IDs.
- */
- if (ids == NULL && S_ISDIR(mode))
- continue;
-
ret = snprintf(p, psize, "%s%s%s", dpath,
got_path_is_root_dir(dpath) ? "" : "/",
got_tree_entry_get_name(e));
}
STAILQ_INSERT_TAIL(ids, qid, entry);
} else if (S_ISREG(mode) || S_ISLNK(mode)) {
+ uint32_t path_hash;
+
+ path_hash = murmurhash2(p, strlen(p), seed);
err = got_pack_add_object(want_meta,
- want_meta ? idset : idset_exclude, id, p,
+ want_meta ? idset : idset_exclude, id, path_hash,
GOT_OBJ_TYPE_BLOB, mtime, seed, loose_obj_only,
repo, ncolored, nfound, ntrees,
progress_cb, progress_arg, rl);
while (!STAILQ_EMPTY(&tree_ids)) {
const char *path;
+ uint32_t path_hash;
+
if (cancel_cb) {
err = (*cancel_cb)(cancel_arg);
if (err)
continue;
}
+ path_hash = murmurhash2(path, strlen(path), seed);
err = got_pack_add_object(want_meta,
want_meta ? idset : idset_exclude,
- &qid->id, path, GOT_OBJ_TYPE_TREE,
+ &qid->id, path_hash, GOT_OBJ_TYPE_TREE,
mtime, seed, loose_obj_only, repo,
ncolored, nfound, ntrees, progress_cb, progress_arg, rl);
if (err) {
err = got_pack_add_object(want_meta,
want_meta ? idset : idset_exclude,
- &qid->id, "", GOT_OBJ_TYPE_COMMIT,
+ &qid->id, 0, GOT_OBJ_TYPE_COMMIT,
got_object_commit_get_committer_time(commit), seed,
loose_obj_only, repo,
ncolored, nfound, ntrees, progress_cb, progress_arg, rl);
return err;
err = got_pack_add_object(want_meta,
- want_meta ? idset : idset_exclude, id, "", GOT_OBJ_TYPE_TAG,
+ want_meta ? idset : idset_exclude, id, 0, GOT_OBJ_TYPE_TAG,
got_object_tag_get_tagger_time(tag), seed, loose_obj_only, repo,
ncolored, nfound, ntrees, progress_cb, progress_arg, rl);
if (err)
blob - 2d3f72ec455ad24f8683a5641a379dbc088091ed0fd6c32375626b9d0d3ace47
blob + 006c6d8bd619840c7113579ec311166df95e6d1c8c4e6f484e12c2921a95d22a
--- lib/pack_create_privsep.c
+++ lib/pack_create_privsep.c
#include <sys/queue.h>
#include <sys/tree.h>
#include <sys/uio.h>
+#include <sys/stat.h>
#include <sha1.h>
#include <sha2.h>
#include "got_lib_pack_create.h"
#include "got_lib_repository.h"
+#include "murmurhash2.h"
+
struct send_id_arg {
struct imsgbuf *ibuf;
struct got_object_id *ids[GOT_IMSG_OBJ_ID_LIST_MAX_NIDS];
struct load_packed_obj_arg {
/* output parameters: */
struct got_object_id *id;
- char *dpath;
time_t mtime;
/* input parameters: */
return got_pack_add_object(a->want_meta,
a->want_meta ? a->idset : a->idset_exclude,
- id, "", GOT_OBJ_TYPE_COMMIT, mtime, a->seed, a->loose_obj_only,
+ id, 0, GOT_OBJ_TYPE_COMMIT, mtime, a->seed, a->loose_obj_only,
repo, a->ncolored, a->nfound, a->ntrees,
a->progress_cb, a->progress_arg, a->rl);
}
static const struct got_error *
-load_packed_tree_ids(void *arg, struct got_tree_object *tree, time_t mtime,
- struct got_object_id *id, const char *dpath, struct got_repository *repo)
+load_packed_trees(void *arg, struct got_tree_object *tree, time_t mtime,
+ struct got_object_id *id, uint32_t path_hash, struct got_repository *repo)
{
const struct got_error *err;
struct load_packed_obj_arg *a = arg;
- const char *relpath;
+ int i;
/*
- * When we receive a tree's ID and path but not the tree itself,
+ * When we receive a tree's ID but not the tree itself then
* this tree object was not found in the pack file. This is the
* last time we are being called for this optimized traversal.
* Return from here and switch to loading objects the slow way.
a->id = got_object_id_dup(id);
if (a->id == NULL) {
err = got_error_from_errno("got_object_id_dup");
- free(a->dpath);
- a->dpath = NULL;
return err;
}
- free(a->dpath);
- a->dpath = strdup(dpath);
- if (a->dpath == NULL) {
- err = got_error_from_errno("strdup");
- free(a->id);
- a->id = NULL;
- return err;
- }
-
a->mtime = mtime;
return NULL;
}
got_object_idset_contains(a->idset_exclude, id))
return NULL;
- relpath = dpath;
- while (relpath[0] == '/')
- relpath++;
-
err = got_pack_add_object(a->want_meta,
a->want_meta ? a->idset : a->idset_exclude,
- id, relpath, GOT_OBJ_TYPE_TREE, mtime, a->seed,
+ id, path_hash, GOT_OBJ_TYPE_TREE, mtime, a->seed,
a->loose_obj_only, repo, a->ncolored, a->nfound, a->ntrees,
a->progress_cb, a->progress_arg, a->rl);
if (err)
return err;
- return got_pack_load_tree_entries(NULL, a->want_meta, a->idset,
- a->idset_exclude, tree, id, dpath, mtime, a->seed, repo,
- a->loose_obj_only, a->ncolored, a->nfound, a->ntrees,
- a->progress_cb, a->progress_arg, a->rl,
- a->cancel_cb, a->cancel_arg);
+ (*a->ntrees)++;
+ err = got_pack_report_progress(a->progress_cb, a->progress_arg, a->rl,
+ *a->ncolored, *a->nfound, *a->ntrees, 0L, 0, 0, 0, 0, 0);
+ if (err)
+ return err;
+
+ for (i = 0; i < got_object_tree_get_nentries(tree); i++) {
+ struct got_tree_entry *e;
+ struct got_object_id *id;
+ mode_t mode;
+
+ if (a->cancel_cb) {
+ err = (*a->cancel_cb)(a->cancel_arg);
+ if (err)
+ return err;
+ }
+
+ e = got_object_tree_get_entry(tree, i);
+ if (e == NULL) /* should not happen */
+ return got_error(GOT_ERR_NO_TREE_ENTRY);
+
+ id = got_tree_entry_get_id(e);
+
+ if (got_object_tree_entry_is_submodule(e) ||
+ got_object_idset_contains(a->idset, id) ||
+ got_object_idset_contains(a->idset_exclude, id))
+ continue;
+
+ mode = got_tree_entry_get_mode(e);
+ if (S_ISREG(mode) || S_ISLNK(mode)) {
+ err = got_pack_add_object(a->want_meta,
+ a->want_meta ? a->idset : a->idset_exclude,
+ id, got_tree_entry_get_path_hash(e),
+ GOT_OBJ_TYPE_BLOB, mtime, a->seed,
+ a->loose_obj_only, repo,
+ a->ncolored, a->nfound, a->ntrees,
+ a->progress_cb, a->progress_arg, a->rl);
+ if (err)
+ return err;
+ }
+
+ }
+
+ return NULL;
}
const struct got_error *
/* Attempt to load objects via got-read-pack, as far as possible. */
err = got_object_enumerate(found_all_objects, load_packed_commit_id,
- load_packed_tree_ids, &lpa, ours, nours, theirs, ntheirs,
- packidx, repo);
+ load_packed_trees, &lpa, ours, nours, theirs, ntheirs,
+ packidx, seed, repo);
if (err)
return err;
* Continue loading trees the slow way.
*/
err = got_pack_load_tree(want_meta, idset, idset_exclude,
- lpa.id, lpa.dpath, lpa.mtime, seed, repo, loose_obj_only,
+ lpa.id, "/", lpa.mtime, seed, repo, loose_obj_only,
ncolored, nfound, ntrees, progress_cb, progress_arg, rl,
cancel_cb, cancel_arg);
free(lpa.id);
- free(lpa.dpath);
return err;
}
blob - edbfb2be10c241fce8005f5589b6c3aeff4a755fa3a4f72f25af378fa2740cad
blob + 1be166fb18e0fb01f0462abefaed0598f5ab52239d17cad14eebeaff5c9b61fa
--- lib/privsep.c
+++ lib/privsep.c
#include "got_privsep.h"
+#include "murmurhash2.h"
+
#ifndef MIN
#define MIN(_a,_b) ((_a) < (_b) ? (_a) : (_b))
#endif
return err;
}
+static const struct got_error *
+send_enumerated_tree_entries_batch(struct imsgbuf *ibuf,
+ struct got_parsed_tree_entry *entries, int idx0, int idxN, size_t len)
+{
+ struct ibuf *wbuf;
+ struct got_imsg_enumerated_tree_entries ientries;
+ int i;
+
+ memset(&ientries, 0, sizeof(ientries));
+
+ wbuf = imsg_create(ibuf, GOT_IMSG_ENUMERATED_TREE_ENTRIES, 0, 0, len);
+ if (wbuf == NULL)
+ return got_error_from_errno("imsg_create TREE_ENTRY");
+
+ ientries.nentries = idxN - idx0 + 1;
+ if (imsg_add(wbuf, &ientries, sizeof(ientries)) == -1)
+ return got_error_from_errno("imsg_add TREE_ENTRY");
+
+ for (i = idx0; i <= idxN; i++) {
+ static const char gap[12]; /* for sha1 inside sha256 align */
+ struct got_parsed_tree_entry *pte = &entries[i];
+
+ /*
+ * Keep in sync with struct got_imsg_enumerated_tree_entry
+ * definition!
+ */
+ if (imsg_add(wbuf, pte->id, pte->digest_len) == -1)
+ return got_error_from_errno("imsg_add TREE_ENTRY");
+ if (pte->algo == GOT_HASH_SHA1 &&
+ imsg_add(wbuf, gap, sizeof(gap)) == -1)
+ return got_error_from_errno("imsg_add TREE_ENTRY");
+ if (imsg_add(wbuf, &pte->mode, sizeof(pte->mode)) == -1)
+ return got_error_from_errno("imsg_add TREE_ENTRY");
+ if (imsg_add(wbuf, &pte->path_hash,
+ sizeof(pte->path_hash)) == -1)
+ return got_error_from_errno("imsg_add TREE_ENTRY");
+ }
+
+ imsg_close(ibuf, wbuf);
+ return NULL;
+}
+
+static const struct got_error *
+send_enumerated_tree_entries(struct imsgbuf *ibuf,
+ struct got_parsed_tree_entry *entries, int nentries)
+{
+ const struct got_error *err = NULL;
+ int i, j;
+ size_t entries_len = sizeof(struct got_imsg_enumerated_tree_entries);
+
+ i = 0;
+ for (j = 0; j < nentries; j++) {
+ size_t len = sizeof(struct got_imsg_enumerated_tree_entry);
+
+ if (j > 0 &&
+ entries_len + len > MAX_IMSGSIZE - IMSG_HEADER_SIZE) {
+ err = send_enumerated_tree_entries_batch(ibuf, entries,
+ i, j - 1, entries_len);
+ if (err)
+ return err;
+ i = j;
+ entries_len = sizeof(
+ struct got_imsg_enumerated_tree_entries);
+ }
+
+ entries_len += len;
+ }
+
+ if (j > 0) {
+ err = send_enumerated_tree_entries_batch(ibuf, entries,
+ i, j - 1, entries_len);
+ if (err)
+ return err;
+ }
+
+ return NULL;
+}
+
const struct got_error *
got_privsep_send_enumerated_tree(size_t *totlen, struct imsgbuf *ibuf,
- struct got_object_id *tree_id, const char *path,
+ struct got_object_id *tree_id, const char *path, uint32_t seed,
struct got_parsed_tree_entry *entries, int nentries)
{
const struct got_error *err = NULL;
struct ibuf *wbuf;
- size_t path_len = strlen(path);
- size_t msglen;
+ uint32_t path_hash = murmurhash2(path, strlen(path), seed);
- msglen = sizeof(struct got_imsg_enumerated_tree) + path_len;
- wbuf = imsg_create(ibuf, GOT_IMSG_ENUMERATED_TREE, 0, 0, msglen);
+ wbuf = imsg_create(ibuf, GOT_IMSG_ENUMERATED_TREE, 0, 0,
+ sizeof(struct got_imsg_enumerated_tree));
if (wbuf == NULL)
return got_error_from_errno("imsg_create ENUMERATED_TREE");
+ /* Keep in sync with struct got_imsg_enumerated_tree! */
if (imsg_add(wbuf, tree_id, sizeof(*tree_id)) == -1)
return got_error_from_errno("imsg_add ENUMERATED_TREE");
if (imsg_add(wbuf, &nentries, sizeof(nentries)) == -1)
return got_error_from_errno("imsg_add ENUMERATED_TREE");
- if (imsg_add(wbuf, path, path_len) == -1)
+ if (imsg_add(wbuf, &path_hash, sizeof(path_hash)) == -1)
return got_error_from_errno("imsg_add ENUMERATED_TREE");
imsg_close(ibuf, wbuf);
if (entries) {
- err = send_tree_entries(ibuf, entries, nentries);
+ err = send_enumerated_tree_entries(ibuf, entries, nentries);
if (err)
return err;
}
}
const struct got_error *
-got_privsep_send_object_enumeration_request(struct imsgbuf *ibuf)
+got_privsep_send_object_enumeration_request(struct imsgbuf *ibuf, uint32_t seed)
{
if (imsg_compose(ibuf, GOT_IMSG_OBJECT_ENUMERATION_REQUEST,
- 0, 0, -1, NULL, 0) == -1)
+ 0, 0, -1, &seed, sizeof(seed)) == -1)
return got_error_from_errno("imsg_compose "
"OBJECT_ENUMERATION_REQUEST");
return NULL;
}
+static const struct got_error *
+recv_enumerated_tree_entries(void *data, size_t datalen,
+ struct got_tree_object *tree, int *nentries, int algo)
+{
+ const struct got_error *err = NULL;
+ struct got_imsg_enumerated_tree_entries *ientries;
+ struct got_tree_entry *te;
+ size_t te_offset;
+ size_t i;
+
+ if (datalen <= sizeof(*ientries) ||
+ datalen > MAX_IMSGSIZE - IMSG_HEADER_SIZE)
+ return got_error(GOT_ERR_PRIVSEP_LEN);
+
+ ientries = (struct got_imsg_enumerated_tree_entries *)data;
+ if (ientries->nentries > INT_MAX) {
+ return got_error_msg(GOT_ERR_NO_SPACE,
+ "too many tree entries");
+ }
+
+ te_offset = sizeof(*ientries);
+ for (i = 0; i < ientries->nentries; i++) {
+ struct got_imsg_enumerated_tree_entry ite;
+ uint8_t *buf = (uint8_t *)data + te_offset;
+
+ if (te_offset + sizeof(ite) > datalen) {
+ err = got_error(GOT_ERR_PRIVSEP_LEN);
+ break;
+ }
+
+ /* Might not be aligned, size is ~40 bytes. */
+ memcpy(&ite, buf, sizeof(ite));
+
+ if (*nentries >= tree->nentries) {
+ err = got_error(GOT_ERR_PRIVSEP_LEN);
+ break;
+ }
+ te = &tree->entries[*nentries];
+ memcpy(te->id.hash, ite.id, sizeof(te->id.hash));
+ te->id.algo = algo;
+ te->mode = ite.mode;
+ te->idx = *nentries;
+ (*nentries)++;
+
+ te_offset += sizeof(ite);
+ }
+
+ return err;
+}
+
const struct got_error *
got_privsep_recv_enumerated_objects(int *found_all_objects,
struct imsgbuf *ibuf,
got_object_enumerate_commit_cb cb_commit,
got_object_enumerate_tree_cb cb_tree, void *cb_arg,
- struct got_repository *repo)
+ struct got_repository *repo, enum got_hash_algorithm algo)
{
const struct got_error *err = NULL;
struct imsg imsg;
struct got_tree_object tree;
struct got_imsg_enumerated_tree *itree;
struct got_object_id tree_id;
- char *path = NULL, *canon_path = NULL;
- size_t datalen, path_len;
+ uint32_t path_hash = 0;
+ size_t datalen;
int nentries = -1;
int done = 0;
err = got_error(GOT_ERR_PRIVSEP_MSG);
break;
}
- if (datalen < sizeof(*itree)) {
+ if (datalen != sizeof(*itree)) {
err = got_error(GOT_ERR_PRIVSEP_LEN);
break;
}
itree = imsg.data;
- path_len = datalen - sizeof(*itree);
- if (path_len == 0) {
- err = got_error(GOT_ERR_PRIVSEP_LEN);
- break;
- }
memcpy(&tree_id, &itree->id, sizeof(tree_id));
- free(path);
- path = strndup(imsg.data + sizeof(*itree), path_len);
- if (path == NULL) {
- err = got_error_from_errno("strndup");
+ if (tree_id.algo != algo) {
+ err = got_error(GOT_ERR_HASH_ALGO);
break;
}
- free(canon_path);
- canon_path = malloc(path_len + 1);
- if (canon_path == NULL) {
- err = got_error_from_errno("malloc");
- break;
- }
- if (!got_path_is_absolute(path)) {
- err = got_error(GOT_ERR_BAD_PATH);
- break;
- }
- if (got_path_is_root_dir(path)) {
- /* XXX check what got_canonpath() does wrong */
- canon_path[0] = '/';
- canon_path[1] = '\0';
- } else {
- err = got_canonpath(path, canon_path,
- path_len + 1);
- if (err)
- break;
- }
- if (strcmp(path, canon_path) != 0) {
- err = got_error(GOT_ERR_BAD_PATH);
- break;
- }
+ memcpy(&path_hash, &itree->path_hash,
+ sizeof(path_hash));
if (nentries != -1) {
err = got_error(GOT_ERR_PRIVSEP_MSG);
break;
if (itree->nentries == -1) {
/* Tree was not found in pack file. */
err = cb_tree(cb_arg, NULL, mtime, &tree_id,
- path, repo);
+ path_hash, repo);
break;
}
if (itree->nentries > INT_MAX) {
}
if (itree->nentries == 0) {
err = cb_tree(cb_arg, &tree, mtime, &tree_id,
- path, repo);
+ path_hash, repo);
if (err)
break;
nentries = 0;
}
break;
- case GOT_IMSG_TREE_ENTRIES:
+ case GOT_IMSG_ENUMERATED_TREE_ENTRIES:
/* Should be preceeded by GOT_IMSG_ENUMERATED_TREE. */
if (nentries <= -1) {
err = got_error(GOT_ERR_PRIVSEP_MSG);
break;
}
- err = recv_tree_entries(imsg.data, datalen,
- &tree, &nentries);
+ err = recv_enumerated_tree_entries(imsg.data, datalen,
+ &tree, &nentries, algo);
if (err)
break;
if (tree.nentries == nentries) {
err = cb_tree(cb_arg, &tree, mtime, &tree_id,
- path, repo);
+ path_hash, repo);
if (err)
break;
break;
case GOT_IMSG_TREE_ENUMERATION_DONE:
/* All trees have been found and traversed. */
- if (!have_commit || path == NULL || nentries != -1) {
+ if (!have_commit || nentries != -1) {
err = got_error(GOT_ERR_PRIVSEP_MSG);
break;
}
break;
}
- free(path);
- free(canon_path);
free(tree.entries);
return err;
}
blob - 38ebbc8a7bb593a63a64b685ceeb581ec854d1945b3b4853ba70dcdbc8bb1559
blob + 53534769132cee786d810be9516e40233da69eebfccbcc50968e30fcdbb68a70
--- libexec/got-fetch-pack/Makefile
+++ libexec/got-fetch-pack/Makefile
PROG= got-fetch-pack
SRCS= got-fetch-pack.c error.c inflate.c object_parse.c \
path.c privsep.c hash.c pkt.c gitproto.c ratelimit.c \
- pollfd.c object_qid.c
+ pollfd.c object_qid.c murmurhash2.c
CPPFLAGS = -I${.CURDIR}/../../include -I${.CURDIR}/../../lib
blob - c6579efc18f2b33d6b37852067c3972089d51152cb1475e9898f8514d8756f3c
blob + d707c3efadbcade2c0a33398f0346217d8f5c61bc4740fe013ce53274d418bac
--- libexec/got-index-pack/Makefile
+++ libexec/got-index-pack/Makefile
PROG= got-index-pack
SRCS= got-index-pack.c error.c inflate.c object_parse.c object_idset.c \
delta_cache.c delta.c pack.c path.c privsep.c hash.c ratelimit.c \
- pack_index.c pollfd.c object_qid.c
+ pack_index.c pollfd.c object_qid.c murmurhash2.c
CPPFLAGS = -I${.CURDIR}/../../include -I${.CURDIR}/../../lib
blob - 69251d700dfce7cb832f7c7e5b2210bc7c83d5c11599ec7f033fd15587350377
blob + 8064e1634d3fd5c166834c9409843954fdfc164188fcaa58d87f03dc4de6b7b4
--- libexec/got-read-blob/Makefile
+++ libexec/got-read-blob/Makefile
PROG= got-read-blob
SRCS= got-read-blob.c error.c inflate.c object_parse.c \
- object_qid.c path.c privsep.c hash.c pollfd.c
+ object_qid.c path.c privsep.c hash.c pollfd.c \
+ murmurhash2.c
CPPFLAGS = -I${.CURDIR}/../../include -I${.CURDIR}/../../lib
blob - baf6898e5e81dc21c5bd058488fd6bf1fbfc1fa959ba323f343d81c4c21d811e
blob + b860c568073f2d9f01f594b9eb343af3ff052c64c6ede2c7e69181c1e3e642f5
--- libexec/got-read-commit/Makefile
+++ libexec/got-read-commit/Makefile
PROG= got-read-commit
SRCS= got-read-commit.c error.c inflate.c object_parse.c \
- object_qid.c path.c privsep.c hash.c pollfd.c
+ object_qid.c path.c privsep.c hash.c pollfd.c \
+ murmurhash2.c
CPPFLAGS = -I${.CURDIR}/../../include -I${.CURDIR}/../../lib
blob - 2875902f87ac058f6cb1207df00e583aa2dc29c8756d8cca64f7473e39dc369c
blob + f1404c991ebc5d3061735b7392d951cef7d203db789c821026d2077a289e0ac0
--- libexec/got-read-gitconfig/Makefile
+++ libexec/got-read-gitconfig/Makefile
PROG= got-read-gitconfig
SRCS= got-read-gitconfig.c error.c inflate.c object_parse.c \
- path.c privsep.c hash.c gitconfig.c pollfd.c object_qid.c
+ path.c privsep.c hash.c gitconfig.c pollfd.c object_qid.c \
+ murmurhash2.c
CPPFLAGS = -I${.CURDIR}/../../include -I${.CURDIR}/../../lib
blob - 123adf46a00ec9bdf79ccfc7c169dd021fb3884002977714bff2784043ae2db3
blob + 5938c6a3b4c180ad25fdf403aa40a767a102463406fa10982228822b8a9b0593
--- libexec/got-read-gotconfig/Makefile
+++ libexec/got-read-gotconfig/Makefile
PROG= got-read-gotconfig
SRCS= got-read-gotconfig.c error.c inflate.c object_parse.c \
- path.c privsep.c hash.c parse.y pollfd.c object_qid.c
+ path.c privsep.c hash.c parse.y pollfd.c object_qid.c \
+ murmurhash2.c
CPPFLAGS = -I${.CURDIR}/../../include -I${.CURDIR}/../../lib -I${.CURDIR}
YFLAGS =
blob - bca85acf0c2df6134f79e46585f75b18b295a5af7f3933d1ac2e7db765093c37
blob + 30f0c22c9f7c72c824a43b308a560265d3c78b15c7d04473649599f5c644a54f
--- libexec/got-read-object/Makefile
+++ libexec/got-read-object/Makefile
PROG= got-read-object
SRCS= got-read-object.c error.c inflate.c object_parse.c \
- object_qid.c path.c privsep.c hash.c pollfd.c
+ object_qid.c path.c privsep.c hash.c pollfd.c murmurhash2.c
CPPFLAGS = -I${.CURDIR}/../../include -I${.CURDIR}/../../lib
blob - f66c3746d91e57b2304758663232eaef8e3bb2c5d1539654ca7eecd49085c6b0
blob + 24aead8e5067733d5b36fcd6d963a51ed8723fca31e81157f7d8eeab53807e18
--- libexec/got-read-pack/Makefile
+++ libexec/got-read-pack/Makefile
PROG= got-read-pack
SRCS= got-read-pack.c delta.c error.c inflate.c object_cache.c \
object_idset.c object_parse.c opentemp.c pack.c path.c \
- privsep.c hash.c delta_cache.c pollfd.c object_qid.c
+ privsep.c hash.c delta_cache.c pollfd.c object_qid.c \
+ murmurhash2.c
CPPFLAGS = -I${.CURDIR}/../../include -I${.CURDIR}/../../lib
blob - 648393cf062ff65d428f8c1726f76723fdc54f3b9d29550d1245a70678174ae9
blob + 9b649722260c35accfcb4b5de56c426f821490a5e33fcf1ae6f6ece62e30dce5
--- libexec/got-read-pack/got-read-pack.c
+++ libexec/got-read-pack/got-read-pack.c
#include "got_lib_privsep.h"
#include "got_lib_pack.h"
+#include "murmurhash2.h"
+
#ifndef nitems
#define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
#endif
static const struct got_error *
enumerate_tree(int *have_all_entries, struct imsgbuf *ibuf, size_t *totlen,
- struct got_object_id *tree_id,
- const char *path, struct got_pack *pack, struct got_packidx *packidx,
+ struct got_object_id *tree_id, const char *path, uint32_t seed,
+ struct got_pack *pack, struct got_packidx *packidx,
struct got_object_cache *objcache, struct got_object_idset *idset,
struct enumerated_tree **trees, size_t *nalloc, size_t *ntrees)
{
struct got_object_qid *eqid = NULL;
struct got_parsed_tree_entry *pte = &entries[i];
char *p;
+ size_t plen;
if (!S_ISDIR(pte->mode))
continue;
eqid->id.algo = pte->algo;
memcpy(&eqid->id.hash, pte->id, pte->digest_len);
- if (asprintf(&p, "%s%s%s", path,
+ plen = asprintf(&p, "%s%s%s", path,
got_path_is_root_dir(path) ? "" : "/",
- pte->name) == -1) {
+ pte->name);
+ if (plen == -1) {
err = got_error_from_errno("asprintf");
got_object_qid_free(eqid);
goto done;
}
+ pte->path_hash = murmurhash2(p, plen, seed);
eqid->data = p;
STAILQ_INSERT_TAIL(&ids, eqid, entry);
}
for (i = 0; i < *ntrees; i++) {
tree = &(*trees)[i];
err = got_privsep_send_enumerated_tree(totlen,
- ibuf, &tree->id, tree->path, tree->entries,
+ ibuf, &tree->id, tree->path, seed, tree->entries,
tree->nentries);
if (err)
goto done;
* entire tree the slow way.
*/
err = got_privsep_send_enumerated_tree(totlen, ibuf,
- tree_id, "/", NULL, -1);
+ tree_id, "/", 0, NULL, -1);
if (err)
goto done;
}
int i, idx, have_all_entries = 1;
struct enumerated_tree *trees = NULL;
size_t ntrees = 0, nalloc = 16, nids = 0;
+ uint32_t seed;
STAILQ_INIT(&commit_ids);
+ if (imsg_get_data(imsg, &seed, sizeof(seed)) == -1)
+ return got_error(GOT_ERR_PRIVSEP_LEN);
+
trees = calloc(nalloc, sizeof(*trees));
if (trees == NULL)
return got_error_from_errno("calloc");
if (idx == -1) {
have_all_entries = 0;
err = got_privsep_send_enumerated_tree(&totlen, ibuf,
- tree_id, "/", NULL, -1);
+ tree_id, "/", 0, NULL, -1);
if (err)
goto done;
break;
}
err = enumerate_tree(&have_all_entries, ibuf, &totlen,
- tree_id, "/", pack, packidx, objcache, idset,
+ tree_id, "/", seed, pack, packidx, objcache, idset,
&trees, &nalloc, &ntrees);
if (err)
goto done;
blob - ff6ec4d6af95e1a3db3807555902fc0738bc426fe0dbefc6a0d6aa2d88c4dcad
blob + 5f4e4e43a8a6b6f383bf42ff56f023280351174e122b16dab47ea45db2eaa5e6
--- libexec/got-read-patch/Makefile
+++ libexec/got-read-patch/Makefile
PROG= got-read-patch
SRCS= got-read-patch.c error.c inflate.c object_parse.c \
- path.c privsep.c hash.c pollfd.c object_qid.c
+ path.c privsep.c hash.c pollfd.c object_qid.c murmurhash2.c
CPPFLAGS = -I${.CURDIR}/../../include -I${.CURDIR}/../../lib
blob - 996e45896921e5e9bf9feb7bfbc403cb8c77478eac425e485499841236bdfbc4
blob + 2a6062de6ef36f4f249d11f3bcd65e5590f43ab620d06c8e7c56ebb81b0f3224
--- libexec/got-read-tag/Makefile
+++ libexec/got-read-tag/Makefile
PROG= got-read-tag
SRCS= got-read-tag.c error.c inflate.c object_parse.c \
- object_qid.c path.c privsep.c hash.c pollfd.c
+ object_qid.c path.c privsep.c hash.c pollfd.c murmurhash2.c
CPPFLAGS = -I${.CURDIR}/../../include -I${.CURDIR}/../../lib
blob - b20fda233186b6ab3cc9cc62d159cfd4e84273c16cfc583f254740a42a73f052
blob + 647be2b660e6049f8bf5ebe5f920631b8f4e70609ffd5bde5cd71389234eccfe
--- libexec/got-read-tree/Makefile
+++ libexec/got-read-tree/Makefile
PROG= got-read-tree
SRCS= got-read-tree.c error.c inflate.c object_parse.c \
- object_qid.c path.c privsep.c hash.c pollfd.c
+ object_qid.c path.c privsep.c hash.c pollfd.c murmurhash2.c
CPPFLAGS = -I${.CURDIR}/../../include -I${.CURDIR}/../../lib
blob - 4c1c1586c6804815604ac182f4b30f2b43c1dc70476e9ce0f466ff081e20438f
blob + 59eecabea04b192d03aeca3c7e4eca9402e02e81a2be40704407b461908a9965
--- libexec/got-send-pack/Makefile
+++ libexec/got-send-pack/Makefile
PROG= got-send-pack
SRCS= got-send-pack.c error.c inflate.c object_parse.c \
path.c privsep.c hash.c pkt.c gitproto.c ratelimit.c \
- pollfd.c reference_parse.c object_qid.c
+ pollfd.c reference_parse.c object_qid.c murmurhash2.c
CPPFLAGS = -I${.CURDIR}/../../include -I${.CURDIR}/../../lib