Skip to content

Commit

Permalink
cat-file: add remove_timestamp helper
Browse files Browse the repository at this point in the history
maybe_remove_timestamp() takes arguments, but it would be useful to have
a function that reads from stdin and strips the timestamp. This would
allow tests to pipe data into a function to remove timestamps, and
wouldn't have to always assign a variable. This is especially helpful
when the data is multiple lines.

Keep maybe_remove_timestamp() the same, but add a remove_timestamp
helper that reads from stdin.

The tests in the next patch will make use of this.

Signed-off-by: John Cai <johncai86@gmail.com>
  • Loading branch information
john-cai committed Feb 16, 2022
1 parent 12084a3 commit bf74b6c
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions t/t1006-cat-file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,18 @@ strlen () {
}

maybe_remove_timestamp () {
if test -z "$2"; then
echo_without_newline "$1"
else
echo_without_newline "$(printf '%s\n' "$1" | sed -e 's/ [0-9][0-9]* [-+][0-9][0-9][0-9][0-9]$//')"
fi
if test -z "$2"; then
echo_without_newline "$1"
else
echo_without_newline "$(printf '%s\n' "$1" | remove_timestamp)"
fi
}

remove_timestamp () {
sed -e 's/ [0-9][0-9]* [-+][0-9][0-9][0-9][0-9]$//'
}


run_tests () {
type=$1
sha1=$2
Expand Down

0 comments on commit bf74b6c

Please sign in to comment.