Mercurial Queues Emulation for Git
修訂 | be7793e838712eb18693a0e742b14d765702edaa (tree) |
---|---|
時間 | 2019-06-17 07:39:04 |
作者 | Keith Marshall <keith@user...> |
Commiter | Keith Marshall |
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.
@@ -168,6 +168,7 @@ install-libexec-scripts: git-qpush-backend.sh git-qpop-backend.sh | ||
168 | 168 | install-libexec-scripts: git-qfinish-named.sh git-qfinish-all.sh |
169 | 169 | install-libexec-scripts: git-qgoto-init.sh git-rev-import.sh |
170 | 170 | |
171 | +install-libexec-scripts: mq-message-opts.sh | |
171 | 172 | install-libexec-scripts: mq-series-index.sh mq-series-list.sh |
172 | 173 | install-libexec-scripts: mq-series-list-colour.sh mq-select-list.awk |
173 | 174 | install-libexec-scripts: mq-select-activate.sh mq-select-backend.sh |
@@ -47,7 +47,7 @@ mq_facility="git qfold" | ||
47 | 47 | # (which describes only a small subset of its actual content). |
48 | 48 | # |
49 | 49 | OPTIONS_SPEC="\ |
50 | -git qfold [-e] [-m <text>] [-l <file>] [-k] <patch> ... | |
50 | +git qfold [-e] [[[-m <text>] ...] | [-F <file>]] [-k] <patch> ... | |
51 | 51 | |
52 | 52 | Merge the content of specified unapplied patches into the current |
53 | 53 | topmost patch; the merged patches are then removed from the series, |
@@ -80,8 +80,9 @@ mq_commit_opts="--amend" | ||
80 | 80 | while git_mq_getopt "$@" |
81 | 81 | do case $1 in |
82 | 82 | -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 ;; | |
85 | 86 | -k) mq_remove_opt=false ;; |
86 | 87 | esac; shift |
87 | 88 | done |
@@ -146,7 +147,10 @@ mq_tmpfile mq_errlog '`mktemp` || $fatal "cannot open error message cache"' | ||
146 | 147 | # cache file in which we may assemble a cumulative message, extracted |
147 | 148 | # from the original and folded patch headers. |
148 | 149 | # |
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 | +} || { | |
150 | 154 | mq_tmpfile mq_msg_file '`mktemp` || $fatal "cannot open log message cache"' |
151 | 155 | mq_collect mq_commit_opts "--file='$mq_msg_file'" |
152 | 156 | git qheader > "$mq_msg_file" |
@@ -67,26 +67,18 @@ ETX | ||
67 | 67 | . ./git-mq-setup.shar |
68 | 68 | |
69 | 69 | 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 | - | |
85 | 70 | # Regardless of any options specified by the user, we must be prepared |
86 | 71 | # to commit an empty patch. |
87 | 72 | # |
88 | 73 | mq_commit_opts="--allow-empty" |
89 | 74 | |
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 | + | |
90 | 82 | # Process any options which the user may have specified on the command |
91 | 83 | # line; shift them out of the way, leaving only non-option arguments. |
92 | 84 | # |
@@ -94,8 +86,9 @@ while git_mq_getopt "$@" | ||
94 | 86 | do case $1 in |
95 | 87 | -e) mq_collect mq_commit_opts "--edit" ;; |
96 | 88 | -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 ;; | |
99 | 92 | -d) mq_commit_date="--date='$2'"; shift ;; |
100 | 93 | -D) mq_commit_date="--date='`date '+%s %z'`'" ;; |
101 | 94 | -u) mq_commit_user="--author='$2'"; shift ;; |
@@ -226,7 +219,7 @@ test $# -gt 0 && { | ||
226 | 219 | # commit options set; if no log message specified, substitute a |
227 | 220 | # suitable default. |
228 | 221 | # |
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" || | |
230 | 223 | mq_collect mq_commit_opts "--message '[Git-MQ]: $mq_patchname'" |
231 | 224 | |
232 | 225 | # Delegate the commit, and subsequent patch generation, to the patch |
@@ -46,7 +46,7 @@ mq_facility="git qrefresh" | ||
46 | 46 | # (which describes only a small subset of its actual content). |
47 | 47 | # |
48 | 48 | OPTIONS_SPEC="\ |
49 | -git qrefresh [-e] [-m <text>] [-F <file>] [-s] [-a | <path> ...] | |
49 | +git qrefresh [-e] [[[-m <text>] ...] | [-F <file>]] [-s] [-a | <path> ...] | |
50 | 50 | |
51 | 51 | Update the current topmost patch, to incorporate staged changes, and |
52 | 52 | optionally unstaged working tree changes, to tracked and/or specified |
@@ -76,6 +76,13 @@ cat <<\ETX | ||
76 | 76 | # |
77 | 77 | mq_commit_opts="--amend" |
78 | 78 | |
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 | + | |
79 | 86 | # Collect any other options, which have been specified on the command |
80 | 87 | # line, into the "mq_commit_opts" shell variable, so that we may pass |
81 | 88 | # them on to the "git commit" command. |
@@ -84,8 +91,9 @@ while git_mq_getopt "$@" | ||
84 | 91 | do case $1 in |
85 | 92 | -e) mq_collect mq_commit_opts --edit ;; |
86 | 93 | -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 ;; | |
89 | 97 | -U) mq_commit_user="--reset-author" ;; |
90 | 98 | -u) mq_commit_user="--author='$2'"; shift ;; |
91 | 99 | -D) mq_commit_date="--date='`date '+%s %z'`'" ;; |
@@ -110,7 +118,8 @@ mq_patchfile="$mq_patchdir/$mq_patchname" | ||
110 | 118 | # if none was given via a command line option, then arrange to reuse |
111 | 119 | # whatever message was provided for the original patch. |
112 | 120 | # |
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" | |
114 | 123 | |
115 | 124 | # We prefer to capture the updated patch into a temporary file, |
116 | 125 | # before finally updating the actual patch. |
@@ -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 |