Re: What is an efficient way to get all blobs / trees that have notes attached?
- From
Johan Herland <johan@herland.net>
- Date
- Apr 1, 2016, 12:16 UTC
- Message-ID
- <CALKQrgdytYJtMTBHXbcRQ_iT5rWakZCxxqRW1rpLsPiSejud-Q@mail.gmail.com>
- In-Reply-To
- <ndljs8$vj3$1@ger.gmane.org>
On Fri, Apr 1, 2016 at 12:51 PM, Sebastian Schuberth <sschuberth@gmail.com> wrote:
Show 15 quoted lines
> Hi, > > I'm curious whether there's a more efficient way to get a list of blobs / > trees (and their names) that have notes attached than doing this: > > 1) Get all notes refs I'm interested in (git-for-each-ref). > > 2) For each notes ref, get the list of notes (git-notes list) and store them > in a hash table that maps object hashes to notes. > > 3) Recursively list all blobs / trees (git-ls-tree) and look whether an > object's hash is conatined in our table to get its notes. > > In particular 3) could be expensive for repos with a lot of files as we're > looking at all of them just to see whether they have notes attached.
In (3), why would you need to search through _all_ blobs/trees? Would it not be cheaper to simply query the object type of each annotated object from (2)? I.e. something like:
for notes_ref in $(git for-each-ref refs/notes | cut -c 49-)
do
echo "--- $notes_ref ---"
for annotated_obj in $(git notes --ref=$notes_ref list | cut -c 41-)
do
type=$(git cat-file -t "$annotated_obj")
if test "$type" != "commit"
then
echo "$annotated_obj: $type"
fi
done
doneCan probably be made even faster by using the --batch option to cat-file...
...Johan
-- Johan Herland, <johan@herland.net> www.herland.net