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
}

_check_patch() {
  patch=$1
  cd "$VIM_SOURCE_DIR_DEFAULT"
  # shellcheck disable=SC2126
  VERSION_LNUM="$(git show -U0 --format="" "$patch" -- src/version.c |
    grep '^+[^+]' |
    grep -Pz '(?s)\+\s+[0-9]+,\n\+\/\*\*\/' |
    wc -l)" || true
  # shellcheck disable=SC2086
  FILE_LNUM="$(diff <(git diff-tree --no-commit-id --name-only -r "$patch" | grep -v -f "$NA_REGEXP") "$NA_FILELIST" | grep -c '^<')" || true
  if test "$FILE_LNUM" -eq 0 || test "$FILE_LNUM" -eq 1 -a "$VERSION_LNUM" -eq 2; then
    if (echo "$patch" | grep -q '^v[0-9]'); then
      echo "vim-patch:$(git log -1 --pretty=format:%s "$patch" | sed 's/^patch //')"
    else
      echo "vim-patch:$(git log -1 --oneline "$patch")"
    fi
  fi
  cd "$NVIM_SOURCE_DIR"
}

list_na_patches() {
  NA_REGEXP="$NVIM_SOURCE_DIR/scripts/vim_na_regexp.txt"
  NA_FILELIST="$NVIM_SOURCE_DIR/scripts/vim_na_files.txt"

  list_missing_vimpatches 0 | while read -r patch; do
    _check_patch "$patch"
  done
}

while getopts "hlLmnMVp:P:g:r:s" opt; do
  case ${opt} in
    h)

Review comment (suggestion):
This regexp doesn't seem to work with the latest git version. With that the `git show` command above outputs for the latest patch (which matches <https://github.com/vim/vim/commit/aa9862a5b0e68581b07197f9c21b1441ab62a290.patch>):
```diff
diff --git a/src/version.c b/src/version.c
index 78fb7bea1..df2c7f050 100644
--- a/src/version.c
+++ b/src/version.c
@@ -729,6 +729,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1901,
 /**/
     1900,
 /**/
```
and reversing the two lines in the regexp seems to work:
```suggestion
    grep -Pz '(?s)\+\/\*\*\/\n\+\s+[0-9]+,' |
```

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 FILE_LNUM
  # shellcheck disable=SC2086
  FILE_LNUM="$(diff <(git -C "${VIM_SOURCE_DIR}" diff-tree --no-commit-id --name-only -r "$patch" | grep -v -f "$NA_REGEXP") "$NA_FILELIST" |
    grep -c '^<')" || FILE_LNUM=0
  test "$FILE_LNUM" -gt 1 && return 1
  if test "$FILE_LNUM" -eq 1; then
    local VERSION_LNUM
    VERSION_LNUM=$(git -C "${VIM_SOURCE_DIR}" log -1 --numstat --format= "$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}" log -1 -U1 --format="" "$patch" -- src/version.c |
      grep -Pzc '[ +]\/\*\*\/\n\+\s+[0-9]+,\n[ +]\/\*\*\/\n')" || true
    test "$VERSION_VNUM" -ne 1 && return 1
  fi
  return 0
}

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