threads / patch / 25338

patchtg.sh: simplify cat_file

Subject: [TopGit PATCH] tg.sh: simplify cat_file

## tl;dr

2 messages between Oct 4, 2010 and Oct 4, 2010. Diffs are folded; open one to read it.

replies: 1people: 1as markdown or json

Bert Wesarg· Oct 4, 2010, 18:43 UTC · lore
Use shell parameter expansion to strip the leading (w): and (i)
Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
---
 tg.sh |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)
Show changes to tg.sh +3 −5
diff --git a/tg.sh b/tg.sh
index 9d08d63..d320956 100644 tg.sh
--- a/tg.sh
+++ b/tg.sh
@@ -25,17 +25,15 @@ cat_file()
 	arg="$1"
 	case "$arg" in
 	'(w):'*)
-		arg=$(echo "$arg" | tail --bytes=+5)
-		cat "$arg"
-		return
+		cat "${arg#????}"
 		;;
 	'(i):'*)
 		# ':file' means cat from index
-		arg=$(echo "$arg" | tail --bytes=+5)
-		git cat-file blob ":$arg"
+		git cat-file blob "${arg#???}"
 		;;
 	*)
 		git cat-file blob "$arg"
+		;;
 	esac
 }
 
-- 
1.7.1.1067.g5aeb7
Bert Wesarg· Oct 4, 2010, 18:47 UTC · re: Bert Wesarg · lore

[TopGit PATCH v2] tg.sh: simplify cat_file

Use shell parameter expansion to strip the leading (w): and (i)
Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
---
No need to use wildcards, we know exactly what we want to strip.
 tg.sh |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)
Show changes to tg.sh +3 −5
diff --git a/tg.sh b/tg.sh
index 9d08d63..0e72865 100644 tg.sh
--- a/tg.sh
+++ b/tg.sh
@@ -25,17 +25,15 @@ cat_file()
 	arg="$1"
 	case "$arg" in
 	'(w):'*)
-		arg=$(echo "$arg" | tail --bytes=+5)
-		cat "$arg"
-		return
+		cat "${arg#(w):}"
 		;;
 	'(i):'*)
 		# ':file' means cat from index
-		arg=$(echo "$arg" | tail --bytes=+5)
-		git cat-file blob ":$arg"
+		git cat-file blob "${arg#(i)}"
 		;;
 	*)
 		git cat-file blob "$arg"
+		;;
 	esac
 }
 
-- 
1.7.1.1067.g5aeb7

← back to recent threads