| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 1 #!/bin/bash | 1 #!/bin/sh |
|
Sebastian Noack
2017/08/23 15:52:33
It seems the only reason this script requires bash
Vasily Kuznetsov
2017/08/23 16:29:39
Done.
| |
| 2 # | 2 # |
| 3 # This file is part of Adblock Plus <https://adblockplus.org/>, | 3 # This file is part of Adblock Plus <https://adblockplus.org/>, |
| 4 # Copyright (C) 2006-2017 eyeo GmbH | 4 # Copyright (C) 2006-present eyeo GmbH |
|
Sebastian Noack
2017/08/23 15:52:33
We don't put the current year into the copyright h
Vasily Kuznetsov
2017/08/23 16:29:39
Done.
| |
| 5 # | 5 # |
| 6 # Adblock Plus is free software: you can redistribute it and/or modify | 6 # Adblock Plus is free software: you can redistribute it and/or modify |
| 7 # it under the terms of the GNU General Public License version 3 as | 7 # it under the terms of the GNU General Public License version 3 as |
| 8 # published by the Free Software Foundation. | 8 # published by the Free Software Foundation. |
| 9 # | 9 # |
| 10 # Adblock Plus is distributed in the hope that it will be useful, | 10 # Adblock Plus is distributed in the hope that it will be useful, |
| 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 # GNU General Public License for more details. | 13 # GNU General Public License for more details. |
| 14 # | 14 # |
| 15 # You should have received a copy of the GNU General Public License | 15 # You should have received a copy of the GNU General Public License |
| 16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 17 | 17 |
|
Sebastian Noack
2017/08/23 15:52:32
It is best practice to put `set -eu` at the top of
Vasily Kuznetsov
2017/08/23 16:29:39
Done.
| |
| 18 if [[ "$1" == "" ]]; then | 18 set -eu |
| 19 | |
| 20 if [ $# -lt 1 ]; then | |
| 19 echo "usage: rapply.sh PATCH" | 21 echo "usage: rapply.sh PATCH" |
| 20 exit 1 | 22 exit 1 |
| 21 fi | 23 fi |
| 22 | 24 |
| 23 SRCFILE="$1" | |
| 24 TMPFILE="$TMPDIR/`basename $SRCFILE`" | |
|
Sebastian Noack
2017/08/23 15:52:32
Where does the variable TMPDIR comes from? I don't
Vasily Kuznetsov
2017/08/23 16:29:39
It comes from POSIX (see https://en.wikipedia.org/
| |
| 25 | |
| 26 if git st >/dev/null 2>&1; then | 25 if git st >/dev/null 2>&1; then |
| 27 IMPORT="git apply" | 26 IMPORT="git apply" |
| 28 elif hg st >/dev/null 2>&1; then | 27 elif hg st >/dev/null 2>&1; then |
| 29 IMPORT="hg import --no-commit" | 28 IMPORT="hg import --no-commit -" |
| 30 else | 29 else |
| 31 echo "No repository found in `pwd`" | 30 echo "No repository found in `pwd`" |
| 32 exit 2 | 31 exit 2 |
| 33 fi | 32 fi |
| 34 | 33 |
| 35 if [[ "$SRCFILE" =~ ^https?:// ]]; then | 34 BASEDIR=$(dirname "$0") |
| 36 curl "$SRCFILE" | patchconv >"$TMPFILE" || exit 1 | 35 if [ -f "$BASEDIR/patchconv.py" ]; then |
| 37 else | 36 alias patchconv="$BASEDIR/patchconv.py" |
| 38 patchconv <"$SRCFILE" >"$TMPFILE" || exit 1 | |
|
Sebastian Noack
2017/08/23 15:52:33
Nit: Please add a space before and after the angle
Vasily Kuznetsov
2017/08/23 16:29:39
Done.
| |
| 39 fi | 37 fi |
| 40 | 38 |
| 41 $IMPORT "$TMPFILE" | 39 if [ -f "$1" ]; then |
|
Sebastian Noack
2017/08/23 15:52:32
It seems the temporary file is not cleaned up. But
Vasily Kuznetsov
2017/08/23 16:29:39
You're right, that's better.
Done.
| |
| 40 patchconv < "$1" | $IMPORT | |
| 41 else | |
| 42 curl "$1" | patchconv | $IMPORT | |
| 43 fi | |
| LEFT | RIGHT |