HCAI-Lab/w2-consensus-deepdive-unlearning-artifacts / social-data-attribution-w2 /scripts /bootstrap_local_deps.sh
| set -euo pipefail | |
| REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)" | |
| DEPENDENCY_ROOT="${DEPENDENCY_ROOT:-$REPO_ROOT}" | |
| PATCH_ROOT="${PATCH_ROOT:-$REPO_ROOT}" | |
| hash_file() { | |
| if command -v shasum >/dev/null 2>&1; then | |
| shasum -a 256 "$1" 2>/dev/null | cut -d' ' -f1 | |
| else | |
| sha256sum "$1" 2>/dev/null | cut -d' ' -f1 | |
| fi | |
| } | |
| deps=( | |
| "bergson|https://github.com/glennmatlin/bergson.git|ddf857d877478935cb102988567b6acd4290da1f|" | |
| "olmes|https://github.com/allenai/olmes.git|b532dd59a71004d88f8152788d79cec617c8eff6|patches/olmes-fix.patch,patches/olmes-social-tasks.patch,patches/olmes-bbq-social-task.patch,patches/olmes-pub-social-task.patch,patches/olmes-negotiationtom-social-task.patch,patches/olmes-bbh-social-task.patch,patches/olmes-tombench-social-task.patch,patches/olmes-morables-social-task.patch,patches/olmes-stereoset-social-task.patch,patches/olmes-moralexceptqa-rbqa-social-task.patch" | |
| ) | |
| ensure_clean_for_checkout() { | |
| local repo_path="$1" | |
| local name="$2" | |
| local dirty | |
| dirty="$(git -C "$repo_path" status --porcelain | grep -vE '^\?\? \.DS_Store$' || true)" | |
| if [ -n "$dirty" ]; then | |
| echo "Error: $name has local changes; cannot switch commits automatically." >&2 | |
| echo "$dirty" >&2 | |
| exit 1 | |
| fi | |
| } | |
| patch_targets() { | |
| local patch_path="$1" | |
| sed -n 's/^diff --git a\/\(.*\) b\/.*/\1/p' "$patch_path" | |
| } | |
| patch_file_state() { | |
| local repo_path="$1" | |
| local patch_path="$2" | |
| local target="$3" | |
| if git -C "$repo_path" apply --reverse --check --include="$target" "$patch_path" >/dev/null 2>&1; then | |
| echo "applied" | |
| return | |
| fi | |
| if git -C "$repo_path" apply --check --include="$target" "$patch_path" >/dev/null 2>&1; then | |
| echo "missing" | |
| return | |
| fi | |
| echo "unknown" | |
| } | |
| apply_patch_if_needed() { | |
| local repo_path="$1" | |
| local patch_path="$2" | |
| local name="$3" | |
| local target | |
| local state | |
| local missing_targets=() | |
| local unknown_targets=() | |
| local apply_args=() | |
| while IFS= read -r target; do | |
| [ -n "$target" ] || continue | |
| state="$(patch_file_state "$repo_path" "$patch_path" "$target")" | |
| case "$state" in | |
| applied) ;; | |
| missing) missing_targets+=("$target") ;; | |
| *) unknown_targets+=("$target") ;; | |
| esac | |
| done < <(patch_targets "$patch_path") | |
| if [ ${#unknown_targets[@]} -gt 0 ]; then | |
| echo "Error: $name has diverged from tracked patch $(basename "$patch_path")" >&2 | |
| printf 'Unclassified patch targets:\n' >&2 | |
| printf ' %s\n' "${unknown_targets[@]}" >&2 | |
| echo "Refresh the tracked patch or restore the vendored repo to the pinned patched state." >&2 | |
| exit 1 | |
| fi | |
| if [ ${#missing_targets[@]} -eq 0 ]; then | |
| echo "Patch already applied for $name: $(basename "$patch_path")" | |
| return | |
| fi | |
| echo "Applying patch for $name: $(basename "$patch_path")" | |
| for target in "${missing_targets[@]}"; do | |
| apply_args+=(--include="$target") | |
| done | |
| git -C "$repo_path" apply "${apply_args[@]}" "$patch_path" | |
| } | |
| patches_all_marked() { | |
| local repo_path="$1" | |
| local patch_list="$2" | |
| [ -n "$patch_list" ] || return 0 | |
| local p_arr | |
| IFS=',' read -r -a p_arr <<<"$patch_list" | |
| for patch_rel in "${p_arr[@]}"; do | |
| [ -n "$patch_rel" ] || continue | |
| local patch_path="$PATCH_ROOT/$patch_rel" | |
| local marker_file="$repo_path/.patched_$(basename "$patch_rel" .patch)" | |
| local patch_hash | |
| patch_hash="$(hash_file "$patch_path")" | |
| if [ ! -f "$marker_file" ] || [ "$(cat "$marker_file")" != "$patch_hash" ]; then | |
| return 1 | |
| fi | |
| done | |
| return 0 | |
| } | |
| for spec in "${deps[@]}"; do | |
| IFS="|" read -r name repo_url commit patch_list <<<"$spec" | |
| repo_path="$DEPENDENCY_ROOT/$name" | |
| echo "==> $name" | |
| if [ -d "$repo_path/.git" ]; then | |
| current_commit="$(git -C "$repo_path" rev-parse HEAD 2>/dev/null || true)" | |
| if [ "$current_commit" = "$commit" ] && patches_all_marked "$repo_path" "$patch_list"; then | |
| echo "$name already at pinned commit with patches applied" | |
| continue | |
| fi | |
| fi | |
| if [ ! -d "$repo_path/.git" ]; then | |
| echo "Cloning $repo_url into $repo_path" | |
| git clone "$repo_url" "$repo_path" | |
| fi | |
| if ! git -C "$repo_path" cat-file -e "$commit^{commit}" >/dev/null 2>&1; then | |
| echo "Fetching $name to resolve pinned commit" | |
| git -C "$repo_path" fetch --tags origin | |
| fi | |
| current_commit="$(git -C "$repo_path" rev-parse HEAD)" | |
| if [ "$current_commit" != "$commit" ]; then | |
| ensure_clean_for_checkout "$repo_path" "$name" | |
| echo "Checking out $name at $commit" | |
| git -C "$repo_path" checkout "$commit" | |
| else | |
| echo "$name already at pinned commit" | |
| fi | |
| if [ -n "$patch_list" ]; then | |
| IFS=',' read -r -a patches <<<"$patch_list" | |
| for patch_rel in "${patches[@]}"; do | |
| [ -n "$patch_rel" ] || continue | |
| patch_path="$PATCH_ROOT/$patch_rel" | |
| apply_patch_if_needed "$repo_path" "$patch_path" "$name" | |
| echo "$(hash_file "$patch_path")" > "$repo_path/.patched_$(basename "$patch_rel" .patch)" | |
| done | |
| fi | |
| done | |
| echo "Local dependencies are ready in $DEPENDENCY_ROOT" | |
Xet Storage Details
- Size:
- 5.33 kB
- Xet hash:
- 3351878b1a22f61297d45533a3413bbfb192e440600a736f4257266660e9707e
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.