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 missingWhich 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