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

Re: [PATCH RFC] diff: add SUBMODULE_DIFF format to display submodule diff

From
Jacob Keller <jacob.keller@gmail.com>
Date
Aug 9, 2016, 22:56 UTC
Message-ID
<CA+P7+xqnALzwkgLXrP57BUtFGaxGudAEG7cmGTakP47ofFEjHQ@mail.gmail.com>
In-Reply-To
<CAGZ79kbzDhpsfpY8s=7O86_dNLA=VRkyC=8eiCqMambKvUnXmw@mail.gmail.com>
On Tue, Aug 9, 2016 at 3:50 PM, Stefan Beller <sbeller@google.com> wrote:
Show 16 quoted lines
> On Tue, Aug 9, 2016 at 3:32 PM, Jacob Keller <jacob.e.keller@intel.com> wrote:
>> 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.  ;)
Right this is a straight forward way..
Show 9 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)

That's why I'd prefer if we had a way to do this via builtins, because it would make option passing easier.

Show 16 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.

There is no easy way to do this, we're given it one module at a time and it would be a huge re-write to make it go in parallel. I think that's the wrong way to think about this.

Show 8 quoted lines
>
>> +               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?

Yea, but I can't figure out how to do that. Is there an easy way to stream chunks from the pipe straight into the file?

Show 30 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?

We can actually do this every time. How would you pass that in a child_process? I don't think it's "dir" but instead passing "--git-dir" somehow?

Thanks, Jake

>
> Thanks,
> Stefan
Previous: Stefan BellerNext: Stefan Beller
Message 4 of 7 in “diff: add SUBMODULE_DIFF format to display submodule diff”
  1. diff: add SUBMODULE_DIFF format to display submodule diffJacob Keller, Aug 9, 2016
  2. Junio C HamanoAug 9, 2016
  3. Stefan BellerAug 9, 2016
  4. Jacob KellerAug 9, 2016
  5. Stefan BellerAug 9, 2016
  6. Stefan BellerAug 9, 2016
  7. Johannes SixtAug 10, 2016

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.