zsh-workers
 help / color / mirror / code / Atom feed
From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: zsh-workers@zsh.org
Subject: [PATCH] vcs_info git: Under git-am(1) conflicts, pass to the gen-applied-string hook information on already-applied patches.
Date: Thu, 26 Mar 2020 02:43:41 +0000	[thread overview]
Message-ID: <20200326024341.22427-1-danielsh@tarpaulin.shahaf.local2> (raw)

The hook already receives information about the current (topmost
applied) patch and, if the get-unapplied style is set, about future
(unapplied) patches.

Tested in the Functions/VCS_Info/test-repo-git-rebase-apply scenario,
after manually converting the rebase to a «git am».  (Specifically,
I ran:
    mkdir d
    git rebase --abort
    git format-patch rebase_from_this..HEAD -o d
    git checkout rebase_onto_this
    git am d/*
.)
---
 Functions/VCS_Info/Backends/VCS_INFO_get_data_git | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
index 2b1e9afca..2b2040c94 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
@@ -258,14 +258,14 @@ elif [[ -d "${gitdir}/rebase-merge" ]]; then
     fi
     VCS_INFO_git_handle_patches
 elif [[ -d "${gitdir}/rebase-apply" ]]; then
-    # 'git rebase' without -i
+    # 'git rebase' without -i, or 'git am'
     patchdir="${gitdir}/rebase-apply"
     local next="${patchdir}/next"
     local this_patch_file
     if [[ -f $next ]]; then
         local cur=$(< $next)
         local p subject
-        # Fake patch names for patches "before" the current patch
+        # Compute patch names for patches "before" the current patch
         if [[ -r ${patchdir}/rewritten ]]; then
             if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" use-simple; then
                 git_patches_applied=( ${${(f)"$(<${patchdir}/rewritten)"}// */' ?'} )
@@ -280,7 +280,13 @@ elif [[ -d "${gitdir}/rebase-apply" ]]; then
             # of these versions have original-commit and orig-head and would
             # take the 'if' branch, rather than this 'else' branch.
             for ((p = 1; p < cur; p++)); do
-                printf -v "git_patches_applied[$p]"  "%04d ?" "$p"
+                printf -v this_patch_file "%s/%04d" "${patchdir}" "${p}"
+                if [[ -f $this_patch_file ]]; then
+                    VCS_INFO_patch2subject "${this_patch_file}"
+                    git_patches_applied+=( "$p $REPLY" )
+                else
+                    git_patches_applied+=( "$p ?" )
+                fi
             done
         fi
         # Set $subject to the info for the current patch
@@ -298,6 +304,8 @@ elif [[ -d "${gitdir}/rebase-apply" ]]; then
         subject=${subject:-'?'}
         if [[ -f "${patchdir}/original-commit" ]]; then
             git_patches_applied+=("$(< ${patchdir}/original-commit) $subject")
+        elif [[ -f "${patchdir}/next" ]]; then
+            git_patches_applied+=("$(< ${patchdir}/next) $subject")
         else
             git_patches_applied+=("? $subject")
         fi

                 reply	other threads:[~2020-03-26  2:44 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200326024341.22427-1-danielsh@tarpaulin.shahaf.local2 \
    --to=d.s@daniel.shahaf.name \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).