git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: The most efficient way to test if repositories share the same objects

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Mar 22, 2018, 19:53 UTC
Message-ID
<87muyzyjhm.fsf@evledraar.gmail.com>
In-Reply-To
<xmqqlgejlx8e.fsf@gitster-ct.c.googlers.com>
On Thu, Mar 22 2018, Junio C. Hamano wrote:
Show 10 quoted lines
> Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
>
>> But of course that'll just give you the tips. You could then use `git
>> cat-file --batch-check` on both ends to see what commits from the other
>> they report knowing about, in case they have branches that are
>> ahead/behind the other.
>
> I am not sure how you are envisioning to use "cat-file
> --batch-check" here.  Do you mean to take "rev-list --all" output
> from both and compare, or something?
By doing something like this:
    (
        cd /tmp &&
        git clone http://github.com/gitster/git gitster-git;
        git clone http://github.com/avar/git avar-git;
        git -C gitster-git for-each-ref --format="%(object)" | git -C avar-git cat-file --batch-check|grep -E -o '(commit|missing)'|sort|uniq -c &&
        git -C avar-git for-each-ref --format="%(object)" | git -C gitster-git cat-file --batch-check|grep -E -o '(commit|missing)'|sort|uniq -c
    )
Which outputs:
    673 commit
    696 missing
    374 commit
    495 missing

Which of course, as noted, isn't going to be a good general solution in all cases, but it's blindingly fast, and since the original question is essentially that he's starting out with doing a rough equivalent of that, but for tags only, maybe it'll work for his use-case.

Show 6 quoted lines
> I am not sure how Konstantin defines "the most efficient", but if it
> is "with the smallest number of bits exchanged between the
> repositories", then the answer would probably be to find the root
> commit(s) in each repository and if they share any common root(s).
> If there isn't then there is no hope to share objects between them,
> of course.
Yes, that would probably be much better:
    diff -ru <(git -C avar-git log --oneline --pretty=format:%H --max-parents=0) \
             <(git -C gitster-git log --oneline --pretty=format:%H --max-parents=0) &&
    do_stuff_because_they_have_stuff_in_common
Previous: Junio C HamanoNext: Konstantin Ryabitsev
Message 4 of 8 in “The most efficient way to test if repositories share the same objects”
  1. Konstantin RyabitsevMar 22, 2018
  2. Ævar Arnfjörð BjarmasonMar 22, 2018
  3. Junio C HamanoMar 22, 2018
  4. Ævar Arnfjörð BjarmasonMar 22, 2018
  5. Konstantin RyabitsevMar 22, 2018
  6. Junio C HamanoMar 22, 2018
  7. Konstantin RyabitsevMar 23, 2018
  8. Ævar Arnfjörð BjarmasonMar 23, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.