threads / discuss / 17111

patches in context format ?

Subject: patches in context format ?

## tl;dr

7 messages between Jan 12, 2009 and Jan 12, 2009.

replies: 6people: 4as markdown or json

Christian MICHON· Jan 12, 2009, 09:00 UTC · lore

I'm maintaining a git tree of the vim project: this work can be seen at http://github.com/cmichon/vim

vim patches do not come as unified format, but only as context format instead (from a "diff -c").

The current solution I have is to use the original patch command, stage modifications and add new files. I do not like this solution, because I have to work out the commit messages out of the mbox and I lose reproducibility. I'm basically maintaining a subset of shell scripts, the original patches and an artificial way (ugly) to get timestamps of modifications (for the commit dates).

Instead of this complicated procedure, I'd like to use "git apply" or "git am", provided I can get git to support "context output format" as input for patches ?

I guess the answer is no, but has anyone on the list been working on this ? is there another way to translate from "context" to "unified" format ?

TIA
-- 
Christian
--
http://detaolb.sourceforge.net/, a linux distribution for Qemu with Git inside !
Junio C Hamano· Jan 12, 2009, 09:28 UTC · re: Christian MICHON · lore

Re: patches in context format ?

"Christian MICHON" <christian.michon@gmail.com> writes:
Show 9 quoted lines
> I'm maintaining a git tree of the vim project: this work can be seen
> at http://github.com/cmichon/vim
>
> vim patches do not come as unified format, but only as context format
> instead (from a "diff -c").
> ...
> I guess the answer is no, but has anyone on the list been working on
> this ? is there another way to translate from "context" to "unified"
> format ?
Not that I know of.

If you want to add support for the copied context format patches to your workflow, I think the first step (and easiest one) would be to find an external program that lets you convert from the copied context format to the unified context format. Perhaps "interdiff /dev/null copied >unified" would suffice (but I haven't tested this).

Then find the place that feeds "git apply" with a patch, and add an option to "git am" to instead do something like this:

- git apply --index "$dotest/patch" + case "$input_is_in_the_copied_context_format" + yes) + interdiff /dev/null "$dotest/patch" | git apply --index + ;; + *) + # unified context as before... + git apply --index "$dotest/patch" + ;; + esac

In the longer term, if we were to update "git-apply" to support the copied context format, I think we should take the same approach.

Inside read_patch_file(), you detect that the patch is in the copied context format, and convert it to the unified context format and return the result. All the rest of the program can then be left alone and you will have little chance of regression.

Christian MICHON· Jan 12, 2009, 09:52 UTC · re: Junio C Hamano · lore

Re: patches in context format ?

On Mon, Jan 12, 2009 at 10:28 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 12 quoted lines
>> I guess the answer is no, but has anyone on the list been working on
>> this ? is there another way to translate from "context" to "unified"
>> format ?
>
> Not that I know of.
>
> If you want to add support for the copied context format patches to your
> workflow, I think the first step (and easiest one) would be to find an
> external program that lets you convert from the copied context format to
> the unified context format.  Perhaps "interdiff /dev/null copied >unified"
> would suffice (but I haven't tested this).
>

interdiff is exactly what I needed (I used -p and -q switches, plus a substitution for the path).

Thanks for this! I guess there's not really a need to add this now in git-am, since I've seldom seen such context patches.

-- 
Christian
--
http://detaolb.sourceforge.net/, a linux distribution for Qemu with Git inside !
Teemu Likonen· Jan 12, 2009, 09:34 UTC · re: Christian MICHON · lore

Re: patches in context format ?

Christian MICHON (2009-01-12 10:00 +0100) wrote:
> is there another way to translate from "context" to "unified" format ?

Well, this is not exactly the best solution for a Vim user but this is the only way I know. Emacs can convert diffs between the formats. You don't even need to launch Emacs, just run it in batch mode:

    $ emacs --batch -Q --file input.diff \
        --eval '(diff-context->unified (point-min) (point-max))' \
        --eval '(save-buffer)'
Christian MICHON· Jan 12, 2009, 09:53 UTC · re: Teemu Likonen · lore

Re: patches in context format ?

On Mon, Jan 12, 2009 at 10:34 AM, Teemu Likonen <tlikonen@iki.fi> wrote:
Show 12 quoted lines
> Christian MICHON (2009-01-12 10:00 +0100) wrote:
>
>> is there another way to translate from "context" to "unified" format ?
>
> Well, this is not exactly the best solution for a Vim user but this is
> the only way I know. Emacs can convert diffs between the formats. You
> don't even need to launch Emacs, just run it in batch mode:
>
>    $ emacs --batch -Q --file input.diff \
>        --eval '(diff-context->unified (point-min) (point-max))' \
>        --eval '(save-buffer)'
>
you're asking a vim user to use emacs ? ;-)

thanks for the suggestion: I'll try it at least, but I think I'll stick to interdiff.

-- 
Christian
--
http://detaolb.sourceforge.net/, a linux distribution for Qemu with Git inside !
Jeff King· Jan 12, 2009, 09:52 UTC · re: Christian MICHON · lore

Re: patches in context format ?

On Mon, Jan 12, 2009 at 10:00:11AM +0100, Christian MICHON wrote:
Show 10 quoted lines
> The current solution I have is to use the original patch command,
> stage modifications and add new files. I do not like this solution,
> because I have to work out the commit messages out of the mbox and I
> lose reproducibility. I'm basically maintaining a subset of shell
> scripts, the original patches and an artificial way (ugly) to get
> timestamps of modifications (for the commit dates).
> 
> Instead of this complicated procedure, I'd like to use "git apply" or
> "git am", provided I can get git to support "context output format" as
> input for patches ?

Maybe this is not the nicest solution if you are going to apply a lot of these patches, but you can pick up where git-am fails, run patch, and ask it to resume:

  $ git am mbox-with-context-diff
  Applying: a minor change
  error: No changes
  Patch failed at 0001.
  When you have resolved this problem run "git am --resolved".
  If you would prefer to skip this patch, instead run "git am --skip".
  To restore the original branch and stop patching run "git am --abort".
  $ patch <.git/rebase-apply/patch ;# or whatever
  $ git add -u
  $ git am -r
  Applying: a minor change
-Peff
Christian MICHON· Jan 12, 2009, 09:57 UTC · re: Jeff King · lore

Re: patches in context format ?

On Mon, Jan 12, 2009 at 10:52 AM, Jeff King <peff@peff.net> wrote:
Show 32 quoted lines
> On Mon, Jan 12, 2009 at 10:00:11AM +0100, Christian MICHON wrote:
>
>> The current solution I have is to use the original patch command,
>> stage modifications and add new files. I do not like this solution,
>> because I have to work out the commit messages out of the mbox and I
>> lose reproducibility. I'm basically maintaining a subset of shell
>> scripts, the original patches and an artificial way (ugly) to get
>> timestamps of modifications (for the commit dates).
>>
>> Instead of this complicated procedure, I'd like to use "git apply" or
>> "git am", provided I can get git to support "context output format" as
>> input for patches ?
>
> Maybe this is not the nicest solution if you are going to apply a lot of
> these patches, but you can pick up where git-am fails, run patch, and
> ask it to resume:
>
>  $ git am mbox-with-context-diff
>  Applying: a minor change
>  error: No changes
>  Patch failed at 0001.
>  When you have resolved this problem run "git am --resolved".
>  If you would prefer to skip this patch, instead run "git am --skip".
>  To restore the original branch and stop patching run "git am --abort".
>
>  $ patch <.git/rebase-apply/patch ;# or whatever
>  $ git add -u
>  $ git am -r
>  Applying: a minor change
>
> -Peff
>

vim patches are in hundredth... so I guess this is too manual. Thanks for the suggestion!

-- 
Christian
--
http://detaolb.sourceforge.net/, a linux distribution for Qemu with Git inside !

← back to recent threads