Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [WIP PATCH] vcs_info svn support for 'svnversion'



Daniel Shahaf wrote on Sun, Dec 01, 2019 at 00:52:17 +0000:
> [[[
> From: Daniel Shahaf <danielsh@xxxxxxxxxx>
> Subject: [PATCH]
>  WIP: vcs_info svn: Use svnversion to show uniform revisions and local mods
> 
> The 'staged' expando, %c, will now be set if there's an 'M' in the output of `svnversion`.
> 
> The 'revision number' expando, %i, will now show the full output of svnversion.
> 
> svnversion will only be used if the check-for-changes and get-revision styles are both set.
> 
> TODO: derive the svnversion command name robustly
> TODO: write docs

Here's another version.  Differences:

- It's not a patch now, but configuration to be added to zshrc.

- It uses only public APIs, but takes advantage of an implementation detail to
  avoid svnversion doing a (potentially expensive) tree crawl.  The trade-off is
  that it's not read-only any more.

[[[
zstyle -e ':vcs_info:svn+post-backend:*' hooks 'reply=( ${${(k)functions[(I)[+]vi-svn-post-backend*]}#+vi-} )'

## svn: indicate mixed-revision working copies in the %i (revision) expando
zstyle -e ':vcs_info:svn:*:*' "zshrc:make-temporary-changes" '[[ $PWD == ~/* ]] && reply=(true)'
+vi-svn-post-backend-mixed-revision() {

  local non_uniform_revision modified

  if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" "check-for-changes" ; then
    local output="$(svnversion 2>/dev/null)"
    if [[ ${output} == *M* ]]; then
      hook_com[unstaged]='yes' # value is ignored
    fi
    if [[ ${output} == *:* ]]; then
      non_uniform_revision=${output}
    fi
  elif zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" "zshrc:make-temporary-changes" \
    && [[ -w ${hook_com[base_orig]}/.svn/wc.db ]]; then
    {
      # Make a dummy propmod to prevent svnversion(1) from doing a worktree stat() crawl.
      #
      # This relies on an implementation detail of svn_wc_revision_status2():
      # It will not do a tree crawl if it detected a propery mod (or a tree mod).
      ${vcs_comm[cmd]} propset --quiet vcs_info:dummy yes -- ${hook_com[base_orig]}
      local output="${$(svnversion 2>/dev/null)/M/}" # remove 'M' caused by the dummy propmod
      if [[ ${output} == *:* ]]; then
        non_uniform_revision=${output}
      fi
    } always {
      ${vcs_comm[cmd]} propdel --quiet vcs_info:dummy     -- ${hook_com[base_orig]}
    }
  fi

  if [[ $non_uniform_revision == *:* ]]; then
    integer min=${non_uniform_revision%%:*} max=${${non_uniform_revision#*:}%%[^0-9]*}
    hook_com[revision]="r${min}:r${max}${non_uniform_revision//[0-9:]##}"
    hook_com[revision]+=" (+$((max-min)))"
  fi

  return 0
}

]]]



Messages sorted by: Reverse Date, Date, Thread, Author