scripts/git-resolve.sh
Source file repositories/reference/linux-study-clean/scripts/git-resolve.sh
File Facts
- System
- Linux kernel
- Corpus path
scripts/git-resolve.sh- Extension
.sh- Size
- 5940 bytes
- Lines
- 202
- Domain
- Support Tooling And Documentation
- Bucket
- scripts
- Inferred role
- Support Tooling And Documentation: scripts
- Status
- atlas-only
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
- No top-level syscall, struct, function, initcall, or export declaration detected by the generator.
Annotated Snippet
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
# (c) 2025, Sasha Levin <sashal@kernel.org>
usage() {
echo "Usage: $(basename "$0") [--selftest] [--force] <commit-id> [commit-subject]"
echo "Resolves a short git commit ID to its full SHA-1 hash, particularly useful for fixing references in commit messages."
echo ""
echo "Arguments:"
echo " --selftest Run self-tests"
echo " --force Try to find commit by subject if ID lookup fails"
echo " commit-id Short git commit ID to resolve"
echo " commit-subject Optional commit subject to help resolve between multiple matches"
exit 1
}
# Convert subject with ellipsis to grep pattern
convert_to_grep_pattern() {
local subject="$1"
# First escape ALL regex special characters
local escaped_subject
escaped_subject=$(printf '%s\n' "$subject" | sed 's/[[\.*^$()+?{}|]/\\&/g')
# Also escape colons, parentheses, and hyphens as they are special in our context
escaped_subject=$(echo "$escaped_subject" | sed 's/[:-]/\\&/g')
# Then convert escaped ... sequence to .*?
escaped_subject=$(echo "$escaped_subject" | sed 's/\\\.\\\.\\\./.*?/g')
echo "^${escaped_subject}$"
}
git_resolve_commit() {
local force=0
if [ "$1" = "--force" ]; then
force=1
shift
fi
# Split input into commit ID and subject
local input="$*"
local commit_id="${input%% *}"
local subject=""
# Extract subject if present (everything after the first space)
if [[ "$input" == *" "* ]]; then
subject="${input#* }"
# Strip the ("...") quotes if present
subject="${subject#*(\"}"
subject="${subject%\")*}"
fi
# Get all possible matching commit IDs
local matches
readarray -t matches < <(git rev-parse --disambiguate="$commit_id" 2>/dev/null)
# Return immediately if we have exactly one match
if [ ${#matches[@]} -eq 1 ]; then
echo "${matches[0]}"
return 0
fi
# If no matches and not in force mode, return failure
if [ ${#matches[@]} -eq 0 ] && [ $force -eq 0 ]; then
return 1
fi
# If we have a subject, try to find a match with that subject
if [ -n "$subject" ]; then
# Convert subject with possible ellipsis to grep pattern
local grep_pattern
grep_pattern=$(convert_to_grep_pattern "$subject")
Annotation
- Atlas domain: Support Tooling And Documentation / scripts.
- Implementation status: atlas-only.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.