File: reformat.sh

package info (click to toggle)
gdal 3.12.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 92,396 kB
  • sloc: cpp: 1,224,305; ansic: 206,456; python: 26,284; java: 6,001; xml: 4,769; sh: 3,869; cs: 2,513; yacc: 1,306; makefile: 214
file content (71 lines) | stat: -rwxr-xr-x 1,301 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/sh
set -eu

if ! (cmake-format --version >/dev/null); then
  echo "cmake-format not available. Install it with 'pip install cmake-format'"
  exit 1
fi

# GNU prefix command for mac os support (gsed)
GP=
# shellcheck disable=SC2039,SC3028
case "${OSTYPE:-}" in
  darwin*)
    GP=g
    ;;
esac

# determine changed files
MODIFIED=$(git status --porcelain| ${GP}sed -ne "s/^ *[MA]  *//p" | sort -u)

if [ -z "$MODIFIED" ]; then
  echo "nothing was modified"
  exit 0
fi

FORMAT_FIX_DIFF=format_fix.diff
rm -f "$FORMAT_FIX_DIFF"
touch "$FORMAT_FIX_DIFF"

for f in $MODIFIED; do

  case "$f" in

    *CMakeLists.txt)
      ;;

    *gdal.cmake)
      ;;

    *cmake/helpers/CheckDependentLibraries.cmake)
      ;;

    *)
      continue
      ;;
  esac

  # Disable cmake-format (https://github.com/OSGeo/gdal/pull/5326#issuecomment-1042617407)
  # m=$f.prepare
  # cp "$f" "$m"
  # cmake-format -i "$f"
  # diff -u "$m" "$f" >> "$FORMAT_FIX_DIFF" || /bin/true
  # rm -f "$m"
done

ret_code=0
if [ -s "$FORMAT_FIX_DIFF" ]; then
  ret_code=1
  # review changes
  if tty -s; then
    if ! (colordiff --version >/dev/null); then
      cat "$FORMAT_FIX_DIFF"
    else
      colordiff < "$FORMAT_FIX_DIFF" | less -r
    fi
  else
    cat "$FORMAT_FIX_DIFF"
  fi
fi
rm -f "$FORMAT_FIX_DIFF"
exit $ret_code