Skip to content

Commit 523e77a

Browse files
committed
Checkout the commit for comparison to a separate worktree
This resolves #605 -- the previous code would leave the local tree in a very confusing state. This is slower, but checks out the comparison commit to a completely separate directory with no relation to the local directory and also arranges for it to be completely cleaned up at the end.
1 parent f0bce03 commit 523e77a

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

Performance/perf_runner.sh

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ else
4141
fi
4242

4343
# Directory containing this script
44-
readonly script_dir="."
44+
readonly script_dir=`pwd`
4545

4646
# Change this if your checkout of github.com/protocolbuffers/protobuf is in a
4747
# different location.
@@ -238,10 +238,14 @@ fi
238238
# Set up a hook to cleanup revision comparison checkouts when the script
239239
# completes.
240240
declare -a CLEANUP_WHEN_DONE
241+
declare -a GIT_WORKTREE
241242
function cleanup_revision_checkouts() {
242243
if [[ "${#CLEANUP_WHEN_DONE[@]}" -ne 0 ]]; then
243244
rm -rf "${CLEANUP_WHEN_DONE[@]}"
244245
fi
246+
if [ "$GIT_WORKTREE" != "" ]; then
247+
git worktree remove "$GIT_WORKTREE"
248+
fi
245249
}
246250
trap cleanup_revision_checkouts EXIT HUP INT QUIT TERM
247251

@@ -316,19 +320,24 @@ for comparison in "${comparisons[@]}"; do
316320

317321
# Check out the commit to a temporary directory and create its _generated
318322
# directory. (Results will still go in the working tree.)
319-
tmp_checkout="$(mktemp -d -t swiftprotoperf)"
320-
CLEANUP_WHEN_DONE+=("$tmp_checkout")
321-
git --work-tree="$tmp_checkout" checkout "$comparison" -- .
322-
mkdir "$tmp_checkout/Performance/_generated"
323-
324-
build_swift_packages "$tmp_checkout" "ForRev"
325-
${PROTOC} --plugin="$tmp_checkout/.build/release/protoc-gen-swiftForRev" \
326-
--swiftForRev_out=FileNaming=DropPath:"$tmp_checkout/Performance/_generated" \
323+
GIT_WORKTREE="$(mktemp -d `pwd`/_generated/swiftprotoperf.XXXXXX)"
324+
CLEANUP_WHEN_DONE+=("$GIT_WORKTREE")
325+
git worktree add "$GIT_WORKTREE" "$comparison"
326+
mkdir "$GIT_WORKTREE/Performance/_generated"
327+
328+
build_swift_packages "$GIT_WORKTREE" "ForRev"
329+
echo ${PROTOC} --plugin="$GIT_WORKTREE/.build/release/protoc-gen-swiftForRev" \
330+
--swiftForRev_out=FileNaming=DropPath:"$GIT_WORKTREE/Performance/_generated" \
331+
--proto_path=`dirname $gen_message_path` \
332+
"$gen_message_path"
333+
${PROTOC} --plugin="$GIT_WORKTREE/.build/release/protoc-gen-swiftForRev" \
334+
--swiftForRev_out=FileNaming=DropPath:"$GIT_WORKTREE/Performance/_generated" \
335+
--proto_path=`dirname $gen_message_path` \
327336
"$gen_message_path"
328337

329-
harness_swift="$tmp_checkout/Performance/_generated/harness_swift"
338+
harness_swift="$GIT_WORKTREE/Performance/_generated/harness_swift"
330339
results_trace="$script_dir/_results/$report_type (swift)"
331-
run_swift_harness "$tmp_checkout" "$comparison" "$commit_results"
340+
run_swift_harness "$GIT_WORKTREE" "$comparison" "$commit_results"
332341
else
333342
echo
334343
echo "==== Found cached results for Swift ($comparison) ===================="

0 commit comments

Comments
 (0)