git p4 test: refactor marshal_dump

This function will be useful in future tests. Move it to the git-p4 test library. Let it accept an optional argument to pick a certain marshaled object out of the input stream. Signed-off-by: Pete Wyckoff <pw@padd.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Pete Wyckoff committed Jul 4, 2012 at 09:34 UTC 798d598080a68deb4958d69adacee409a23b467b
2 files changed +13 -5
t/lib-git-p4.sh
+13
@@ -102,3 +102,16 @@ cleanup_git() {
102 rm -rf "$git" &&
103 mkdir "$git"
104 }
105 +
106 +marshal_dump() {
107 + what=$1 &&
108 + line=${2:-1} &&
109 + cat >"$TRASH_DIRECTORY/marshal-dump.py" <<-EOF &&
110 + import marshal
111 + import sys
112 + for i in range($line):
113 + d = marshal.load(sys.stdin)
114 + print d['$what']
115 + EOF
116 + "$PYTHON_PATH" "$TRASH_DIRECTORY/marshal-dump.py"
117 +}
t/t9800-git-p4-basic.sh
-5
@@ -155,11 +155,6 @@ test_expect_success 'clone bare' '
155 )
156 '
157
158 -marshal_dump() {
159 - what=$1
160 - "$PYTHON_PATH" -c 'import marshal, sys; d = marshal.load(sys.stdin); print d["'$what'"]'
161 -}
162 -
158 # Sleep a bit so that the top-most p4 change did not happen "now". Then
159 # import the repo and make sure that the initial import has the same time
160 # as the top-most change.