5

Let's say I have this patch file from emacs git.

I usually fix stuff manually by reviewing the patch files. But I am sure there is an automated way to do that. I played a bit by opening package.el in emacs source and trying to use ediff-patch-file but was unsuccessful.

It would be good to get a brief walk-through for the patching process.


The patch referenced above:

---
diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index 444adf0..79f37e7 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -2943,12 +2943,9 @@ objects removed."
                 (format status-format (cl-incf i)))
           (force-mode-line-update)
           (redisplay 'force)
-          (package-install
-           ;; Don't mark as selected if it's a new version of an
-           ;; installed package.
-           pkg (and (not (package-installed-p pkg))
-                    (package-installed-p
-                     (package-desc-name pkg))))))
+          ;; Don't mark as selected, `package-menu-execute' already
+          ;; does that.
+          (package-install pkg 'dont-select)))
     ;; Once there are no more packages to install, proceed to
     ;; deletion.
     (let ((package-menu--transaction-status ":Deleting"))
@@ -2995,6 +2992,10 @@ Optional argument NOQUERY non-nil means do not ask the user to confirm."
                        (when .upgrade (format "Upgrad__ %s" (length .upgrade)))
                        "]")))
           (message (replace-regexp-in-string "__" "ing" message-template) "started")
+          ;; Packages being upgraded are not marked as selected.
+          (package--save-selected-packages
+           (remove-dups (append (mapcar #'package-desc-name .install)
+                                package-selected-packages)))
           (package-menu--perform-transaction install-list delete-list)
           (when package-selected-packages
             (if-let ((removable (package--removable-packages)))
--
  • Does git am work for you? – abo-abo May 21 '15 at 17:17
  • @abo-abo I had not heard of that before you mentioned it; will look into it. I was looking for a solution that can be implemented from within emacs so that I don't need to save patch files and call executables/scripts from the terminal. epatch-buffer is exactly what I wanted. I am interested in seeing your patching work-flow using git am. – Kaushal Modi May 21 '15 at 18:03
7

You can use either:

  • enter diff-mode, then C-c C-a when point is on each hunk to apply the patch to the destination file. You should open the file in a window to see the effect.

  • epatch-buffer: if patch is already in the buffer, the command asks for the patch and the buffer to be applied, then create patched and unpatched windows side by side for you to compare with ediff. If you are satisfied, you can press q to quit and save the patched version into your original file.

  • epatch: the same as epatch-buffer but asking for a source file instead of a buffer to patch.

| improve this answer | |
  • 1
    If C-c C-a in diff-mode picks the wrong file to patch, you can tell it which one to use with M-x diff-tell-file-name. – legoscia May 21 '15 at 17:02
4

The patch that you linked was generated with something like:

git format-patch HEAD~1

At least that's what I use when I send patches to the mailing list. To apply it, call:

git am foo.patch

Obviously, you need to do it in a compatible git repository. A nice thing is that you get a full commit, with all the metadata and all.

In case the patch can't be applied cleanly, I use this:

git apply .git/rebase-apply/0001 --reject

Then resolve the conflicts with magit e.

| improve this answer | |
  • 1
    If you don't want to save the patch to a file, simply select it and "C-| git am RET" will apply it. You might need to "M-x cd" into the right directory before doing so. – YoungFrog May 22 '15 at 5:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.