• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Mercurial Queues Emulation for Git


Commit MetaInfo

修訂be7793e838712eb18693a0e742b14d765702edaa (tree)
時間2019-06-17 07:39:04
作者Keith Marshall <keith@user...>
CommiterKeith Marshall

Log Message

Avoid "--message" vs. "--file" option conflicts.

* git-qnew.shar (mq_collect_msgopt, mq_validate_option): Remove;
these are superseded by a new, reusable API module.

* mq-message-opts.sh: New file; it reimplements...
(mq_collect_msgopt): ...this message option collector API.
* git-qnew.shar git-qrefresh.shar git-qfold.shar: Use it.
* Makefile.in (install-libexec-scripts): Add it.

Change Summary

差異

--- a/Makefile.in
+++ b/Makefile.in
@@ -168,6 +168,7 @@ install-libexec-scripts: git-qpush-backend.sh git-qpop-backend.sh
168168 install-libexec-scripts: git-qfinish-named.sh git-qfinish-all.sh
169169 install-libexec-scripts: git-qgoto-init.sh git-rev-import.sh
170170
171+install-libexec-scripts: mq-message-opts.sh
171172 install-libexec-scripts: mq-series-index.sh mq-series-list.sh
172173 install-libexec-scripts: mq-series-list-colour.sh mq-select-list.awk
173174 install-libexec-scripts: mq-select-activate.sh mq-select-backend.sh
--- a/git-qfold.shar
+++ b/git-qfold.shar
@@ -47,7 +47,7 @@ mq_facility="git qfold"
4747 # (which describes only a small subset of its actual content).
4848 #
4949 OPTIONS_SPEC="\
50-git qfold [-e] [-m <text>] [-l <file>] [-k] <patch> ...
50+git qfold [-e] [[[-m <text>] ...] | [-F <file>]] [-k] <patch> ...
5151
5252 Merge the content of specified unapplied patches into the current
5353 topmost patch; the merged patches are then removed from the series,
@@ -80,8 +80,9 @@ mq_commit_opts="--amend"
8080 while git_mq_getopt "$@"
8181 do case $1 in
8282 -e) mq_collect mq_commit_opts --edit ;;
83- -m) mq_msgopt=true; mq_collect mq_commit_opts "-m '$2'"; shift ;;
84- -[Fl]) mq_msgopt=true; mq_collect mq_commit_opts "-F '$2'"; shift ;;
83+ -F) mq_collect_valid_msgopt --file "$2"; shift ;;
84+ -l) mq_collect_valid_msgopt --logfile "$2"; shift ;;
85+ -m) mq_collect_valid_msgopt --message "$2"; shift ;;
8586 -k) mq_remove_opt=false ;;
8687 esac; shift
8788 done
@@ -146,7 +147,10 @@ mq_tmpfile mq_errlog '`mktemp` || $fatal "cannot open error message cache"'
146147 # cache file in which we may assemble a cumulative message, extracted
147148 # from the original and folded patch headers.
148149 #
149-${mq_msgopt-false} && mq_fold_count=count || {
150+test ${mq_msgopt+set} && {
151+ mq_fold_count=count
152+ mq_collect mq_commit_opts "$mq_msgopt"
153+} || {
150154 mq_tmpfile mq_msg_file '`mktemp` || $fatal "cannot open log message cache"'
151155 mq_collect mq_commit_opts "--file='$mq_msg_file'"
152156 git qheader > "$mq_msg_file"
--- a/git-qnew.shar
+++ b/git-qnew.shar
@@ -67,26 +67,18 @@ ETX
6767 . ./git-mq-setup.shar
6868
6969 cat <<\ETX
70-# Establish helper functions, to assist in parsing of command-specific
71-# options specified on the command line; the first rejects any conflict,
72-# such as "--file" vs. "--message"...
73-#
74-mq_validate_option() {
75- test "x$1" = "x${2-$1}" || $fatal "option '$1' conflicts with '$2'"
76-}
77-# ...while the second collects commit message fragments, if any, which
78-# are specified with the "--message" option.
79-#
80-mq_collect_msgopt() {
81- mq_validate_option $1 $mq_msgopt
82- mq_msgopt=${mq_msgopt+"$mq_msgopt "}"$1 '$2'"
83-}
84-
8570 # Regardless of any options specified by the user, we must be prepared
8671 # to commit an empty patch.
8772 #
8873 mq_commit_opts="--allow-empty"
8974
75+# The commit message definition options, "--message", "--logfile", or
76+# "--file", require a special validating interpreter, to ensure that no
77+# invalid combination is specified; this collects any valid sequence of
78+# such options into the "mq_msgopt" shell variable.
79+#
80+mq_require mq-message-opts
81+
9082 # Process any options which the user may have specified on the command
9183 # line; shift them out of the way, leaving only non-option arguments.
9284 #
@@ -94,8 +86,9 @@ while git_mq_getopt "$@"
9486 do case $1 in
9587 -e) mq_collect mq_commit_opts "--edit" ;;
9688 -a) mq_commit_all=true; mq_collect mq_commit_opts --all ;;
97- -[Fl]) mq_collect_msgopt --file "$2"; shift ;;
98- -m) mq_collect_msgopt --message "$2"; shift ;;
89+ -F) mq_collect_valid_msgopt --file "$2"; shift ;;
90+ -l) mq_collect_valid_msgopt --logfile "$2"; shift ;;
91+ -m) mq_collect_valid_msgopt --message "$2"; shift ;;
9992 -d) mq_commit_date="--date='$2'"; shift ;;
10093 -D) mq_commit_date="--date='`date '+%s %z'`'" ;;
10194 -u) mq_commit_user="--author='$2'"; shift ;;
@@ -226,7 +219,7 @@ test $# -gt 0 && {
226219 # commit options set; if no log message specified, substitute a
227220 # suitable default.
228221 #
229-test ${mq_msgopt+set} && mq_commit_opts="$mq_commit_opts $mq_msgopt" ||
222+test ${mq_msgopt+set} && mq_collect mq_commit_opts "$mq_msgopt" ||
230223 mq_collect mq_commit_opts "--message '[Git-MQ]: $mq_patchname'"
231224
232225 # Delegate the commit, and subsequent patch generation, to the patch
--- a/git-qrefresh.shar
+++ b/git-qrefresh.shar
@@ -46,7 +46,7 @@ mq_facility="git qrefresh"
4646 # (which describes only a small subset of its actual content).
4747 #
4848 OPTIONS_SPEC="\
49-git qrefresh [-e] [-m <text>] [-F <file>] [-s] [-a | <path> ...]
49+git qrefresh [-e] [[[-m <text>] ...] | [-F <file>]] [-s] [-a | <path> ...]
5050
5151 Update the current topmost patch, to incorporate staged changes, and
5252 optionally unstaged working tree changes, to tracked and/or specified
@@ -76,6 +76,13 @@ cat <<\ETX
7676 #
7777 mq_commit_opts="--amend"
7878
79+# The commit message definition options, "--message", "--logfile", or
80+# "--file", require a special validating interpreter, to ensure that no
81+# invalid combination is specified; this collects any valid sequence of
82+# such options into the "mq_msgopt" shell variable.
83+#
84+mq_require mq-message-opts
85+
7986 # Collect any other options, which have been specified on the command
8087 # line, into the "mq_commit_opts" shell variable, so that we may pass
8188 # them on to the "git commit" command.
@@ -84,8 +91,9 @@ while git_mq_getopt "$@"
8491 do case $1 in
8592 -e) mq_collect mq_commit_opts --edit ;;
8693 -a) mq_refresh_all=true; mq_collect mq_commit_opts --all ;;
87- -m) mq_msgopt=true; mq_collect mq_commit_opts "-m '$2'"; shift ;;
88- -[Fl]) mq_msgopt=true; mq_collect mq_commit_opts "-F '$2'"; shift ;;
94+ -F) mq_collect_valid_msgopt --file "$2"; shift ;;
95+ -l) mq_collect_valid_msgopt --logfile "$2"; shift ;;
96+ -m) mq_collect_valid_msgopt --message "$2"; shift ;;
8997 -U) mq_commit_user="--reset-author" ;;
9098 -u) mq_commit_user="--author='$2'"; shift ;;
9199 -D) mq_commit_date="--date='`date '+%s %z'`'" ;;
@@ -110,7 +118,8 @@ mq_patchfile="$mq_patchdir/$mq_patchname"
110118 # if none was given via a command line option, then arrange to reuse
111119 # whatever message was provided for the original patch.
112120 #
113-${mq_msgopt-false} || mq_collect mq_commit_opts "-C qtip"
121+test ${mq_msgopt+set} && mq_collect mq_commit_opts "$mq_msgopt" ||
122+ mq_collect mq_commit_opts "-C qtip"
114123
115124 # We prefer to capture the updated patch into a temporary file,
116125 # before finally updating the actual patch.
--- /dev/null
+++ b/mq-message-opts.sh
@@ -0,0 +1,57 @@
1+# mq-message-opts.sh
2+# ------------------------------------------------------------------------------
3+#
4+# Supplementary shell script fragment; it implements helper functions to
5+# collect and validate the commit log message options, which may be passed
6+# to the handlers for the "qnew", "qrefresh", and "qfold" subcommands.
7+#
8+# ------------------------------------------------------------------------------
9+#
10+# $Id$
11+#
12+# Written by Keith Marshall <keith@users.osdn.me>
13+# Copyright (C) 2019, MinGW.org Project
14+#
15+# Permission is hereby granted, free of charge, to any person obtaining a copy
16+# of this software and associated documentation files (the "Software"), to deal
17+# in the Software without restriction, including without limitation the rights
18+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19+# copies of the Software, and to permit persons to whom the Software is
20+# furnished to do so, subject to the following conditions:
21+#
22+# The above copyright notice and this permission notice shall be included in
23+# all copies or substantial portions of the Software.
24+#
25+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
31+# THE SOFTWARE.
32+#
33+# ------------------------------------------------------------------------------
34+#
35+# Recognizing that neither Mercurial nor Git allow the combination of the
36+# "--message" option with the "--logfile" option (in Mercurial's case), or
37+# the "--file" option (in Git's case); we provide the following helper to
38+# trap any violation of this constraint, and abort the command early.
39+#
40+ mq_reject_opt_conflict() {
41+ local reason_for_rejection="fatal: cannot combine options '$1' and '$2'"
42+ test "x$3" = "x${4-$3}" || mq_abort 2 "$reason_for_rejection"
43+ }
44+# Now, we may implement the primary API entry for this module; we accept
45+# "--file" and "--logfile" options as aliases, and map both to the former,
46+# while collecting it, or any other option without modification, together
47+# with a mandatory argument, into the "mq_msgopt" shell variable.
48+#
49+ mq_collect_valid_msgopt() {
50+ local collect_option="--file"
51+ test "x$1" = "x--logfile" || collect_option="$1"
52+ mq_reject_opt_conflict "${mq_msgsrc=$1}" "$1" "$collect_option" $mq_msgopt
53+ mq_collect mq_msgopt "$collect_option '$2'"
54+ }
55+#
56+# ------------------------------------------------------------------------------
57+# $RCSfile$: end of file