interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / t / lib-httpd / apply-one-time-script.sh

36 lines · 1247 bytes Raw Blame History
1#!/bin/sh
2
3# If "one-time-script" exists in $HTTPD_ROOT_PATH, run the script on the HTTP
4# response. If the response was modified as a result, delete "one-time-script"
5# so that subsequent HTTP responses are no longer modified.
6#
7# This can be used to simulate the effects of the repository changing in
8# between HTTP request-response pairs.
9test -f one-time-script || exec "$GIT_EXEC_PATH/git-http-backend"
10
11LC_ALL=C
12export LC_ALL
13
14out=out.$$
15modified=out-modified.$$
16"$GIT_EXEC_PATH/git-http-backend" >"$out"
17
18# Since Apache can execute this script for multiple requests
19# concurrently, we chain "rm one-time-script" with the logic
20# for generating a modified response. If the "rm" ran separately,
21# a concurrent request could pass the "test -f" above and
22# erroneously result in multiple modified responses or an empty
23# body depending on the race state.
24#
25# We discard stderr for ./one-time-script since it is possible
26# ./one-time-script has been removed already, which is expected
27# sometimes. In this case, the unmodified response will be returned.
28if ./one-time-script "$out" 2>/dev/null >"$modified" &&
29 ! cmp -s "$out" "$modified" &&
30 rm one-time-script 2>/dev/null
31then
32 cat "$modified"
33else
34 cat "$out"
35fi
36rm -f "$out" "$modified"