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

Re: How to contribute VCSInfo back end for fossil



Mike Meyer wrote:
> Sorry if this is the wrong place, but neither google nor
> hand-examining the zsh sites turned up a place for such submissions...

This is exactly the right place.

> Anyway, I wrote a vcs_info backend for the fossil scm
> (http://fossil-scm.org/). I'd like to donate the code back to the zsh
> community, but don't see an obvious way to do so.

Great. I've briefly looked at the code and it seems clear enough. I'd
like to commit the following:


diff --git a/Functions/VCS_Info/Backends/VCS_INFO_detect_fossil b/Functions/VCS_Info/Backends/VCS_INFO_detect_fossil
new file mode 100644
index 0000000..5515283
--- /dev/null
+++ b/Functions/VCS_Info/Backends/VCS_INFO_detect_fossil
@@ -0,0 +1,13 @@
+## vim:ft=zsh
+## fossil support by: Mike Meyer <mwm@xxxxxxxxx>
+## Distributed under the same BSD-ish license as zsh itself.
+
+setopt localoptions NO_shwordsplit
+
+[[ $1 == '--flavours' ]] && return 1
+
+VCS_INFO_check_com ${vcs_comm[cmd]} || return 1
+vcs_comm[detect_need_file]=_FOSSIL_
+VCS_INFO_bydir_detect . || return 1
+
+return 0
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_fossil b/Functions/VCS_Info/Backends/VCS_INFO_get_data_fossil
new file mode 100644
index 0000000..4568b64
--- /dev/null
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_fossil
@@ -0,0 +1,37 @@
+## vim:ft=zsh
+## fossil support by: Mike Meyer <mwm@xxxxxxxxx>
+## Distributed under the same BSD-ish license as zsh itself.
+
+setopt localoptions extendedglob
+local a b
+local change changed
+local action merging
+local -A fsinfo
+local -xA hook_com
+
+${vcs_comm[cmd]} status | while IFS=: read a b; do fsinfo[${a//-/_}]="${b## #}"; done
+fshash=${fsinfo[checkout]%% *}
+changed=${(Mk)fsinfo:#(ADDED|EDITED|DELETED|UPDATED)*}
+merging=${(Mk)fsinfo:#*_BY_MERGE*}
+if [ -n "$merging" ]; then
+   action="merging"
+fi
+
+# Build the revision display
+fsrev="${hook_com[hash]}"
+
+# Now build the branch display
+zstyle -s ":vcs_info:${vcs}:${usercontext}:${rrn}" branchformat fsbranch || fsbranch="%b:%r"
+
+hook_com=( branch "${fsinfo[tags]%%, *}" revision "${fsrev}" )
+
+if VCS_INFO_hook 'set-branch-format' "${fsbranch}"; then
+    zformat -f fsbranch "${fsbranch}" "b:${hook_com[branch]}" "r:${hook_com[revision]}"
+else
+    fsbranch=${hook_com[branch-replace]}
+fi
+
+hook_com=()
+
+VCS_INFO_formats "$action" "${fsbranch}" "${fsinfo[local_root]}" '' "$changed" "${fsrev}" "${fsinfo[repository]}"
+return 0



As you can see, I've removed the code that surrounded the `$fsrev'
variable. Specifically, the `fsrevformat' style and the
`set-fsrev-format' hook. They didn't add much, as you've got full access
to the same data in with the `branchformat' style and the
`set-branch-format' hook (I kept the `$fsrev' variable for clarity).

Like this, the only required documentation update would be to name
fossil among the supported systems in zshcontrib(1).

If you're okay with those changes, it would be good if you could check
whether the above code works or not - I didn't test those changes.

Regards, Frank



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