Giter VIP home page Giter VIP logo

Comments (4)

kyleam avatar kyleam commented on May 30, 2024 1

Here's a minimal reproducer for the Magit repo:

#!/bin/sh

set -eu

commit=6e394b8928bab7922478566c4eb2f7cf0a6edd8e
git checkout "$commit"~2
git format-patch --no-cover-letter -n2 --stdout "$commit" |
    # Remove commit to make magit-insert-am-sequence go through
    # `patches' arm.
    sed 's/^From .*/From git@z Thu Jan  1 00:00:00 1970/' |
    # Trigger failure in second patch.
    sed 's/dropped."/ &1/' |
    git am

That leads to the following status buffer:

Applying patches
pick 0002 [PATCH 2/2] magit-log-remove-graph-args: Discourage customization
stop 0001 [PATCH 1/2] magit-section--enable-long-lines-shortcuts: Fix message
done 3f0c923c magit-section--enable-long-lines-shortcuts: Fix message typos
onto fc71a772 magit-blame--parse-chunk: Cosmetics

I'm out of time to look into this more tonight, but quickly glancing at magit-insert-am-sequence, it looks like it incorrectly assumes that a patch is deleted from $GIT_DIR/rebase-apply/ after being successfully applied.

from magit.

kyleam avatar kyleam commented on May 30, 2024

As a first step, I'll try to reduce this down to a smaller reproducer. And I expect b4 can be taken out of the equation.

from magit.

stsquad avatar stsquad commented on May 30, 2024

I'm not sure what magit-commit-p is meant to be doing but noodling about in ielm:

ELISP> (--map (magit-file-line it) (nreverse (magit-rebase-patches)))
("From git@z Thu Jan  1 00:00:00 1970" "From git@z Thu Jan  1 00:00:00 1970" "From git@z Thu Jan  1 00:00:00 1970" "From git@z Thu Jan  1 00:00:00 1970" "From git@z Thu Jan  1 00:00:00 1970" "From git@z Thu Jan  1 00:00:00 1970" "From git@z Thu Jan  1 00:00:00 1970" "From git@z Thu Jan  1 00:00:00 1970" "From git@z Thu Jan  1 00:00:00 1970" "From git@z Thu Jan  1 00:00:00 1970" "From git@z Thu Jan  1 00:00:00 1970" "From git@z Thu Jan  1 00:00:00 1970" "From git@z Thu Jan  1 00:00:00 1970" "From git@z Thu Jan  1 00:00:00 1970" "From git@z Thu Jan  1 00:00:00 1970" "From git@z Thu Jan  1 00:00:00 1970" "From git@z Thu Jan  1 00:00:00 1970" "From git@z Thu Jan  1 00:00:00 1970" "From git@z Thu Jan  1 00:00:00 1970" "From git@z Thu Jan  1 00:00:00 1970" "From git@z Thu Jan  1 00:00:00 1970" "From git@z Thu Jan  1 00:00:00 1970" "From git@z Thu Jan  1 00:00:00 1970")

ELISP> (--map (cadr (split-string (magit-file-line it))) (nreverse (magit-rebase-patches)))
("git@z" "git@z" "git@z" "git@z" "git@z" "git@z" "git@z" "git@z" "git@z" "git@z" "git@z" "git@z" "git@z" "git@z" "git@z" "git@z" "git@z" "git@z" "git@z" "git@z" "git@z" "git@z" "git@z")

ELISP> (--map (magit-commit-p
                        (cadr (split-string (magit-file-line it)))) (nreverse (magit-rebase-patches)))
(nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil)

but if its meant to pick up applied patches and it did we could switch patches/commit checks in cond .

from magit.

kyleam avatar kyleam commented on May 30, 2024

I'm not sure what magit-commit-p is meant to be doing

That checks whether an object for a commit named in the From_ line (i.e. what comes straight from git-format-patch) is present locally. You can trigger that codepath if you drop the first sed line in my script above. It doesn't come into play for the standard patch workflow where commits for the sender's patches aren't present in the applier's repo.


Here's my initial crack at dropping the already applied patches from the display. With light testing, what's displayed looks reasonable to me, but I've yet to test it more thoroughly (edge cases, older Git versions, ...). I won't get to that until at least this weekend.

diff
diff --git a/lisp/magit-sequence.el b/lisp/magit-sequence.el
index 2b210a57..c4f204ff 100644
--- a/lisp/magit-sequence.el
+++ b/lisp/magit-sequence.el
@@ -914,24 +914,31 @@ (defun magit-insert-am-sequence ()
   (when (magit-am-in-progress-p)
     (magit-insert-section (rebase-sequence)
       (magit-insert-heading "Applying patches")
-      (let ((patches (nreverse (magit-rebase-patches)))
-            patch commit)
-        (while patches
+      (let* ((patches (nreverse (magit-rebase-patches)))
+             (dir (expand-file-name "rebase-apply" (magit-gitdir)))
+             (i (string-to-number
+                 (magit-file-line (expand-file-name "last" dir))))
+             (cur (string-to-number
+                   (magit-file-line (expand-file-name "next" dir))))
+             patch commit)
+        (while (and patches (>= i cur))
           (setq patch (pop patches))
           (setq commit (magit-commit-p
                         (cadr (split-string (magit-file-line patch)))))
-          (cond ((and commit patches)
+          (cond ((and commit (= i cur))
                  (magit-sequence-insert-commit
-                  "pick" commit 'magit-sequence-pick))
-                (patches
+                  "stop" commit 'magit-sequence-stop))
+                ((= i cur)
                  (magit-sequence-insert-am-patch
-                  "pick" patch 'magit-sequence-pick))
+                  "stop" patch 'magit-sequence-stop))
                 (commit
-                 (magit-sequence-insert-sequence commit "ORIG_HEAD"))
+                 (magit-sequence-insert-commit
+                  "pick" commit 'magit-sequence-pick))
                 (t
                  (magit-sequence-insert-am-patch
-                  "stop" patch 'magit-sequence-stop)
-                 (magit-sequence-insert-sequence nil "ORIG_HEAD")))))
+                  "pick" patch 'magit-sequence-pick)))
+          (cl-decf i))
+        (magit-sequence-insert-sequence nil "ORIG_HEAD"))
       (insert ?\n))))

 (defun magit-sequence-insert-am-patch (type patch face)
Applying patches section

Tweaked script to add one more patch:

#!/bin/sh

set -eu

commit=c5597033d8cde513d124d9054ec0ad5f04889c20
git checkout "$commit"~3
git format-patch --no-cover-letter -n3 --stdout "$commit" |
    # Remove commit to make magit-insert-am-sequence go through
    # `patches' arm.
    sed 's/^From .*/From git@z Thu Jan  1 00:00:00 1970/' |
    # Trigger failure in second patch.
    sed 's/dropped."/ &1/' |
    git am
Applying patches
pick 0003 [PATCH 3/3] magit-section-{pre,post}-command-hook: Don't suppress in
stop 0002 [PATCH 2/3] magit-log-remove-graph-args: Discourage customization
done 019726ec magit-section--enable-long-lines-shortcuts: Fix message typos
onto fc71a772 magit-blame--parse-chunk: Cosmetics

from magit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.