Skip to content

Commit 709768a

Browse files
committed
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 parent 42864e5 commit 709768a

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

src/pack-objects.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1641,7 +1641,7 @@ int insert_tree(git_packbuilder *pb, git_tree *tree)
16411641
if ((error = retrieve_object(&obj, pb, git_tree_id(tree))) < 0)
16421642
return error;
16431643

1644-
if (obj->seen)
1644+
if (obj->seen || obj->uninteresting)
16451645
return 0;
16461646

16471647
obj->seen = 1;
@@ -1665,6 +1665,10 @@ int insert_tree(git_packbuilder *pb, git_tree *tree)
16651665

16661666
break;
16671667
case GIT_OBJ_BLOB:
1668+
if ((error = retrieve_object(&obj, pb, git_tree_id(tree))) < 0)
1669+
return error;
1670+
if (obj->uninteresting)
1671+
continue;
16681672
name = git_tree_entry_name(entry);
16691673
if ((error = git_packbuilder_insert(pb, entry_id, name)) < 0)
16701674
return error;

src/transports/local.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,21 @@ static int local_counting(int stage, unsigned int current, unsigned int total, v
503503
return error;
504504
}
505505

506+
static int foreach_reference_cb(git_reference *reference, void *payload)
507+
{
508+
git_revwalk *walk = (git_revwalk *)payload;
509+
510+
int error = git_revwalk_hide(walk, git_reference_target(reference));
511+
/* The reference is in the local repository, so the target may not
512+
* exist on the remote. It also may not be a commit. */
513+
if (error == GIT_ENOTFOUND || error == GITERR_INVALID) {
514+
giterr_clear();
515+
error = 0;
516+
}
517+
518+
return error;
519+
}
520+
506521
static int local_download_pack(
507522
git_transport *transport,
508523
git_repository *repo,
@@ -542,11 +557,6 @@ static int local_download_pack(
542557
if (git_object_type(obj) == GIT_OBJ_COMMIT) {
543558
/* Revwalker includes only wanted commits */
544559
error = git_revwalk_push(walk, &rhead->oid);
545-
if (!error && !git_oid_iszero(&rhead->loid)) {
546-
error = git_revwalk_hide(walk, &rhead->loid);
547-
if (error == GIT_ENOTFOUND)
548-
error = 0;
549-
}
550560
} else {
551561
/* Tag or some other wanted object. Add it on its own */
552562
error = git_packbuilder_insert_recur(pack, &rhead->oid, rhead->name);
@@ -556,6 +566,9 @@ static int local_download_pack(
556566
goto cleanup;
557567
}
558568

569+
if ((error = git_reference_foreach(repo, foreach_reference_cb, walk)))
570+
goto cleanup;
571+
559572
if ((error = git_packbuilder_insert_walk(pack, walk)))
560573
goto cleanup;
561574

0 commit comments

Comments
 (0)