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

Re: New to Git / Questions about single user / multiple projects

From
Jakub Narebski <jnareb@gmail.com>
Date
Aug 19, 2009, 13:20 UTC
Message-ID
<200908191520.56436.jnareb@gmail.com>
In-Reply-To
<20090819124820.GC20381@coredump.intra.peff.net>
On Wed, 19 August 2009, Jeff King <peff@peff.net> wrote:
Show 21 quoted lines
> On Wed, Aug 19, 2009 at 02:18:07PM +0200, Jakub Narebski wrote:
> 
> > More complicated solution, used by gitweb, requires Perl, not checked
> > that it works correctly, doesn't work with ancient repositories with
> > symlink HEAD.
> > 
> >  $ perl -e '
> >  use File::Find qw(find);
> >  my @list = ();
> >  find({follow_fast => 1, follow_skip => 2, dangling_symlinks => 0,
> >        wanted => sub {
> >          return if (m!^[/.]$!);
> >          return unless (-d $_);
> >          push @list, $_ if -e "$_/HEAD" 
> >        }});
> >  print join("\n", @list)."\n";
> >  '
> 
> That doesn't seem very accurate. It will find 'HEAD' in "logs/" of
> repositories with reflogs enabled, and "refs/remotes/*/" of cloned
> repositories, giving you a lot of false positives.

To be more exact it is simplified solution used by git; in this case _oversimplified_, as gitweb doesn't have problems with 'HEAD' in remote-tracking branches.

On the other hand gitweb currently does not detect submodules or submodule-like repositories, i.e. repositories inside working directory of other repository. So this could be improved...

Show 8 quoted lines
> 
> If you want accuracy, you can ask git rev-parse to verify whether a
> directory is a git repo; it actually uses a few different heuristics to
> check. For example:
> 
>   find . -type d |
>     while read dir; do
>       if GIT_DIR=$dir git rev-parse --git-dir >/dev/null 2>&1; then
Or "git --git-dir=$dir rev-parse 2> /dev/null"
Show 11 quoted lines
>         echo $dir
>       fi
>     done
> 
> but it is a bit slower, as you invoke rev-parse for every directory, and
> it actually does some verification of the contents of HEAD (so it is
> probably a bad idea for something like gitweb, which cares about
> performance).
> 
> If you want to do a cheap and fast check, searching for 'HEAD', 'refs',
> and 'objects' in the same directory is a reasonable heuristic.

If one follow preferred git conventions for naming non-bare repositories, and one doesn't have anything funny,

  $ find . -name "*.git" -type d
should be sufficient.
-- 
Jakub Narebski
Poland
Previous: Jeff King
Message 11 of 11 in “New to Git / Questions about single user / multiple projects”
  1. Rob (gmail)Aug 19, 2009
  2. Changsheng JiangAug 19, 2009
  3. Chris PackhamAug 19, 2009
  4. Daniel BarkalowAug 19, 2009
  5. Jakub NarebskiAug 19, 2009
  6. Rob (gmail)Aug 19, 2009
  7. Jakub NarebskiAug 19, 2009
  8. Rob (gmail)Aug 19, 2009
  9. Jeff KingAug 19, 2009
  10. Jeff KingAug 19, 2009
  11. Jakub NarebskiAug 19, 2009

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.