Don't fetch objects we don't need in local transport. Hide all local refs in the revwalk. Packbuilder should not add hidden trees or blobs.
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
diff --git a/src/pack-objects.c b/src/pack-objects.c
index 9f62322..8ca6403 100644
--- a/src/pack-objects.c
+++ b/src/pack-objects.c
@@ -1641,7 +1641,7 @@ int insert_tree(git_packbuilder *pb, git_tree *tree)
if ((error = retrieve_object(&obj, pb, git_tree_id(tree))) < 0)
return error;
- if (obj->seen)
+ if (obj->seen || obj->uninteresting)
return 0;
obj->seen = 1;
@@ -1665,6 +1665,10 @@ int insert_tree(git_packbuilder *pb, git_tree *tree)
break;
case GIT_OBJ_BLOB:
+ if ((error = retrieve_object(&obj, pb, git_tree_id(tree))) < 0)
+ return error;
+ if (obj->uninteresting)
+ continue;
name = git_tree_entry_name(entry);
if ((error = git_packbuilder_insert(pb, entry_id, name)) < 0)
return error;
diff --git a/src/transports/local.c b/src/transports/local.c
index 4eae9de..9ec6ab6 100644
--- a/src/transports/local.c
+++ b/src/transports/local.c
@@ -503,6 +503,21 @@ static int local_counting(int stage, unsigned int current, unsigned int total, v
return error;
}
+static int foreach_reference_cb(git_reference *reference, void *payload)
+{
+ git_revwalk *walk = (git_revwalk *)payload;
+
+ int error = git_revwalk_hide(walk, git_reference_target(reference));
+ /* The reference is in the local repository, so the target may not
+ * exist on the remote. It also may not be a commit. */
+ if (error == GIT_ENOTFOUND || error == GITERR_INVALID) {
+ giterr_clear();
+ error = 0;
+ }
+
+ return error;
+}
+
static int local_download_pack(
git_transport *transport,
git_repository *repo,
@@ -542,11 +557,6 @@ static int local_download_pack(
if (git_object_type(obj) == GIT_OBJ_COMMIT) {
/* Revwalker includes only wanted commits */
error = git_revwalk_push(walk, &rhead->oid);
- if (!error && !git_oid_iszero(&rhead->loid)) {
- error = git_revwalk_hide(walk, &rhead->loid);
- if (error == GIT_ENOTFOUND)
- error = 0;
- }
} else {
/* Tag or some other wanted object. Add it on its own */
error = git_packbuilder_insert_recur(pack, &rhead->oid, rhead->name);
@@ -556,6 +566,9 @@ static int local_download_pack(
goto cleanup;
}
+ if ((error = git_reference_foreach(repo, foreach_reference_cb, walk)))
+ goto cleanup;
+
if ((error = git_packbuilder_insert_walk(pack, walk)))
goto cleanup;