romkatv / libgit2

A cross-platform, linkable library implementation of Git that you can use in your application.
https://libgit2.org/
Other
7 stars 3 forks source link

Allow partial clones in libgit2 #3

Closed hoffbrinkle closed 3 years ago

hoffbrinkle commented 3 years ago

There shouldn't be anything that gitstatus does that would be affected by having a partial clone.

romkatv commented 3 years ago

How can I create a repository for which this PR will have some effect?

hoffbrinkle commented 3 years ago

How can I create a repository for which this PR will have some effect?

git clone --filter=blob:none

That will pull all the metadata from a source but none of the blobs (the blobs will be fetched as needed). For instance, with the above clone, you'll see the pull of the metadata, then pull of the blobs needed to do the initial checkout (--no-checkout would avoid the pull of even those blobs).

romkatv commented 3 years ago

How can I create a repository for which this PR will have some effect?

git clone --filter=blob:none

Here's what I've tried:

❯ zsh -f
adam% git clone --filter=blob:none https://github.com/romkatv/gitstatus.git
Cloning into 'gitstatus'...
remote: Enumerating objects: 22, done.
remote: Counting objects: 100% (22/22), done.
remote: Compressing objects: 100% (17/17), done.
remote: Total 2913 (delta 8), reused 19 (delta 5), pack-reused 2891
Receiving objects: 100% (2913/2913), 366.96 KiB | 472.00 KiB/s, done.
Resolving deltas: 100% (1599/1599), done.
remote: Enumerating objects: 40, done.
remote: Counting objects: 100% (40/40), done.
remote: Compressing objects: 100% (40/40), done.
remote: Total 61 (delta 12), reused 0 (delta 0), pack-reused 21
Receiving objects: 100% (61/61), 109.09 KiB | 781.00 KiB/s, done.
Resolving deltas: 100% (13/13), done.
Updating files: 100% (62/62), done.
adam% cd gitstatus
adam% source gitstatus.prompt.zsh
romka@adam /tmp/test/gitstatus master
% touch x
romka@adam /tmp/test/gitstatus master ?1
% echo >>LICENSE
romka@adam /tmp/test/gitstatus master !1 ?1
%

It appears that the stock version of gitstatus can correctly show status of a repository cloned with --filter=blob:none.

What are you looking to accomplish with this PR? How can I see the difference it would make?

hoffbrinkle commented 3 years ago

I just duplicated this and can confirm your observation. The key here is I originally had git 2.17.1 (the version that comes with Ubuntu 18.04 LTS). That version of git puts this in the repository config:

[extensions]
        partialclone = origin

Since then I've upgraded to git 2.29.2. The diff in the config generated is:

--- config      2020-12-09 13:17:42.728447068 -0500
+++ gitstatus/.git/config       2020-12-09 13:19:22.828364733 -0500
@@ -3,12 +3,11 @@
        filemode = true
        bare = false
        logallrefupdates = true
-       partialclonefilter = blob:none
 [remote "origin"]
        url = https://github.com/romkatv/gitstatus.git
        fetch = +refs/heads/*:refs/remotes/origin/*
-[extensions]
-       partialclone = origin
+       promisor = true
+       partialclonefilter = blob:none
 [branch "master"]
        remote = origin
        merge = refs/heads/master

I believe the extension is the older, less flexible way as it only allows a single remote to be a partial source, and the newer way allows multiple remotes to be partial sources (or promisors).

The current version of gitstatus will ignore a repository with unknown extensions, of which partialclone is one of those. The extension is still a valid way to specify a promisor remote.

Given that the default behavior of newer versions of git set up the partial clone in a way that gitstatus can handle, I'm okay with dropping this pull request.

romkatv commented 3 years ago

Given that the default behavior of newer versions of git set up the partial clone in a way that gitstatus can handle, I'm okay with dropping this pull request.

SGTM. Merging this PR would require work because I would have to be sure that it's indeed safe to ignore this extension. Given that the PR doesn't appear to have a purpose for the users of newer Git, it's better to close it.

hoffbrinkle commented 3 years ago

Agreed.