Re: [PATCH RFC] diff: add SUBMODULE_DIFF format to display submodule diff
- From
Stefan Beller <sbeller@google.com>
- Date
- Aug 9, 2016, 22:50 UTC
- Message-ID
- <CAGZ79kbzDhpsfpY8s=7O86_dNLA=VRkyC=8eiCqMambKvUnXmw@mail.gmail.com>
- In-Reply-To
- <20160809223219.17982-1-jacob.e.keller@intel.com>
On Tue, Aug 9, 2016 at 3:32 PM, Jacob Keller <jacob.e.keller@intel.com> wrote:
Show 12 quoted lines
> From: Jacob Keller <jacob.keller@gmail.com> > > For projects which have frequent updates to submodules it is often > useful to be able to see a submodule update commit as a difference. > Teach diff's --submodule= a new "diff" format which will execute a diff > for the submodule between the old and new commit, and display it as > a standard diff. This allows users to easily see what changed in > a submodule without having to dig into the submodule themselves. > > Signed-off-by: Jacob Keller <jacob.keller@gmail.com> > --- > There are no tests yet. Stefan suggested the use of child_process,
Well you said "I just want this one command but don't know where to put it " so it's natural to suggest using child_process. ;)
Show 5 quoted lines
> but I > really believe there has to be some way of getting the diff without > having to run a sub process (as this means we also can't do the diff > without a checked out submodule). It doesn't properly handle options > either, so a better solution would be much appreciated.
Oh right, we would need to codify all options again (and all future options, too)
Show 9 quoted lines
> > I also would prefer if the diff actually prefixed the files with > "path/to/submodule" so that it was obvious where the file was located in > the directory. > > Suggestions welcome. > > + > + if (start_command(&cp))
I wonder if we want to stay single-execution here, i.e. if we rather want to use run_processes_parallel for all the submodules at the same time?
Though then non deterministic ordering may be an issue.
> + return -1; > + > + if (strbuf_read(buf, cp.out, 0) < 0)
So we keep the whole diff in memory I don't know much about the diff machinery, but I thought the rest of the diff machinery just streams it out?
Show 25 quoted lines
> +
> +void show_submodule_diff(FILE *f, const char *path,
> + const char *line_prefix,
> + unsigned char one[20], unsigned char two[20],
> + unsigned dirty_submodule, const char *meta,
> + const char *reset)
> +{
> + struct strbuf buf = STRBUF_INIT;
> + struct strbuf sb = STRBUF_INIT;
> + const char *message = NULL;
> +
> + if (dirty_submodule & DIRTY_SUBMODULE_UNTRACKED)
> + fprintf(f, "%sSubmodule %s contains untracked content\n",
> + line_prefix, path);
> + if (dirty_submodule & DIRTY_SUBMODULE_MODIFIED)
> + fprintf(f, "%sSubmodule %s contains modified content\n",
> + line_prefix, path);
> +
> + if (!hashcmp(one, two)) {
> + strbuf_release(&sb);
> + return;
> + }
> +
> + if (add_submodule_odb(path))
> + message = "(not checked out)";When not checked out, we can invoke the diff command in .git/modules/<name> as that is the git dir of the submodule, i.e. operating diff with a bare repo?
Thanks, Stefan