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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Jan 23, 2013 at 3:12 PM, Lars Hjemli <hjemli@xxxxxxxxx> 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"

> +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?

> +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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]