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

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

From
Duy Nguyen <pclouds@gmail.com>
Date
Jan 23, 2013, 08:55 UTC
Message-ID
<CACsJy8DskoCi9Lg+HW0JeQBe4HX-bMXNHUgfrsg+DoqBN9-ntQ@mail.gmail.com>
In-Reply-To
<1358928767-16283-1-git-send-email-hjemli@gmail.com>
On Wed, Jan 23, 2013 at 3:12 PM, Lars Hjemli <hjemli@gmail.com> wrote:
> +NAME
> +----
> +git-all - Execute a git command in multiple repositories
I agree with Junio "git-all" is too generic. Maybe "git-for-each-repo"
Show 11 quoted lines
> +static int get_repo_state()
> +{
> +       const char *diffidx[] = {"diff", "--quiet", "--cached", NULL};
> +       const char *diffwd[] = {"diff", "--quiet", NULL};
> +
> +       if (run_command_v_opt(diffidx, RUN_GIT_CMD) != 0)
> +               return DIRTY;
> +       if (run_command_v_opt(diffwd, RUN_GIT_CMD) != 0)
> +               return DIRTY;
> +       return CLEAN;
> +}

Perhaps we could add the subrepo's object data to the in-memory object database of git-all, then do the diff without launching new commands?

Show 45 quoted lines
> +static int walk(struct strbuf *path, int argc, const char **argv)
> +{
> +       DIR *dir;
> +       struct dirent *ent;
> +       struct stat st;
> +       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_addstr(path, ent->d_name);
> +                       setenv(GIT_DIR_ENVIRONMENT, path->buf, 1);
> +                       strbuf_setlen(path, len - 1);
> +                       setenv(GIT_WORK_TREE_ENVIRONMENT, path->buf, 1);
> +                       handle_repo(path->buf, argv);
> +                       strbuf_addstr(path, "/");
> +                       continue;
> +               }
> +               strbuf_setlen(path, len);
> +               strbuf_addstr(path, ent->d_name);
> +               switch (DTYPE(ent)) {
> +               case DT_UNKNOWN:
> +                       /* Use stat() instead of lstat(), since we want to
> +                        * know if we can follow this path into another
> +                        * directory - it's  not important if it's actually
> +                        * a symlink which gets us there.
> +                        */
> +                       if (stat(path->buf, &st) || !S_ISDIR(st.st_mode))
> +                               break;
> +                       /* fallthrough */
> +               case DT_DIR:
> +                       walk(path, argc, argv);
> +                       break;
> +               }
> +               strbuf_setlen(path, len);
> +       }
> +       closedir(dir);
> +       return 0;
> +}

I'm not a user of this command so this is more of bikeshedding. I think we should have an option to list repos listed in index. For directory walk, how about reusing fill_directory() to do the job for you? You could then limit repositories by name. "ls-files -o" code should be very similar.

-- 
Duy
Previous: Lars HjemliNext: Lars Hjemli
Message 2 of 9 in “all: new command used for multi-repo operations”
  1. all: new command used for multi-repo operationsLars Hjemli, Jan 23, 2013
  2. Duy NguyenJan 23, 2013
  3. Lars HjemliJan 23, 2013
  4. Duy NguyenJan 23, 2013
  5. Jens LehmannJan 23, 2013
  6. Junio C HamanoJan 23, 2013
  7. Junio C HamanoJan 23, 2013
  8. Lars HjemliJan 23, 2013
  9. Lars HjemliJan 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.