Archive of RubyForge sup-devel mailing list
 help / color / mirror / Atom feed
* [sup-devel] Need help applying patches
@ 2011-02-20 19:19 Hamish
  2011-02-20 19:55 ` Hamish
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Hamish @ 2011-02-20 19:19 UTC (permalink / raw)
  To: sup-devel

[-- Attachment #1: Type: text/plain, Size: 2060 bytes --]

Gaudenz has submitted a few useful patches which I want to commit to the
gpgme branch, but git apply seems to fail. I've forwarded the message
text below, and attached the patches. When I apply it gpgme, I get:


$ git apply --check --verbose ../patches2merge/0001-Unify-formatting-of-GPGME-error-messages.patch
Checking patch lib/sup/crypto.rb...
error: while searching for:
    begin
      sig = GPGME.detach_sign(format_payload(payload), gpg_opts)
    rescue GPGME::Error => exc
      info "Error while running gpg: #{exc.message}"
      raise Error, "GPG command failed. See log for details."
    end

    envelope = RMail::Message.new

error: patch failed: lib/sup/crypto.rb:75
error: lib/sup/crypto.rb: patch does not apply


But I can't see why it could not find it. The code quoted above has
moved down by 31 lines, but is otherwise unchanged, but I thought git
could cope with that :/

I tried hand-editing the patch to change the line numbers, but I still
get the same error. Am I missing a trick? I've checked the file formats
and both have unix-style line endings.

I have tried and I can apply these patches by hand, but then they will
appear as committed by me, rather than giving Gaudenz his due.

Do others have the same problem? You could try by checking out the gpgme
branch and trying git apply.

I've also tried git am on a directory with these 3 attachments in:


$ git am -s ../patches2merge/
Nothing to do.


Not very helpful. Any help appreciated.

Hamish Downer


PS I am using git 1.7.1 on Ubuntu 10.10 x86_64 


--- Begin forwarded message from Gaudenz Steinlin ---
From: Gaudenz Steinlin <gaudenz@soziologie.ch>
To: sup-devel <sup-devel@rubyforge.org>
Date: Thu, 17 Feb 2011 14:49:01 +0000
Subject: [sup-devel] GPGME fixes

Hi

While reimporting all my messages I encountered a few problemes with
the GPGME code. Please consider the attached fixes.

The second patch depends on the first (error message unification). But
if you don't like the first I can easily produce a standalone version.

Gaudenz

--- End forwarded message ---

[-- Attachment #2: 0003-Check-for-valid-signature-before-signature.to_s.patch --]
[-- Type: application/octet-stream, Size: 1290 bytes --]

From 0a242c50f93319a47217dd577089732f4fbf0664 Mon Sep 17 00:00:00 2001
From: Gaudenz Steinlin <gaudenz@soziologie.ch>
Date: Thu, 17 Feb 2011 15:26:41 +0100
Subject: [PATCH 3/3] Check for valid signature before signature.to_s

In some circumstances with broken signatures signature.to_s returns nil.
Check for a valid signature before relying on this string. This avoids
an uncaught exception.
---
 lib/sup/crypto.rb |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/lib/sup/crypto.rb b/lib/sup/crypto.rb
index cbd0751..9ab8607 100644
--- a/lib/sup/crypto.rb
+++ b/lib/sup/crypto.rb
@@ -292,7 +292,13 @@ private
     ctx = GPGME::Ctx.new
     begin
       from_key = ctx.get_key(signature.fingerprint)
-      first_sig = signature.to_s.sub(/from [0-9A-F]{16} /, 'from "') + '"'
+      if GPGME::gpgme_err_code(signature.status) == GPGME::GPG_ERR_GENERAL
+        first_sig = "General error on signature verification for #{signature.fingerprint}"
+      elsif signature.to_s
+        first_sig = signature.to_s.sub(/from [0-9A-F]{16} /, 'from "') + '"'
+      else
+        first_sig = "Unknown error or empty signature"
+      end
     rescue EOFError
       from_key = nil
       first_sig = "No public key available for #{signature.fingerprint}"
-- 
1.7.2.3


[-- Attachment #3: 0002-Check-for-ArgumentError-on-signature-verification.patch --]
[-- Type: application/octet-stream, Size: 1614 bytes --]

From f86d0bb6c2cc9a1d8ef544a34f9c10f73850767c Mon Sep 17 00:00:00 2001
From: Gaudenz Steinlin <gaudenz@soziologie.ch>
Date: Thu, 17 Feb 2011 15:13:31 +0100
Subject: [PATCH 2/3] Check for ArgumentError on signature verification

Broken signatures can cause a NULL pointer which results in an
ArguementError when calling ctx.verify_result even if the previous call
to ctx.verify does not raise an exception.

The underling cause is probably a bug in GPGME.
---
 lib/sup/crypto.rb |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/lib/sup/crypto.rb b/lib/sup/crypto.rb
index a3771bf..cbd0751 100644
--- a/lib/sup/crypto.rb
+++ b/lib/sup/crypto.rb
@@ -183,7 +183,11 @@ EOS
     rescue GPGME::Error => exc
       return unknown_status [gpgme_exc_msg(exc.message)]
     end
-    self.verified_ok? ctx.verify_result
+    begin
+      self.verified_ok? ctx.verify_result
+    rescue ArgumentError => exc
+      return unknown_status [gpgme_exc_msg(exc.message)]
+    end
   end
 
   ## returns decrypted_message, status, desc, lines
@@ -201,7 +205,11 @@ EOS
     rescue GPGME::Error => exc
       return Chunk::CryptoNotice.new(:invalid, "This message could not be decrypted", gpgme_exc_msg(exc.message))
     end
-    sig = self.verified_ok? ctx.verify_result
+    begin
+      sig = self.verified_ok? ctx.verify_result
+    rescue ArgumentError => exc
+      sig = unknown_status [gpgme_exc_msg(exc.message)]
+    end
     plain_data.seek(0, IO::SEEK_SET)
     output = plain_data.read
     output.force_encoding Encoding::ASCII_8BIT if output.respond_to? :force_encoding
-- 
1.7.2.3


[-- Attachment #4: 0001-Unify-formatting-of-GPGME-error-messages.patch --]
[-- Type: application/octet-stream, Size: 2413 bytes --]

From b52a306ed119715e5dac26f35a406ecdd4c5fb87 Mon Sep 17 00:00:00 2001
From: Gaudenz Steinlin <gaudenz@soziologie.ch>
Date: Thu, 17 Feb 2011 15:09:23 +0100
Subject: [PATCH 1/3] Unify formatting of GPGME error messages

Create a private function to turn a an exception into a "human friendly"
error message and to add a entry to the logfile. Use this function for
all error paths.
---
 lib/sup/crypto.rb |   17 ++++++++++-------
 1 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/lib/sup/crypto.rb b/lib/sup/crypto.rb
index 2bfb475..a3771bf 100644
--- a/lib/sup/crypto.rb
+++ b/lib/sup/crypto.rb
@@ -75,8 +75,7 @@ EOS
     begin
       sig = GPGME.detach_sign(format_payload(payload), gpg_opts)
     rescue GPGME::Error => exc
-      info "Error while running gpg: #{exc.message}"
-      raise Error, "GPG command failed. See log for details."
+      raise Error, gpgme_exc_msg(exc.message)
     end
 
     envelope = RMail::Message.new
@@ -103,8 +102,7 @@ EOS
     begin
       cipher = GPGME.encrypt(recipients, format_payload(payload), gpg_opts)
     rescue GPGME::Error => exc
-      info "Error while running gpg: #{exc.message}"
-      raise Error, "GPG command failed. See log for details."
+      raise Error, gpgme_exc_msg(exc.message)
     end
 
     encrypted_payload = RMail::Message.new
@@ -183,7 +181,7 @@ EOS
     begin
       ctx.verify(sig_data, signed_text_data, plain_data)
     rescue GPGME::Error => exc
-      return unknown_status exc.message
+      return unknown_status [gpgme_exc_msg(exc.message)]
     end
     self.verified_ok? ctx.verify_result
   end
@@ -201,8 +199,7 @@ EOS
     begin
       ctx.decrypt_verify(cipher_data, plain_data)
     rescue GPGME::Error => exc
-      info "Error while running gpg: #{exc.message}"
-      return Chunk::CryptoNotice.new(:invalid, "This message could not be decrypted", exc.message)
+      return Chunk::CryptoNotice.new(:invalid, "This message could not be decrypted", gpgme_exc_msg(exc.message))
     end
     sig = self.verified_ok? ctx.verify_result
     plain_data.seek(0, IO::SEEK_SET)
@@ -264,6 +261,12 @@ private
     ["Can't find gpgme gem."]
   end
 
+  def gpgme_exc_msg msg
+    err_msg = "Exception in GPGME call: #{msg}"
+    info err_msg
+    err_msg
+  end
+
   ## here's where we munge rmail output into the format that signed/encrypted
   ## PGP/GPG messages should be
   def format_payload payload
-- 
1.7.2.3


[-- Attachment #5: Type: text/plain, Size: 143 bytes --]

_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [sup-devel] Need help applying patches
  2011-02-20 19:19 [sup-devel] Need help applying patches Hamish
@ 2011-02-20 19:55 ` Hamish
  2011-02-22 13:14   ` Gaudenz Steinlin
  2011-02-20 20:12 ` Michael Hamann
  2011-02-20 21:58 ` William Morgan
  2 siblings, 1 reply; 5+ messages in thread
From: Hamish @ 2011-02-20 19:55 UTC (permalink / raw)
  To: sup-devel

Excerpts from Hamish's message of Sun Feb 20 19:19:17 +0000 2011:
> Gaudenz has submitted a few useful patches which I want to commit to the
> gpgme branch, but git apply seems to fail. I've forwarded the message
> text below, and attached the patches. When I apply it gpgme, I get:

Of course, having just written an email describing my problem, I do a
little more playing about and manage to find a way through. To record
what I did:

$ cat ../patches2merge/0001-Unify-formatting-of-GPGME-error-messages.patch | git am -s -3
$ vim lib/sup/crypto.rb
$ git add lib/sup/crypto.rb
$ git am -3 --resolved

Rinse and repeat for the other 2 patches. And now the log looks like I
expect it to. 

I ran into some more issues merging this into next - my usual
cherry-pick method led to the same problems as originally, and led to me
being listed as the committer, but I managed to do a git merge which 
preserved the commit messages from Gaudenz (although a couple of mine
appear to be repeated).

If there is some better way to do this in future, please tell me.

Hamish
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [sup-devel] Need help applying patches
  2011-02-20 19:19 [sup-devel] Need help applying patches Hamish
  2011-02-20 19:55 ` Hamish
@ 2011-02-20 20:12 ` Michael Hamann
  2011-02-20 21:58 ` William Morgan
  2 siblings, 0 replies; 5+ messages in thread
From: Michael Hamann @ 2011-02-20 20:12 UTC (permalink / raw)
  To: sup-devel

Hi,

Excerpts from Hamish's message of 2011-02-20 20:19:17 +0100:
[...]
> I have tried and I can apply these patches by hand, but then they will
> appear as committed by me, rather than giving Gaudenz his due.

You can use git commit --author="Name <example@example.com>", then you
are recorded as committer and the author you supply is recorded as
author of the change.

Michael Hamann
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [sup-devel] Need help applying patches
  2011-02-20 19:19 [sup-devel] Need help applying patches Hamish
  2011-02-20 19:55 ` Hamish
  2011-02-20 20:12 ` Michael Hamann
@ 2011-02-20 21:58 ` William Morgan
  2 siblings, 0 replies; 5+ messages in thread
From: William Morgan @ 2011-02-20 21:58 UTC (permalink / raw)
  To: sup-devel

Reformatted excerpts from Hamish's message of 2011-02-20:
> But I can't see why it could not find it. The code quoted above has
> moved down by 31 lines, but is otherwise unchanged, but I thought git
> could cope with that :/

Git apply is a pretty low-level command and I believe it acts basically like
the patch command, i.e. fails fast if things aren't perfectly in tune.

To pull in the git merge logic on patch files, use `git am -3`.

> $ git am -s ../patches2merge/
> Nothing to do.

I think it's trying to interpret that directory as a maildir. Give it the
individual files.
-- 
William <wmorgan-sup@masanjin.net>
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [sup-devel] Need help applying patches
  2011-02-20 19:55 ` Hamish
@ 2011-02-22 13:14   ` Gaudenz Steinlin
  0 siblings, 0 replies; 5+ messages in thread
From: Gaudenz Steinlin @ 2011-02-22 13:14 UTC (permalink / raw)
  To: sup-devel


[-- Attachment #1.1: Type: text/plain, Size: 1875 bytes --]

Hi

Excerpts from Hamish's message of 2011-02-20 20:55:33 +0100:
> Excerpts from Hamish's message of Sun Feb 20 19:19:17 +0000 2011:
> I ran into some more issues merging this into next - my usual
> cherry-pick method led to the same problems as originally, and led to me
> being listed as the committer, but I managed to do a git merge which 
> preserved the commit messages from Gaudenz (although a couple of mine
> appear to be repeated).

Cherrypicking has basically the same disadvantages as rebasing as it
changes the commit ID. So don't cherry pick commits from one branch
(e.g. next) into another branch (e.g. gpgme) if you want to merge that
branch back into the branch from which you cherry-picked (e.g. you
want to merge gpgme back into next). 

Also don't rebase a branch as soon as you published it somwhere for
other to pull from. 

> 
> If there is some better way to do this in future, please tell me.

I think the correct thing to do is to rebase your development branches
against the branch they will eventually be merged into as long as you
did not publish them. Rebasing has the nice effect of not complicating
the history to much.

If you can't rebase then merge, either merge your feature branch into
the target branch and then you are free recreate your feature branch
and rebase while you are doing development. 

Or if your changes are not ready yet for merging, you can also merge
the target branch into your feature branch to get the latest changes
into your feature branch.

For testing and day to day usage I usually create a sepeparate branch
based of next and merge all my development branches into this branch.
This branch is then never published and frequently recreated if
something fails...

Gaudenz
-- 
Ever tried. Ever failed. No matter.
Try again. Fail again. Fail better.
~ Samuel Beckett ~

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 828 bytes --]

[-- Attachment #2: Type: text/plain, Size: 143 bytes --]

_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-02-22 13:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-20 19:19 [sup-devel] Need help applying patches Hamish
2011-02-20 19:55 ` Hamish
2011-02-22 13:14   ` Gaudenz Steinlin
2011-02-20 20:12 ` Michael Hamann
2011-02-20 21:58 ` William Morgan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox