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

Re: [PATCH] all: new command used for multi-repo operations

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 23, 2013, 06:44 UTC
Message-ID
<7vy5fkiek0.fsf@alter.siamese.dyndns.org>
In-Reply-To
<CAJDDKr6exXh14m08HTihxREjSFgyPT0bN1cF8eUryXJHOgFL1A@mail.gmail.com>
David Aguilar <davvid@gmail.com> writes:
Show 25 quoted lines
>> +static int walk(struct strbuf *path, int argc, const char **argv)
>> +{
>> +       DIR *dir;
>> +       struct dirent *ent;
>> +       size_t len;
>> +
>> +       dir = opendir(path->buf);
>> +       if (!dir)
>> +               return errno;
>> +       strbuf_addstr(path, "/");
>> +       len = path->len;
>> +       while ((ent = readdir(dir))) {
>> +               if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, ".."))
>> +                       continue;
>> +               if (!strcmp(ent->d_name, ".git")) {
>> +                       strbuf_setlen(path, len - 1);
>> +                       chdir(path->buf);
>> +                       handle_repo(path->buf, argv);
>> +                       chdir(root);
>> +                       strbuf_addstr(path, "/");
>> +                       continue;
>> +               }
>
> Does this section above properly handle .git files (where .git is a
> file, not a directory)?

This scans a directory $D to ask "is there '.git' in you?" and if the answer is "yes", then hands $D (not "$D/.git") to handle_repo(). That logic will not miss a gitfile that points at the real $GIT_DIR elsewhere.

There is a recursive call to walk() later in the same loop when the found entry ent turns out to be a directory, and "$D/" + ent->d_name is given to this function.

But I do not think the loop structure of this function is right. If $D has ".git" in it, should it even try to feed other subdirectories of $D (say "$D/a") to itself in recursion to see if $D/a/.git exists?

I think it should be more like
	walk(struct strbuf *path)
        {
		size_t dirlen = path->len;
		int has_git;
		strbuf_addstr(path, "/.git");
		has_git = !lstat(path->buf);
		strbuf_setlen(path, dirlen);
                if (has_git) {
                        handle_repo(path->buf);
			return;
		}
                dir = opendir(path->buf);
		while ((ent = readdir(dir))) {
			... skip . and .. ...
			strbuf_addstr(path, ent->d_name);
			walk(path);
			strbuf_setlen(path, dirlen);
                }
	}

The determination of has_git can be a bit fancier than a simple !lstat() as you mentioned.

Previous: David AguilarNext: Lars Hjemli
Message 6 of 11 in “all: new command used for multi-repo operations”
  1. all: new command used for multi-repo operationsLars Hjemli, Jan 22, 2013
  2. Junio C HamanoJan 22, 2013
  3. Lars HjemliJan 22, 2013
  4. Junio C HamanoJan 23, 2013
  5. David AguilarJan 23, 2013
  6. Junio C HamanoJan 23, 2013
  7. Lars HjemliJan 23, 2013
  8. Junio C HamanoJan 23, 2013
  9. Duy NguyenJan 23, 2013
  10. Lars HjemliJan 23, 2013
  11. all: new command used for multi-repo operationsLars Hjemli, Jan 23, 2013

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.