From 537ad16e3a869aa2d70b4d24d83bd1d8c73b3b21 Mon Sep 17 00:00:00 2001 From: Stephen Rothwell Date: Thu, 10 Jul 2025 19:45:08 +1000 Subject: [PATCH] extract the check_dups function from common.sh --- check_dups.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ common.sh | 37 ------------------------------------- do_merge | 1 + fetch_trees | 1 + 4 files changed, 44 insertions(+), 37 deletions(-) create mode 100644 check_dups.sh diff --git a/check_dups.sh b/check_dups.sh new file mode 100644 index 0000000..85e716e --- /dev/null +++ b/check_dups.sh @@ -0,0 +1,42 @@ +# +# shared check_dups funciont +# + +check_dups() +{ + # "In POSIX sh, 'local' is undefined." + # shellcheck disable=SC3043 + local name base sha dfile + + name="$1" + base="$2" + sha="$3" + dlfile="$top_dir/duplicates/linus/$name" + if [ "$base" = "HEAD" ]; then + dfile="$top_dir/duplicates/next/$name" + else + dfile="$dlfile" + fi + + # if there is anything in this tree, then check for duplicates + if [ "$(git rev-list --count --no-merges "$base".."$sha")" -eq 0 ]; then + rm -f "$dfile" + return; + fi + + dups=$(git cherry "$base" "$sha" | sed -n 's/^- //p' | + xargs -r -n 1 "$tools_dir"/clog | sort) + if [ "$base" = "HEAD" ] && [ -f "$dlfile" ]; then + dups=$(printf '%s\n' "$dups" | comm -23 - "$dlfile") + fi + if [ -z "$dups" ]; then + rm -f "$dfile" + elif ! [ -f "$dfile" ]; then + printf '%s\n' "$dups" | tee "$dfile" + elif ! printf '%s\n' "$dups" | cmp -s - "$dfile"; then + printf '%s\n' "$dups" | comm -23 - "$dfile" + printf '%s\n' "$dups" >"$dfile" + fi +} + +true diff --git a/common.sh b/common.sh index 0bb8d69..272d269 100644 --- a/common.sh +++ b/common.sh @@ -134,41 +134,4 @@ check_unmerged_files() fi } -check_dups() -{ - # "In POSIX sh, 'local' is undefined." - # shellcheck disable=SC3043 - local name base sha dfile - - name="$1" - base="$2" - sha="$3" - dlfile="$top_dir/duplicates/linus/$name" - if [ "$base" = "HEAD" ]; then - dfile="$top_dir/duplicates/next/$name" - else - dfile="$dlfile" - fi - - # if there is anything in this tree, then check for duplicates - if [ "$(git rev-list --count --no-merges "$base".."$sha")" -eq 0 ]; then - rm -f "$dfile" - return; - fi - - dups=$(git cherry "$base" "$sha" | sed -n 's/^- //p' | - xargs -r -n 1 "$tools_dir"/clog | sort) - if [ "$base" = "HEAD" ] && [ -f "$dlfile" ]; then - dups=$(printf '%s\n' "$dups" | comm -23 - "$dlfile") - fi - if [ -z "$dups" ]; then - rm -f "$dfile" - elif ! [ -f "$dfile" ]; then - printf '%s\n' "$dups" | tee "$dfile" - elif ! printf '%s\n' "$dups" | cmp -s - "$dfile"; then - printf '%s\n' "$dups" | comm -23 - "$dfile" - printf '%s\n' "$dups" >"$dfile" - fi -} - true diff --git a/do_merge b/do_merge index 47a1408..34bb2f7 100755 --- a/do_merge +++ b/do_merge @@ -24,6 +24,7 @@ shift $((OPTIND - 1)) tools_dir=$(dirname "$0") . "$tools_dir/common.sh" +. "$tools_dir/check_dups.sh" log() { diff --git a/fetch_trees b/fetch_trees index 92accdd..48599f8 100755 --- a/fetch_trees +++ b/fetch_trees @@ -2,6 +2,7 @@ tools_dir=$(dirname "$0") . "$tools_dir/common.sh" '' +. "$tools_dir/check_dups.sh" if [ "$1" = '-n' ]; then shift -- 2.39.5