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

Re: [PATCH 7/9] difftool: teach difftool to handle directory diffs

From
Tim Henigan <tim.henigan@gmail.com>
Date
Mar 20, 2012, 17:43 UTC
Message-ID
<CAFouetiSyTFAR=CJBuYEcpUDq=f2jVaOMnsThgEP-zSbTH1H_g@mail.gmail.com>
In-Reply-To
<1331949574-15192-1-git-send-email-tim.henigan@gmail.com>

I have run into a problem with the way that the tmp directories are populated using 'git update-index' and 'git checkout-index'. I would appreciate any feedback that may help me understand what I am doing wrong.

This is in regard to the following section of code:
On Fri, Mar 16, 2012 at 9:59 PM, Tim Henigan <tim.henigan@gmail.com> wrote:
Show 7 quoted lines
>
> +sub setup_dir_diff
> +{
> +       # Run the diff; exit immediately if no diff found
> +       my $repo = Git->repository();
> +       my $diffrtn = $repo->command_oneline(['diff', '--raw', '--no-abbrev', '-z', @ARGV]);
> +       exit(0) if (length($diffrtn) == 0);
<snip>
Show 32 quoted lines
> +       my @rawdiff = split('\0', $diffrtn);
> +
> +       for (my $i=0; $i<@rawdiff; $i+=2) {
> +               my ($lmode, $rmode, $lsha1, $rsha1, $status) = split(' ', substr($rawdiff[$i], 1));
> +               my $path = $rawdiff[$i + 1];
> +
> +               if (($lmode eq $submodule_mode) or ($rmode eq $submodule_mode)) {
> +                       $submodule{$path}{left} = $lsha1;
> +                       $submodule{$path}{right} = $rsha1;
> +                       next;
> +               }
> +
> +               if ($lmode ne $null_mode) {
> +                       $lindex .= "$lmode $lsha1\t$path\0";
> +               }
> +
> +               if ($rmode ne $null_mode) {
> +                       if ($rsha1 ne $null_sha1) {
> +                               $rindex .= "$rmode $rsha1\t$path\0";
> +                       } else {
> +                               push(@working_tree, $path);
> +                       }
> +               }
> +       }
> +
> +       # Populate the left and right directories based on each index file
> +       my ($inpipe, $ctx);
> +       $ENV{GIT_INDEX_FILE} = "$tmpdir/lindex";
> +       ($inpipe, $ctx) = $repo->command_input_pipe(qw/update-index -z --index-info/);
> +       print($inpipe $lindex);
> +       $repo->command_close_pipe($inpipe, $ctx);
> +       $repo->command_oneline(["checkout-index", "-a", "--prefix=$ldir/"]);
When run from the root directory of a Git repository, the 'difftool
--dir-diff' command operates as expected:
  - Temporary index files for each side of the diff are created using
'git update-index'.
  - 'git checkout-index --all --prefix=$tmp' is used to populate the
tmp directory based on the index file.
However, when 'difftool --dir-diff' is run from a subdirectory of the
Git repository, there are problems.
  - The temporary index file generated by 'git update-index' appears
to be correct.
  - 'git checkout-index --all --prefix=$tmp' command does not work
(output tmp dir is empty).

I have tried some combinations of setting $ENV{GIT_DIR} and $ENV{GIT_WORK_TREE}, but it has not fixed the problem. Is there anything obvious that I missed?

Previous: Tim HeniganNext: Junio C Hamano
Message 6 of 8 in “difftool: teach difftool to handle directory diffs”
  1. 7/9 difftool: teach difftool to handle directory diffsTim Henigan, Mar 17, 2012
  2. David AguilarMar 17, 2012
  3. Tim HeniganMar 17, 2012
  4. Jakub NarebskiMar 17, 2012
  5. Tim HeniganMar 18, 2012
  6. Tim HeniganMar 20, 2012
  7. Junio C HamanoMar 20, 2012
  8. Tim HeniganMar 20, 2012

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.