Repository: neovim/neovim
File: scripts/vim-patch.sh (Shell)

Code before:
  echo "Found ${#pr_commit_urls[@]} commit(s)."

  local pr_commit_url
  local reply
  for pr_commit_url in "${pr_commit_urls[@]}"; do
    review_commit "${pr_commit_url}"
    if [[ "${pr_commit_url}" != "${pr_commit_urls[-1]}" ]]; then
      read -p "Continue with next commit (Y/n)? " -n 1 -r reply
      echo
      if [[ "${reply}" == n ]]; then
        break
      fi
    fi
  done

  clean_files
}

is_na_patch() {
  local patch=$1
  local NA_REGEXP="$NVIM_SOURCE_DIR/scripts/vim_na_regexp.txt"
  local NA_FILELIST="$NVIM_SOURCE_DIR/scripts/vim_na_files.txt"

  local FILES_REMAINING
  FILES_REMAINING="$(diff <(git -C "${VIM_SOURCE_DIR}" diff-tree --no-commit-id --name-only -r "$patch" | grep -v -f "$NA_REGEXP") "$NA_FILELIST" |
    grep '^<')"
  test "$FILES_REMAINING" == "" && return 0
  if test "$FILES_REMAINING" == "$(printf "< src/version.c\n")"; then
    local VERSION_LNUM
    VERSION_LNUM=$(git -C "${VIM_SOURCE_DIR}" diff-tree --no-commit-id --numstat -r "$patch" -- src/version.c | grep -c '^2\s\+0')
    test "$VERSION_LNUM" -ne 1 && return 1
    local VERSION_VNUM
    VERSION_VNUM="$(git -C "${VIM_SOURCE_DIR}" diff-tree --no-commit-id -U1 -r "$patch" -- src/version.c |
      grep -Pzc '[ +]\/\*\*\/\n\+\s+[0-9]+,\n[ +]\/\*\*\/\n')" || true
    test "$VERSION_VNUM" -eq 1 && return 0
  fi
  return 1
}

list_na_patches() {
  list_missing_vimpatches 0 | while read -r patch; do
    if is_na_patch "$patch"; then
      if (echo "$patch" | grep -q '^v[0-9]'); then
        echo "vim-patch:$(git -C "${VIM_SOURCE_DIR}" log -1 --pretty=format:%s "$patch" | sed 's/^patch //')"
      else
        echo "vim-patch:$(git -C "${VIM_SOURCE_DIR}" log -1 --oneline "$patch")"
      fi
    fi
  done
}


Review comment (bug):
`||` is to handle empty string for this `grep` or broken pipe due to `diff` getting an empty file. Had issues with is_na_patch() aborting early without `||`.

Code after:
  echo "Found ${#pr_commit_urls[@]} commit(s)."

  local pr_commit_url
  local reply
  for pr_commit_url in "${pr_commit_urls[@]}"; do
    review_commit "${pr_commit_url}"
    if [[ "${pr_commit_url}" != "${pr_commit_urls[-1]}" ]]; then
      read -p "Continue with next commit (Y/n)? " -n 1 -r reply
      echo
      if [[ "${reply}" == n ]]; then
        break
      fi
    fi
  done

  clean_files
}

is_na_patch() {
  local patch=$1
  local NA_REGEXP="$NVIM_SOURCE_DIR/scripts/vim_na_regexp.txt"
  local NA_FILELIST="$NVIM_SOURCE_DIR/scripts/vim_na_files.txt"

  local FILES_REMAINING
  FILES_REMAINING="$(diff <(git -C "${VIM_SOURCE_DIR}" diff-tree --no-commit-id --name-only -r "$patch" | grep -v -f "$NA_REGEXP") "$NA_FILELIST" |
    grep '^<')" || true
  test -z "$FILES_REMAINING" && return 0
  if test "$FILES_REMAINING" == "$(printf "< src/version.c\n")"; then
    local VERSION_LNUM
    VERSION_LNUM=$(git -C "${VIM_SOURCE_DIR}" diff-tree --no-commit-id --numstat -r "$patch" -- src/version.c | grep -c '^2\s\+0')
    test "$VERSION_LNUM" -ne 1 && return 1
    local VERSION_VNUM
    VERSION_VNUM="$(git -C "${VIM_SOURCE_DIR}" diff-tree --no-commit-id -U1 -r "$patch" -- src/version.c |
      grep -Pzc '[ +]\/\*\*\/\n\+\s+[0-9]+,\n[ +]\/\*\*\/\n')" || true
    test "$VERSION_VNUM" -eq 1 && return 0
  fi
  return 1
}

list_na_patches() {
  list_missing_vimpatches 0 | while read -r patch; do
    if is_na_patch "$patch"; then
      if (echo "$patch" | grep -q '^v[0-9]'); then
        echo "vim-patch:$(git -C "${VIM_SOURCE_DIR}" log -1 --pretty=format:%s "$patch" | sed 's/^patch //')"
      else
        echo "vim-patch:$(git -C "${VIM_SOURCE_DIR}" log -1 --oneline "$patch")"
      fi
    fi
  done
}