The testbot produced two results that I don't quite understand:

1. For #538846: undefined functions drush_error and drupal_save_session it says

Unable to apply patch drush_error.patch. This may be a -p0 (old style) patch, which is no longer supported by the testbots.

based on

[21:46:18] Command [git apply --check -p1 /var/lib/drupaltestbot/sites/default/files/review/drush_error.patch 2>&1] failed
  Duration 0 seconds
  Directory [/var/lib/drupaltestbot/sites/default/files/checkout/sites/default/modules/devel]
  Status [128]
 Output: [fatal: unable to find filename in patch at line 7].
[21:46:18] Command [git apply --check -p0 /var/lib/drupaltestbot/sites/default/files/review/drush_error.patch 2>&1] failed
  Duration 0 seconds
  Directory [/var/lib/drupaltestbot/sites/default/files/checkout/sites/default/modules/devel]
  Status [1]
 Output: [error: patch failed: devel_generate.drush.inc:45
error: devel_generate.drush.inc: patch does not apply].
[21:46:18] Encountered error on [apply], details:
array (
  '@filename' => 'drush_error.patch',
  '@reason' => 'This may be a -p0 (old style) patch, which is no longer supported by the testbots',
)

IOW, the patch didn't apply with -p0 either, but the testbot still suspects it might be a -p0 patch. (The patch is outdated and will never apply, no matter what -p you specify.)

 

2. For #1345240: Patch not to break xhprof reporting when site name contains spaces it finds

[21:46:22] Command [git apply --check -p1 /var/lib/drupaltestbot/sites/default/files/review/devel_0.patch 2>&1] failed
  Duration 0 seconds
  Directory [/var/lib/drupaltestbot/sites/default/files/checkout/sites/default/modules/devel]
  Status [128]
 Output: [fatal: unable to find filename in patch at line 3].
[21:46:22] Command [git apply --check -p0 /var/lib/drupaltestbot/sites/default/files/review/devel_0.patch 2>&1] succeeded
  Duration: 0 seconds
  Directory: [/var/lib/drupaltestbot/sites/default/files/checkout/sites/default/modules/devel]
  Completion status: [0]
  Output: no output.
[21:46:22] Encountered error on [apply], details:
array (
  '@filename' => 'devel_0.patch',
  '@reason' => 'See the log in the details link for more information',
)

If I interpret this correctly, then the patch would apply with -p0, just not with -p1, but this time the message does not mention -p0 and just says

Unable to apply patch devel_0.patch. See the log in the details link for more information.
instead.

 

I would have expected the messages to be the other way around.

Is there a documented rationale for rejecting -p0 patches? The -p0 message would benefit from including a link to an explanation.

I'm using git version 1.7.4.msysgit.0 and git apply applies the second patch just fine without having to specify -p, even though its documentation says it would default to -p1:

-p<n>

Remove <n> leading slashes from traditional diff paths. The default is 1.

I'm sure there must be a good reason for rejecting -p0 patches, but I can't explain to the well-meaning OP in #1345240: Patch not to break xhprof reporting when site name contains spaces why we insist on having the "a/" and "b/", especially when we have to go out of our way and specify -p1 to make the patch fail if they're missing.

CommentFileSizeAuthor
#5 drupal.demo_p0_patch.patch327 bytesrfay
#5 drupal.demo_p1_patch.patch335 bytesrfay
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jthorson’s picture

Didn't read your whole issue (way too sleepy right now), but more often than not, the -p0 message is a false positive ... there are a number of failure cases that result in that message, even for perfectly good -p1 formatted patches.

Edit: But looking at the age of the first issue ... it's probably legit in that case. To rephrase, the '-p0 message' is addedd for any general 'cannot apply patch' case, even though there are any number of other potential reasons for a 'git apply' to fail.

jthorson’s picture

re: Phasing out -p0 patches: http://groups.drupal.org/node/140204

rfay’s picture

Status: Active » Closed (duplicate)

Yeah, something went wrong with that code and it doesn't actually detect the right thing. We should remove it at this point.

Opened #1346010: Remove -p0 patch detection attempt so marking this one as a duplicate

salvis’s picture

Thank you for the pointer to

re: Phasing out -p0 patches: http://groups.drupal.org/node/140204

The weird thing is that my git apply will apply both types of patches just fine if I don't specify the -p switch. Why can't we be as tolerant as Git is? Or is my Git smarter than others?

As the OP in #1345240: Patch not to break xhprof reporting when site name contains spaces mentioned, Eclipse will generate -p0 patches, and last time I looked, there was no way to tell it to do -p1. The thread on g.d.o didn't give any rationale for why we needed to standardize on only one of -p0 or -p1:

jbrown:
What's the rational for standardizing on -p1 instead of -p0?
I really hate seeing all those 'a's and 'b's all the time.

rfay:
Git uses -p1 by default
Since we're now using git, it seemed reasonable for people to be able to use "git apply" to apply patches and "git diff" or "git format-patch" to create them.

Yes, that's what the documentation says, but Git accepts both if you omit -p.

I'm still unable to explain to anyone why we're insisting on -p1 instead of leaving it to Git what it wants to accept.

rfay’s picture

Sorry... give it a try. git does not accept both if you omit -p. Feel free to experiment with these two Drupal core patches.

rfay@rfay-dell:~/workspace/d7git$ git apply ~/tmp/drupal.demo_p0_patch.patch
fatal: git diff header lacks filename information when removing 1 leading pathname components (line 5)
jthorson’s picture

I believe there are also differences in how they handle 'new' files added by a patch ... I remember having to update the PIFR Coder confirmation patches because git apply would fail with 'file does not exist', whereas it knew this in advance from the ++ /dev/null contained in the -p1 formatted patch.

salvis’s picture

This is crazy! You are right:

HS@NB2 /d/PDev/drupal/d7 (7.x)
$ git apply /d/temp/drupal.demo_p1_patch.patch

HS@NB2 /d/PDev/drupal/d7 (7.x)
$ git apply -R /d/temp/drupal.demo_p1_patch.patch

HS@NB2 /d/PDev/drupal/d7 (7.x)
$ git apply /d/temp/drupal.demo_p0_patch.patch
fatal: git diff header lacks filename information when removing 1 leading pathname components (line 5)

 

But now look at the following, using http://drupal.org/files/devel_0.patch from #1345240: Patch not to break xhprof reporting when site name contains spaces:

HS@NB2 /d/PDev/drupal/d6/sites/all/modules/devel (6.x-1.x)
$ git apply /d/temp/devel_0.patch

HS@NB2 /d/PDev/drupal/d6/sites/all/modules/devel (6.x-1.x)
$ git apply -R /d/temp/devel_0.patch

HS@NB2 /d/PDev/drupal/d6/sites/all/modules/devel (6.x-1.x)
$ git apply -p0 /d/temp/devel_0.patch

HS@NB2 /d/PDev/drupal/d6/sites/all/modules/devel (6.x-1.x)
$ git apply -R /d/temp/devel_0.patch

HS@NB2 /d/PDev/drupal/d6/sites/all/modules/devel (6.x-1.x)
$ git apply -p1 /d/temp/devel_0.patch
fatal: unable to find filename in patch at line 3

As far as I can tell

  • it's a -p0 patch
  • it applies without -p
  • it applies with -p0
  • it fails with -p1

I did try this before posting. That patch was rejected by the testbot because of the explicit -p1 (see the log in the OP above). It passes on my 1.7.4.msysgit.0 and it would probably have passed on the testbot without any -p.

Apparently, Git does a more sophisticated analysis. It won't accept its own -p0 patches, maybe because it realizes that the patch creator consciously deviated from the default, but it will accept those of other tools in order to not scare away the uninitiated.

Except for your drupal.demo_p0_patch.patch I cannot recall seeing any patch that I was unable to git apply (without -p) because of the -p0/-p1 issue. That's why I've never been able to understand what this fuss is all about, and I still don't understand why we need to specify -p1 on the testbot, since it's the default anyway. Why not just drop it and see what happens?

It can't get worse, can it? And maybe it'll get a whole lot better...

rfay’s picture

Well, I have to admit that's fascinating.

One thing I notice is that your patch was *not* created with git. If I apply it and then create a patch with git, it will *not* apply here.

$ git apply ../devel_0.patch
$ git diff --no-prefix >/tmp/devel_0_from_git.patch
$ git reset --hard
$ git apply /tmp/devel_0_from_git.patch
fatal: git diff header lacks filename information when removing 1 leading pathname components (line 5)

Regardless, if you would please just use git to create your patches, it will be much appreciated :-)

salvis’s picture

You're not listening to me, Randy.

I do not intend to use anything other than Git. But we have users like the OP in #1345240: Patch not to break xhprof reporting when site name contains spaces who are so scared by our efforts to train them to use -p1 and never ever -p0 that they barely dare to breathe when they submit their first patch, and they feel like they have to apologize in advance for the tool they prefer to use:

(This is the first patch I've submitted so I'd appreciate knowing if I've done it the right way. I don't know how to use git so I generated this from my Eclipse IDE using SVN.)

If you removed the -p1 switch from the testbot and let Git default to whatever it wants, then you could stop training and scaring people, and it would just work.

One thing I notice is that your patch was *not* created with git.

So what?

If I apply it and then create a patch with git, it will *not* apply here.

You make it sound like it were contagious... It's not. It's just a diff in your file. You git diff --no-prefix — you get a patch that requires -p0 to apply. That has nothing to do with where the diff came from.

That's what I wrote in #7: "Git won't accept its own -p0 patches [without -p0], maybe because it realizes that the patch creator consciously deviated from the default [by giving --no-prefix], but it will accept those [prefix-less patches] of other tools in order to not scare away the uninitiated [who don't use Git and don't understand what we're talking about]."

Your experiment confirms exactly what I wrote. That's no reason to be scared, or to tell people they have to use other tools than the ones they're comfortable with, or to use switches on Git that make it less friendly than it wants to be, unless we have a good reason to do so. It seems that we don't.

jthorson’s picture

I'm just speculating here, as I'm far from being an expert on patch formats ... but I believe there is a desire to try and nudge folks towards using patch formats which generate proper attribution. Would this in any way factor in to the current debate?

jthorson’s picture

Issue summary: View changes

Fixed formatting (code to blockquote), no relevant change.