mirror of
https://github.com/narrrl/proton-sdk-rs.git
synced 2026-11-03 16:41:26 +01:00
fix(scripts): upstream-sync reads short pins and detects rewritten history
- read the SHA from the Pinned line (7-40 chars) instead of requiring a full 40-char SHA the script itself never printed; the old grep died silently under pipefail - print the full head SHA to pin - require the pin to be an ancestor of origin/main, since a rewritten-away pin still resolves locally until gc - --diffs now prints patches, not just stats - --all no longer reports dropped noise - accept submodule/worktree checkouts where .git is a file
This commit is contained in:
1 parent
f7054c3c3b
commit
7422036f65
1 file changed
+18
-12
+18
-12
@@ -2,8 +2,8 @@
|
|||||||
#
|
#
|
||||||
# upstream-sync.sh — list C#-relevant upstream commits since our pinned SHA.
|
# upstream-sync.sh — list C#-relevant upstream commits since our pinned SHA.
|
||||||
#
|
#
|
||||||
# Our pure-Rust port mirrors the canonical C# SDK only, so we watch the subtree
|
# Our pure-Rust port mirrors the canonical C# SDK only, so we watch the C#
|
||||||
# client/cs/sdk/src and drop noise (chore/docs/test/ci/build) commits. The sdk/
|
# subtree (see SUBTREE) and drop noise (chore/docs/test/ci/build) commits. The sdk/
|
||||||
# checkout is gitignored; UPSTREAM_SYNC.md holds the last-reconciled SHA.
|
# checkout is gitignored; UPSTREAM_SYNC.md holds the last-reconciled SHA.
|
||||||
#
|
#
|
||||||
# Usage:
|
# Usage:
|
||||||
@@ -34,25 +34,27 @@ for arg in "$@"; do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
[ -d "$SDK/.git" ] || { echo "error: $SDK is not a git checkout" >&2; exit 1; }
|
git -C "$SDK" rev-parse --git-dir >/dev/null 2>&1 || { echo "error: $SDK is not a git checkout" >&2; exit 1; }
|
||||||
|
|
||||||
PIN="$(grep -oE '[0-9a-f]{40}' "$PIN_FILE" | head -1)"
|
# first 7-40 char SHA on the Pinned line; the rest of the file is history
|
||||||
[ -n "$PIN" ] || { echo "error: no 40-char SHA found in $PIN_FILE" >&2; exit 1; }
|
PIN="$(grep -m1 'Pinned' "$PIN_FILE" | grep -oE '[0-9a-f]{7,40}' | head -1 || true)"
|
||||||
|
[ -n "$PIN" ] || { echo "error: no Pinned SHA found in $PIN_FILE" >&2; exit 1; }
|
||||||
|
|
||||||
echo "fetching upstream..." >&2
|
echo "fetching upstream..." >&2
|
||||||
git -C "$SDK" fetch --quiet origin
|
git -C "$SDK" fetch --quiet origin
|
||||||
|
|
||||||
# Upstream force-pushes: a pin whose object is gone would make the log below
|
# Upstream force-pushes: a dangling pin used to read as "up to date", and a
|
||||||
# fail, which used to read as "up to date". Fail loudly instead.
|
# rewritten-away pin still resolves locally until gc. Require ancestry instead.
|
||||||
if ! git -C "$SDK" cat-file -e "${PIN}^{commit}" 2>/dev/null; then
|
PIN="$(git -C "$SDK" rev-parse --verify --quiet "${PIN}^{commit}" || true)"
|
||||||
echo "error: pinned commit $PIN is not in the upstream history." >&2
|
if [ -z "$PIN" ] || ! git -C "$SDK" merge-base --is-ancestor "$PIN" "$REMOTE_REF"; then
|
||||||
|
echo "error: pinned commit is not in the upstream history of $REMOTE_REF." >&2
|
||||||
echo " upstream rewrote its history; re-pin from a commit date in the log." >&2
|
echo " upstream rewrote its history; re-pin from a commit date in the log." >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
HEAD_SHA="$(git -C "$SDK" rev-parse --short "$REMOTE_REF")"
|
HEAD_SHA="$(git -C "$SDK" rev-parse "$REMOTE_REF")"
|
||||||
echo "pinned: ${PIN:0:8}"
|
echo "pinned: ${PIN:0:8}"
|
||||||
echo "head: $HEAD_SHA ($REMOTE_REF)"
|
echo "head: ${HEAD_SHA:0:8} ($REMOTE_REF)"
|
||||||
echo "subtree: ${SUBTREE[*]}"
|
echo "subtree: ${SUBTREE[*]}"
|
||||||
echo
|
echo
|
||||||
|
|
||||||
@@ -70,7 +72,11 @@ else
|
|||||||
relevant="$(echo "$commits" | grep -vE "$NOISE" || true)"
|
relevant="$(echo "$commits" | grep -vE "$NOISE" || true)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if $keep_noise; then
|
||||||
|
dropped=0
|
||||||
|
else
|
||||||
dropped="$(echo "$commits" | grep -cE "$NOISE" || true)"
|
dropped="$(echo "$commits" | grep -cE "$NOISE" || true)"
|
||||||
|
fi
|
||||||
echo "cs commits since pin: $(echo "$commits" | grep -c . || true) (noise dropped: ${dropped:-0})"
|
echo "cs commits since pin: $(echo "$commits" | grep -c . || true) (noise dropped: ${dropped:-0})"
|
||||||
echo
|
echo
|
||||||
|
|
||||||
@@ -88,7 +94,7 @@ if $show_diffs; then
|
|||||||
echo "$relevant" | awk '{print $1}' | while read -r sha; do
|
echo "$relevant" | awk '{print $1}' | while read -r sha; do
|
||||||
echo
|
echo
|
||||||
echo "----- $sha -----"
|
echo "----- $sha -----"
|
||||||
git -C "$SDK" show --stat --format="%H%n%an %ci%n%n %s%n" "$sha" -- "${SUBTREE[@]}"
|
git -C "$SDK" show --stat --patch --format="%H%n%an %ci%n%n %s%n" "$sha" -- "${SUBTREE[@]}"
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user