zsh-workers
 help / color / mirror / code / Atom feed
caf938beb17ec3078d368c6dfe28be3ab788a2a3 blob 6700 bytes (raw)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
 
## vim:ft=zsh
## git support by: Frank Terbeck <ft@bewatermyfriend.org>
## Distributed under the same BSD-ish license as zsh itself.

setopt localoptions extendedglob NO_shwordsplit
local gitdir gitbase gitbranch gitaction gitunstaged gitstaged gitsha1
local stgitpatch stgitunapplied
local -i querystaged queryunstaged
local -A hook_com

VCS_INFO_git_getaction () {
    local gitdir=$1
    local tmp

    for tmp in "${gitdir}/rebase-apply" \
               "${gitdir}/rebase"       \
               "${gitdir}/../.dotest" ; do
        if [[ -d ${tmp} ]] ; then
            if   [[ -f "${tmp}/rebasing" ]] ; then
                gitaction="rebase"
            elif [[ -f "${tmp}/applying" ]] ; then
                gitaction="am"
            else
                gitaction="am/rebase"
            fi
            return 0
        fi
    done

    for tmp in "${gitdir}/rebase-merge/interactive" \
               "${gitdir}/.dotest-merge/interactive" ; do
        if [[ -f "${tmp}" ]] ; then
            gitaction="rebase-i"
            return 0
        fi
    done

    for tmp in "${gitdir}/rebase-merge" \
               "${gitdir}/.dotest-merge" ; do
        if [[ -d "${tmp}" ]] ; then
            gitaction="rebase-m"
            return 0
        fi
    done

    if [[ -f "${gitdir}/MERGE_HEAD" ]] ; then
        gitaction="merge"
        return 0
    fi

    if [[ -f "${gitdir}/BISECT_LOG" ]] ; then
        gitaction="bisect"
        return 0
    fi

    if [[ -f "${gitdir}/CHERRY_PICK_HEAD" ]] ; then
        if [[ -d "${gitdir}/sequencer" ]] ; then
            gitaction=cherry-seq
        else
            gitaction=cherry
        fi
        return 0
    fi

    return 1
}

VCS_INFO_git_getbranch () {
    local gitdir=$1 tmp actiondir
    local gitsymref="${vcs_comm[cmd]} symbolic-ref HEAD"

    actiondir=''
    for tmp in "${gitdir}/rebase-apply" \
               "${gitdir}/rebase"       \
               "${gitdir}/../.dotest"; do
        if [[ -d ${tmp} ]]; then
            actiondir=${tmp}
            break
        fi
    done
    if [[ -n ${actiondir} ]]; then
        gitbranch="$(${(z)gitsymref} 2> /dev/null)"
        [[ -z ${gitbranch} ]] && [[ -r ${actiondir}/head-name ]] \
            && gitbranch="$(< ${actiondir}/head-name)"

    elif [[ -f "${gitdir}/MERGE_HEAD" ]] ; then
        gitbranch="$(${(z)gitsymref} 2> /dev/null)"
        [[ -z ${gitbranch} ]] && gitbranch="$(< ${gitdir}/MERGE_HEAD)"

    elif [[ -d "${gitdir}/rebase-merge" ]] ; then
        gitbranch="$(< ${gitdir}/rebase-merge/head-name)"

    elif [[ -d "${gitdir}/.dotest-merge" ]] ; then
        gitbranch="$(< ${gitdir}/.dotest-merge/head-name)"

    else
        gitbranch="$(${(z)gitsymref} 2> /dev/null)"

        if [[ $? -ne 0 ]] ; then
            gitbranch="refs/tags/$(${vcs_comm[cmd]} describe --all --exact-match HEAD 2>/dev/null)"

            if [[ $? -ne 0 ]] ; then
                gitbranch="${${"$(< $gitdir/HEAD)"}[1,7]}..."
            fi
        fi
    fi

    return 0
}

gitdir=${vcs_comm[gitdir]}
VCS_INFO_git_getbranch ${gitdir}
if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" get-revision ; then
    gitsha1=$(${vcs_comm[cmd]} rev-parse --quiet --verify HEAD)
else
    gitsha1=''
fi
gitbranch="${gitbranch##refs/[^/]##/}"

if [[ -z ${gitdir} ]] || [[ -z ${gitbranch} ]] ; then
    return 1
fi

if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" "check-for-changes" ; then
    querystaged=1
    queryunstaged=1
elif zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" "check-for-staged-changes" ; then
    querystaged=1
fi
if (( querystaged || queryunstaged )) && \
   [[ "$(${vcs_comm[cmd]} rev-parse --is-inside-work-tree 2> /dev/null)" == 'true' ]] ; then
    # Default: off - these are potentially expensive on big repositories
    if (( queryunstaged )) ; then
        ${vcs_comm[cmd]} diff --no-ext-diff --ignore-submodules --quiet --exit-code ||
            gitunstaged=1
    fi
    if (( querystaged )) ; then
        if ${vcs_comm[cmd]} rev-parse --quiet --verify HEAD &> /dev/null ; then
            ${vcs_comm[cmd]} diff-index --cached --quiet --ignore-submodules HEAD 2> /dev/null
            (( $? && $? != 128 )) && gitstaged=1
        else
            # empty repository (no commits yet)
            # TODO: ls-files' output isn't O(1); might be faster to use
            #         empty_tree_sha1=$(git hash-object -t tree /dev/null)
            #         git diff-index --cached --quiet $empty_tree_sha1
            #         (( $? && $? != 128 ))
            #       to efficiently get the "is the index not empty?" bit.
            [[ -n "$(${vcs_comm[cmd]} ls-files --cached -z)" ]] && gitstaged=1
        fi
    fi
fi

VCS_INFO_adjust
VCS_INFO_git_getaction ${gitdir}
gitbase=$( ${vcs_comm[cmd]} rev-parse --show-toplevel )
rrn=${gitbase:t}

local patchdir=${gitdir}/patches/${gitbranch}
if [[ -d $patchdir ]] && [[ -f $patchdir/applied ]] \
   && [[ -f $patchdir/unapplied ]]
then
    local -a stgit_applied stgit_unapplied stgit_all

    stgit_applied=(${(f)"$(< "${patchdir}/applied")"})
    stgit_applied=( ${(Oa)stgit_applied} )
    stgit_unapplied=(${(f)"$(< "${patchdir}/unapplied")"})
    stgit_unapplied=( ${(oa)stgit_unapplied} )
    stgit_all=( ${(Oa)stgit_applied} ${stgit_unapplied} )

    if VCS_INFO_hook 'gen-applied-string' "${stgit_applied[@]}"; then
        if (( ${#stgit_applied} )); then
            stgitpatch=${stgit_applied[1]}
        else
            stgitpatch=""
        fi
    else
        stgitpatch=${hook_com[patch-string]}
    fi
    hook_com=()
    if VCS_INFO_hook 'gen-unapplied-string' "${stgit_unapplied[@]}"; then
        stgitunapplied=${#stgit_unapplied}
    else
        stgitunapplied=${hook_com[unapplied-string]}
    fi

    if (( ${#stgit_applied} )); then
        zstyle -s ":vcs_info:${vcs}:${usercontext}:${rrn}" patch-format stgitmsg || stgitmsg="%p (%n applied)"
    else
        zstyle -s ":vcs_info:${vcs}:${usercontext}:${rrn}" nopatch-format stgitmsg || stgitmsg="no patch applied"
    fi
    hook_com=( applied "${stgitpatch}"     unapplied "${stgitunapplied}"
               applied-n ${#stgit_applied} unapplied-n ${#stgit_unapplied} all-n ${#stgit_all} )
    if VCS_INFO_hook 'set-patch-format' "${stgitmsg}"; then
        zformat -f stgitmsg "${stgitmsg}" "p:${hook_com[applied]}" "u:${hook_com[unapplied]}" \
                                          "n:${#stgit_applied}" "c:${#stgit_unapplied}" "a:${#stgit_all}"
    else
        stgitmsg=${hook_com[patch-replace]}
    fi
    hook_com=()
else
    stgitmsg=''
fi

backend_misc[patches]="${stgitmsg}"
VCS_INFO_formats "${gitaction}" "${gitbranch}" "${gitbase}" "${gitstaged}" "${gitunstaged}" "${gitsha1}" "${stgitmsg}"
return 0
debug log:

solving caf938b ...
found caf938b in https://inbox.vuxu.org/zsh-workers/20140601022653.GE1820@tarsus.local2/
found a48dc39 in https://git.vuxu.org/mirror/zsh/
preparing index
index prepared:
100644 a48dc390daf47c03bb10a7590a75c26917a9702c	Functions/VCS_Info/Backends/VCS_INFO_get_data_git

applying [1/1] https://inbox.vuxu.org/zsh-workers/20140601022653.GE1820@tarsus.local2/
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
index a48dc39..caf938b 100644

Checking patch Functions/VCS_Info/Backends/VCS_INFO_get_data_git...
Applied patch Functions/VCS_Info/Backends/VCS_INFO_get_data_git cleanly.

index at:
100644 caf938beb17ec3078d368c6dfe28be3ab788a2a3	Functions/VCS_Info/Backends/VCS_INFO_get_data_git

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).