]> git.ozlabs.org Git - next-scripts/commitdiff
extract the check_dups function from common.sh
authorStephen Rothwell <sfr@canb.auug.org.au>
Thu, 10 Jul 2025 09:45:08 +0000 (19:45 +1000)
committerStephen Rothwell <sfr@canb.auug.org.au>
Thu, 10 Jul 2025 09:45:08 +0000 (19:45 +1000)
check_dups.sh [new file with mode: 0644]
common.sh
do_merge
fetch_trees

diff --git a/check_dups.sh b/check_dups.sh
new file mode 100644 (file)
index 0000000..85e716e
--- /dev/null
@@ -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
index 0bb8d69f5e7c0b4f364dc77718e200d5478f5ebd..272d2690a4add9521564f9c9d909c1a550aeab02 100644 (file)
--- 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
index 47a14088cd2b89447b29c1bd83a3b3218e2cd190..34bb2f73f75ae8da342aeb865f094fef82388413 100755 (executable)
--- 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()
 {
index 92accdd2e0f2ccd08a354fb92a77f776554070a2..48599f81b8450b70004bc57e4f8c0010214a9be2 100755 (executable)
@@ -2,6 +2,7 @@
 
 tools_dir=$(dirname "$0")
 . "$tools_dir/common.sh" ''
+. "$tools_dir/check_dups.sh"
 
 if [ "$1" = '-n' ]; then
        shift