raft icon indicating copy to clipboard operation
raft copied to clipboard

Convert naming of internal identifiers to camelCase

Open ericcurtin opened this issue 5 years ago • 1 comments

A double underscore within an identifier is illegal in C++, for interop.

ericcurtin avatar Nov 24 '20 20:11 ericcurtin

Similar in ilk to:

https://github.com/canonical/dqlite/pull/273

Fixes:

https://github.com/canonical/dqlite/issues/221

I had the script written already for dqlite, so why not re-use:

#!/bin/bash

./test/lib/fs.sh teardown
git clean -fdx
git fetch
git reset --hard origin/master

FIND="find . -name *.c -o -name *.h"
GREP="grep -v mu\|dqlite.h\|raft.h"
CC="gcc"
export PATH=$PATH:$PWD/../amalgamate

autoreconf -i
./configure --enable-example --enable-debug --enable-code-coverage --enable-sanitize
amalgamate.py --config=amalgamation.json --source=$(pwd)
$CC raft.c -c -D_GNU_SOURCE -DHAVE_LINUX_AIO_ABI_H -Wall -Wextra -Wpedantic -fpic
./test/lib/fs.sh setup
make check CFLAGS=-O0 $(./test/lib/fs.sh detect) || (cat ./test-suite.log && false)
./test/lib/fs.sh teardown
sed -i "s/-Wall/-Wall -Werror/g" Makefile
sed -i "s/-Wno-conversion/-Wno-conversion -Werror/g" Makefile
FILE="test-suite.log"

sed_change() {
  $FIND | $GREP | xargs grep -l "$i" | xargs sed -i "s/$i/$new_i/g"
  git commit -a -m "s/$i/$new_i/g"
}

clang_fmt_commit() {
  git clang-format -f HEAD~1
  git commit -a --amend --no-edit
}

rm_make() {
  rm -f $FILE
  amalgamate.py --config=amalgamation.json --source=$(pwd)
  $CC raft.c -c -D_GNU_SOURCE -DHAVE_LINUX_AIO_ABI_H -Wall -Wextra -Wpedantic -fpic
  ./test/lib/fs.sh setup
  make check CFLAGS=-O0 $(./test/lib/fs.sh detect)
  ./test/lib/fs.sh teardown
}

reset_rm_make() {
  git reset --hard HEAD~1
  rm_make
}

sed_rm_make() {
  sed_change
  rm_make
}

for i in $(git ls-tree -r master --name-only | grep ".c$\|.h$" | $GREP | xargs grep _ | tr -cs '[:alnum:]_#' '\n' | grep _ | sort | uniq); do
  new_i=$(echo $i | sed "s/__/_/g")
  echo "1 '$i' '$new_i'"
  # exceptions don't change these, leading underscore used for many system
  # defines, page_size literal string not to be changed
  if  [[ "$i" =~ ^_|^page_size|^sqlite|^foreign_keys|^journal_mode|^cache_size|^wal_autocheckpoint ]]; then
    continue
  fi

  echo "2 '$i' '$new_i'"
  if  [ "$i" != "$new_i" ]; then
    sed_rm_make
    if [ -e $FILE ] && [ "$(grep -c "30 of 31\|31 of 152" $FILE)" -eq "2" ]; then
      clang_fmt_commit
    else
      reset_rm_make
      if [ ! -e $FILE ] || [ "$(grep -c "30 of 31\|31 of 152" $FILE)" -ne "2" ]; then
        echo "__ '$i' '$new_i'"
        grep "of 171\|of 32" $FILE
        exit 1
      fi
    fi
  fi

  i="$new_i"
  new_i=$(echo $i | sed -r 's/(_)([a-z])/\U\2/g')
  echo "3 '$i' '$new_i'"
  if  [ "$i" != "$new_i" ]; then
    sed_rm_make
    if [ -e $FILE ] && [ "$(grep -c "30 of 31\|31 of 152" $FILE)" -eq "2" ]; then
      clang_fmt_commit
    else
      reset_rm_make
      if [ ! -e $FILE ] || [ "$(grep -c "30 of 31\|31 of 152" $FILE)" -ne "2" ]; then
        echo "camelCase '$i' '$new_i'"
        grep "of 171\|of 32" $FILE
        exit 2
      fi
    fi
  fi
done

ericcurtin avatar Nov 24 '20 20:11 ericcurtin