@matheusbsbs / matheus-bagliano / commits / 376ccb8cbb
Fork 0

rebase -i: style fixes and minor cleanups

This patch indents ";;" consistently with the rest of git's shell scripts, and makes sure that ";;" are before each "esac". It introduces a helper function "has_action", to make it easier to read the intentions of the code. Errors from "git rev-parse --verify" are no longer ignored. Spaces are quoted using single quotes instead of a backslash, for readability. A "test $preserve=f" (missing spaces) was fixed; hashes are no longer written to "$DOTEST"/rewritten/ unnecessarily. We used to quote the message for a squash, only to have "echo" unquote it. Now we use "printf" and do not need to quote to start with. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Sep 25, 2007 at 16:42 UTC 376ccb8cbb453343998e734d8a1ce79f57a4e092
1 file changed +30 -18
git-rebase--interactive.sh
+30 -18
@@ -41,9 +41,10 @@ output () {
41 test $status != 0 &&
42 cat "$DOTEST"/output
43 return $status
44 - ;;
44 + ;;
45 *)
46 "$@"
47 + ;;
48 esac
49 }
50
@@ -63,6 +64,7 @@ comment_for_reflog () {
64 ''|rebase*)
65 GIT_REFLOG_ACTION="rebase -i ($1)"
66 export GIT_REFLOG_ACTION
67 + ;;
68 esac
69 }
70
@@ -96,13 +98,18 @@ die_abort () {
98 die "$1"
99 }
100
101 +has_action () {
102 + grep -vqe '^$' -e '^#' "$1"
103 +}
104 +
105 pick_one () {
106 no_ff=
107 case "$1" in -n) sha1=$2; no_ff=t ;; *) sha1=$1 ;; esac
108 output git rev-parse --verify $sha1 || die "Invalid commit name: $sha1"
109 test -d "$REWRITTEN" &&
110 pick_one_preserving_merges "$@" && return
105 - parent_sha1=$(git rev-parse --verify $sha1^ 2>/dev/null)
111 + parent_sha1=$(git rev-parse --verify $sha1^) ||
112 + die "Could not get the parent of $sha1"
113 current_sha1=$(git rev-parse --verify HEAD)
114 if test $no_ff$current_sha1 = $parent_sha1; then
115 output git reset --hard $sha1
@@ -130,7 +137,7 @@ pick_one_preserving_merges () {
137 fast_forward=t
138 preserve=t
139 new_parents=
133 - for p in $(git rev-list --parents -1 $sha1 | cut -d\ -f2-)
140 + for p in $(git rev-list --parents -1 $sha1 | cut -d' ' -f2-)
141 do
142 if test -f "$REWRITTEN"/$p
143 then
@@ -142,41 +149,43 @@ pick_one_preserving_merges () {
149 ;; # do nothing; that parent is already there
150 *)
151 new_parents="$new_parents $new_p"
152 + ;;
153 esac
154 fi
155 done
156 case $fast_forward in
157 t)
158 output warn "Fast forward to $sha1"
151 - test $preserve=f && echo $sha1 > "$REWRITTEN"/$sha1
159 + test $preserve = f || echo $sha1 > "$REWRITTEN"/$sha1
160 ;;
161 f)
162 test "a$1" = a-n && die "Refusing to squash a merge: $sha1"
163
156 - first_parent=$(expr "$new_parents" : " \([^ ]*\)")
164 + first_parent=$(expr "$new_parents" : ' \([^ ]*\)')
165 # detach HEAD to current parent
166 output git checkout $first_parent 2> /dev/null ||
167 die "Cannot move HEAD to $first_parent"
168
169 echo $sha1 > "$DOTEST"/current-commit
170 case "$new_parents" in
163 - \ *\ *)
171 + ' '*' '*)
172 # redo merge
173 author_script=$(get_author_ident_from_commit $sha1)
174 eval "$author_script"
167 - msg="$(git cat-file commit $sha1 | \
168 - sed -e '1,/^$/d' -e "s/[\"\\]/\\\\&/g")"
175 + msg="$(git cat-file commit $sha1 | sed -e '1,/^$/d')"
176 # NEEDSWORK: give rerere a chance
177 if ! output git merge $STRATEGY -m "$msg" $new_parents
178 then
172 - echo "$msg" > "$GIT_DIR"/MERGE_MSG
179 + printf "%s\n" "$msg" > "$GIT_DIR"/MERGE_MSG
180 die Error redoing merge $sha1
181 fi
182 ;;
183 *)
184 output git cherry-pick $STRATEGY "$@" ||
185 die_with_patch $sha1 "Could not pick $sha1"
186 + ;;
187 esac
188 + ;;
189 esac
190 }
191
@@ -213,12 +222,11 @@ peek_next_command () {
222 }
223
224 do_next () {
216 - test -f "$DOTEST"/message && rm "$DOTEST"/message
217 - test -f "$DOTEST"/author-script && rm "$DOTEST"/author-script
218 - test -f "$DOTEST"/amend && rm "$DOTEST"/amend
225 + rm -f "$DOTEST"/message "$DOTEST"/author-script \
226 + "$DOTEST"/amend || exit
227 read command sha1 rest < "$TODO"
228 case "$command" in
221 - \#|'')
229 + '#'*|'')
230 mark_action_done
231 ;;
232 pick)
@@ -246,7 +254,7 @@ do_next () {
254 squash)
255 comment_for_reflog squash
256
249 - test -z "$(grep -ve '^$' -e '^#' < $DONE)" &&
257 + has_action "$DONE" ||
258 die "Cannot 'squash' without a previous commit"
259
260 mark_action_done
@@ -256,11 +264,12 @@ do_next () {
264 EDIT_COMMIT=
265 USE_OUTPUT=output
266 cp "$MSG" "$SQUASH_MSG"
259 - ;;
267 + ;;
268 *)
269 EDIT_COMMIT=-e
270 USE_OUTPUT=
263 - test -f "$SQUASH_MSG" && rm "$SQUASH_MSG"
271 + rm -f "$SQUASH_MSG" || exit
272 + ;;
273 esac
274
275 failed=f
@@ -280,11 +289,13 @@ do_next () {
289 warn
290 warn "Could not apply $sha1... $rest"
291 die_with_patch $sha1 ""
292 + ;;
293 esac
294 ;;
295 *)
296 warn "Unknown command: $command $sha1 $rest"
297 die_with_patch $sha1 "Please fix this in the file $TODO."
298 + ;;
299 esac
300 test -s "$TODO" && return
301
@@ -473,17 +484,18 @@ EOF
484 $UPSTREAM...$HEAD | \
485 sed -n "s/^>/pick /p" >> "$TODO"
486
476 - test -z "$(grep -ve '^$' -e '^#' < $TODO)" &&
487 + has_action "$TODO" ||
488 die_abort "Nothing to do"
489
490 cp "$TODO" "$TODO".backup
491 git_editor "$TODO" ||
492 die "Could not execute editor"
493
483 - test -z "$(grep -ve '^$' -e '^#' < $TODO)" &&
494 + has_action "$TODO" ||
495 die_abort "Nothing to do"
496
497 output git checkout $ONTO && do_rest
498 + ;;
499 esac
500 shift
501 done