git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/5] gettext: add gettextln, eval_gettextln to encode common idiom
@ 2011-08-07 11:58 Jon Seymour
  2011-08-07 11:58 ` [PATCH v2 1/5] " Jon Seymour
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Jon Seymour @ 2011-08-07 11:58 UTC (permalink / raw)
  To: git; +Cc: avarab, Jens.Lehmann, gitster, Jon Seymour

Currently, if you want to use gettext or eval_gettext to format a message
you may have to add a separate echo statement and a surrounding subshell
in order to interpolate the required trailing new line.

This patch introduces two new helper functions, gettextln and eval_gettextln
which append a trailing newline to the gettext output.

This allows constructions of the form:

	if test -s "$GIT_DIR/BISECT_START"
	then
		(
			gettext "You need to give me at least one good and one bad revisions.
(You can use \"git bisect bad\" and \"git bisect good\" for that.)" &&
			echo
		) >&2
	else
	...

to be expressed more concisely as:

	if test -s "$GIT_DIR/BISECT_START"
	then
		gettextln "You need to give me at least one good and one bad revisions.
(You can use \"git bisect bad\" and \"git bisect good\" for that.)" >&2
	else
	...

Applies cleanly to master and pu.

Revisions
=========
v2: 
	Split modifications to git-sh-i18n.sh into separate commit.
	Extended application to:
		 git-am.sh
		 git-pull.sh
		 git-stash.sh
		 git-submodule.sh
	Removed application to git-bisect.sh, pending stabilisation of this series and js/bisect-no-checkout in next or master.
	
v1: Initial RFC. Included example of application to git-bisect.sh.

Future
======
	Apply to git-bisect.sh

Jon Seymour (5):
  gettext: add gettextln, eval_gettextln to encode common idiom
  git-am: take advantage of gettextln and eval_gettextln.
  pull: take advantage of eval_gettextln
  stash: take advantage of eval_gettextln
  submodule: take advantage of gettextln and eval_gettextln.

 git-am.sh        |   31 ++++++++++++++-----------------
 git-pull.sh      |    7 ++-----
 git-sh-i18n.sh   |   19 +++++++++++++++++++
 git-stash.sh     |    9 +++------
 git-submodule.sh |   18 ++++++------------
 5 files changed, 44 insertions(+), 40 deletions(-)

-- 
1.7.6.363.g9b380.dirty

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 1/5] gettext: add gettextln, eval_gettextln to encode common idiom
  2011-08-07 11:58 [PATCH v2 0/5] gettext: add gettextln, eval_gettextln to encode common idiom Jon Seymour
@ 2011-08-07 11:58 ` Jon Seymour
  2011-08-07 11:58 ` [PATCH v2 2/5] git-am: take advantage of gettextln and eval_gettextln Jon Seymour
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Jon Seymour @ 2011-08-07 11:58 UTC (permalink / raw)
  To: git; +Cc: avarab, Jens.Lehmann, gitster, Jon Seymour

Currently, if you want to use gettext or eval_gettext to format a message
you may have to add a separate echo statement and a surrounding subshell
in order to interpolate the required trailing new line.

This patch introduces two new helper functions, gettextln and eval_gettextln
which append a trailing newline to the gettext output.

This allows constructions of the form:

	if test -s "$GIT_DIR/BISECT_START"
	then
		(
			gettext "You need to give me at least one good and one bad revisions.
(You can use \"git bisect bad\" and \"git bisect good\" for that.)" &&
			echo
		) >&2
	else
	...

to be expressed more concisely as:

	if test -s "$GIT_DIR/BISECT_START"
	then
		gettextln "You need to give me at least one good and one bad revisions.
(You can use \"git bisect bad\" and \"git bisect good\" for that.)" >&2
	else
	...

Acked-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Jon Seymour <jon.seymour@gmail.com>
---
 git-sh-i18n.sh |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/git-sh-i18n.sh b/git-sh-i18n.sh
index 32ca59d..e672366 100644
--- a/git-sh-i18n.sh
+++ b/git-sh-i18n.sh
@@ -11,19 +11,38 @@ then
 		printf "%s" "$1"
 	}
 
+	gettextln() {
+		printf "%s\n" "$1"
+	}
+
 	eval_gettext () {
 		printf "%s" "$1" | (
 			export PATH $(git sh-i18n--envsubst --variables "$1");
 			git sh-i18n--envsubst "$1"
 		)
 	}
+
+	eval_gettextln () {
+		printf "%s\n" "$1" | (
+			export PATH $(git sh-i18n--envsubst --variables "$1");
+			git sh-i18n--envsubst "$1"
+		)
+	}
 else
 	gettext () {
 		printf "%s" "# GETTEXT POISON #"
 	}
 
+	gettextln () {
+		printf "%s\n" "# GETTEXT POISON #"
+	}
+
 	eval_gettext () {
 		printf "%s" "# GETTEXT POISON #"
 	}
+
+	eval_gettextln () {
+		printf "%s\n" "# GETTEXT POISON #"
+	}
 fi
 
-- 
1.7.6.363.g9b380.dirty

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 2/5] git-am: take advantage of gettextln and eval_gettextln.
  2011-08-07 11:58 [PATCH v2 0/5] gettext: add gettextln, eval_gettextln to encode common idiom Jon Seymour
  2011-08-07 11:58 ` [PATCH v2 1/5] " Jon Seymour
@ 2011-08-07 11:58 ` Jon Seymour
  2011-08-07 11:58 ` [PATCH v2 3/5] pull: take advantage of eval_gettextln Jon Seymour
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Jon Seymour @ 2011-08-07 11:58 UTC (permalink / raw)
  To: git; +Cc: avarab, Jens.Lehmann, gitster, Jon Seymour

Signed-off-by: Jon Seymour <jon.seymour@gmail.com>
---
 git-am.sh |   31 ++++++++++++++-----------------
 1 files changed, 14 insertions(+), 17 deletions(-)

diff --git a/git-am.sh b/git-am.sh
index 463c741..6177567 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -89,11 +89,8 @@ safe_to_abort () {
 	then
 		return 0
 	fi
-	(
-		gettext "You seem to have moved HEAD since the last 'am' failure.
-Not rewinding to ORIG_HEAD" &&
-		echo
-	) >&2
+		gettextln "You seem to have moved HEAD since the last 'am' failure.
+Not rewinding to ORIG_HEAD" >&2
 	return 1
 }
 
@@ -102,9 +99,9 @@ stop_here_user_resolve () {
 	    printf '%s\n' "$resolvemsg"
 	    stop_here $1
     fi
-    eval_gettext "When you have resolved this problem run \"\$cmdline --resolved\".
+    eval_gettextln "When you have resolved this problem run \"\$cmdline --resolved\".
 If you would prefer to skip this patch, instead run \"\$cmdline --skip\".
-To restore the original branch and stop patching run \"\$cmdline --abort\"."; echo
+To restore the original branch and stop patching run \"\$cmdline --abort\"."
 
     stop_here $1
 }
@@ -118,7 +115,7 @@ go_next () {
 
 cannot_fallback () {
 	echo "$1"
-	gettext "Cannot fall back to three-way merge."; echo
+	gettextln "Cannot fall back to three-way merge."
 	exit 1
 }
 
@@ -611,9 +608,9 @@ do
 			go_next && continue
 
 		test -s "$dotest/patch" || {
-			eval_gettext "Patch is empty.  Was it split wrong?
+			eval_gettextln "Patch is empty.  Was it split wrong?
 If you would prefer to skip this patch, instead run \"\$cmdline --skip\".
-To restore the original branch and stop patching run \"\$cmdline --abort\"."; echo
+To restore the original branch and stop patching run \"\$cmdline --abort\"."
 			stop_here $this
 		}
 		rm -f "$dotest/original-commit" "$dotest/author-script"
@@ -648,7 +645,7 @@ To restore the original branch and stop patching run \"\$cmdline --abort\"."; ec
 
 	if test -z "$GIT_AUTHOR_EMAIL"
 	then
-		gettext "Patch does not have a valid e-mail address."; echo
+		gettextln "Patch does not have a valid e-mail address."
 		stop_here $this
 	fi
 
@@ -699,7 +696,7 @@ To restore the original branch and stop patching run \"\$cmdline --abort\"."; ec
 	    action=again
 	    while test "$action" = again
 	    do
-		gettext "Commit Body is:"; echo
+		gettextln "Commit Body is:"
 		echo "--------------------------"
 		cat "$dotest/final-commit"
 		echo "--------------------------"
@@ -763,16 +760,16 @@ To restore the original branch and stop patching run \"\$cmdline --abort\"."; ec
 		# working tree.
 		resolved=
 		git diff-index --quiet --cached HEAD -- && {
-			gettext "No changes - did you forget to use 'git add'?
+			gettextln "No changes - did you forget to use 'git add'?
 If there is nothing left to stage, chances are that something else
-already introduced the same changes; you might want to skip this patch."; echo
+already introduced the same changes; you might want to skip this patch."
 			stop_here_user_resolve $this
 		}
 		unmerged=$(git ls-files -u)
 		if test -n "$unmerged"
 		then
-			gettext "You still have unmerged paths in your index
-did you forget to use 'git add'?"; echo
+			gettextln "You still have unmerged paths in your index
+did you forget to use 'git add'?"
 			stop_here_user_resolve $this
 		fi
 		apply_status=0
@@ -797,7 +794,7 @@ did you forget to use 'git add'?"; echo
 	fi
 	if test $apply_status != 0
 	then
-		eval_gettext 'Patch failed at $msgnum $FIRSTLINE'; echo
+		eval_gettextln 'Patch failed at $msgnum $FIRSTLINE'
 		stop_here_user_resolve $this
 	fi
 
-- 
1.7.6.363.g9b380.dirty

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 3/5] pull: take advantage of eval_gettextln
  2011-08-07 11:58 [PATCH v2 0/5] gettext: add gettextln, eval_gettextln to encode common idiom Jon Seymour
  2011-08-07 11:58 ` [PATCH v2 1/5] " Jon Seymour
  2011-08-07 11:58 ` [PATCH v2 2/5] git-am: take advantage of gettextln and eval_gettextln Jon Seymour
@ 2011-08-07 11:58 ` Jon Seymour
  2011-08-07 11:58 ` [PATCH v2 4/5] stash: " Jon Seymour
  2011-08-07 11:58 ` [PATCH v2 5/5] submodule: take advantage of gettextln and eval_gettextln Jon Seymour
  4 siblings, 0 replies; 6+ messages in thread
From: Jon Seymour @ 2011-08-07 11:58 UTC (permalink / raw)
  To: git; +Cc: avarab, Jens.Lehmann, gitster, Jon Seymour

Signed-off-by: Jon Seymour <jon.seymour@gmail.com>
---
 git-pull.sh |    7 ++-----
 1 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/git-pull.sh b/git-pull.sh
index a10b129..d3ffd8f 100755
--- a/git-pull.sh
+++ b/git-pull.sh
@@ -217,12 +217,9 @@ then
 	# $orig_head commit, but we are merging into $curr_head.
 	# First update the working tree to match $curr_head.
 
-	(
-		eval_gettext "Warning: fetch updated the current branch head.
+	eval_gettextln "Warning: fetch updated the current branch head.
 Warning: fast-forwarding your working tree from
-Warning: commit \$orig_head." &&
-		echo
-	) >&2
+Warning: commit \$orig_head." >&2
 	git update-index -q --refresh
 	git read-tree -u -m "$orig_head" "$curr_head" ||
 		die "$(eval_gettext "Cannot fast-forward your working tree.
-- 
1.7.6.363.g9b380.dirty

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 4/5] stash: take advantage of eval_gettextln
  2011-08-07 11:58 [PATCH v2 0/5] gettext: add gettextln, eval_gettextln to encode common idiom Jon Seymour
                   ` (2 preceding siblings ...)
  2011-08-07 11:58 ` [PATCH v2 3/5] pull: take advantage of eval_gettextln Jon Seymour
@ 2011-08-07 11:58 ` Jon Seymour
  2011-08-07 11:58 ` [PATCH v2 5/5] submodule: take advantage of gettextln and eval_gettextln Jon Seymour
  4 siblings, 0 replies; 6+ messages in thread
From: Jon Seymour @ 2011-08-07 11:58 UTC (permalink / raw)
  To: git; +Cc: avarab, Jens.Lehmann, gitster, Jon Seymour

Signed-off-by: Jon Seymour <jon.seymour@gmail.com>
---
 git-stash.sh |    9 +++------
 1 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/git-stash.sh b/git-stash.sh
index f4e6f05..31dec0a 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -198,8 +198,8 @@ save_stash () {
 			#    $ git stash save --blah-blah 2>&1 | head -n 2
 			#    error: unknown option for 'stash save': --blah-blah
 			#           To provide a message, use git stash save -- '--blah-blah'
-			eval_gettext "$("error: unknown option for 'stash save': \$option
-       To provide a message, use git stash save -- '\$option'")"; echo
+			eval_gettextln "$("error: unknown option for 'stash save': \$option
+       To provide a message, use git stash save -- '\$option'")"
 			usage
 			;;
 		*)
@@ -470,10 +470,7 @@ apply_stash () {
 		status=$?
 		if test -n "$INDEX_OPTION"
 		then
-			(
-				gettext "Index was not unstashed." &&
-				echo
-			) >&2
+			gettextln "Index was not unstashed." >&2
 		fi
 		exit $status
 	fi
-- 
1.7.6.363.g9b380.dirty

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 5/5] submodule: take advantage of gettextln and eval_gettextln.
  2011-08-07 11:58 [PATCH v2 0/5] gettext: add gettextln, eval_gettextln to encode common idiom Jon Seymour
                   ` (3 preceding siblings ...)
  2011-08-07 11:58 ` [PATCH v2 4/5] stash: " Jon Seymour
@ 2011-08-07 11:58 ` Jon Seymour
  4 siblings, 0 replies; 6+ messages in thread
From: Jon Seymour @ 2011-08-07 11:58 UTC (permalink / raw)
  To: git; +Cc: avarab, Jens.Lehmann, gitster, Jon Seymour

Signed-off-by: Jon Seymour <jon.seymour@gmail.com>
---
 git-submodule.sh |   18 ++++++------------
 1 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/git-submodule.sh b/git-submodule.sh
index bc1d3fa..986c5d6 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -223,12 +223,9 @@ cmd_add()
 
 	if test -z "$force" && ! git add --dry-run --ignore-missing "$path" > /dev/null 2>&1
 	then
-		(
-			eval_gettext "The following path is ignored by one of your .gitignore files:
+		eval_gettextln "The following path is ignored by one of your .gitignore files:
 \$path
-Use -f if you really want to add it." &&
-			echo
-		) >&2
+Use -f if you really want to add it." >&2
 		exit 1
 	fi
 
@@ -237,7 +234,7 @@ Use -f if you really want to add it." &&
 	then
 		if test -d "$path"/.git -o -f "$path"/.git
 		then
-			eval_gettext "Adding existing repo at '\$path' to the index"; echo
+			eval_gettextln "Adding existing repo at '\$path' to the index"
 		else
 			die "$(eval_gettext "'\$path' already exists and is not a valid git repo")"
 		fi
@@ -696,10 +693,7 @@ cmd_summary() {
 				;; # removed
 			*)
 				# unexpected type
-				(
-					eval_gettext "unexpected mode \$mod_dst" &&
-					echo
-				) >&2
+				eval_gettextln "unexpected mode \$mod_dst" >&2
 				continue ;;
 			esac
 		fi
@@ -786,9 +780,9 @@ cmd_summary() {
 	done |
 	if test -n "$for_status"; then
 		if [ -n "$files" ]; then
-			gettext "# Submodules changed but not updated:"; echo
+			gettextln "# Submodules changed but not updated:"
 		else
-			gettext "# Submodule changes to be committed:"; echo
+			gettextln "# Submodule changes to be committed:"
 		fi
 		echo "#"
 		sed -e 's|^|# |' -e 's|^# $|#|'
-- 
1.7.6.363.g9b380.dirty

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-08-07 11:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-07 11:58 [PATCH v2 0/5] gettext: add gettextln, eval_gettextln to encode common idiom Jon Seymour
2011-08-07 11:58 ` [PATCH v2 1/5] " Jon Seymour
2011-08-07 11:58 ` [PATCH v2 2/5] git-am: take advantage of gettextln and eval_gettextln Jon Seymour
2011-08-07 11:58 ` [PATCH v2 3/5] pull: take advantage of eval_gettextln Jon Seymour
2011-08-07 11:58 ` [PATCH v2 4/5] stash: " Jon Seymour
2011-08-07 11:58 ` [PATCH v2 5/5] submodule: take advantage of gettextln and eval_gettextln Jon Seymour

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).