Changeset View
Changeset View
Standalone View
Standalone View
tools/tools/git/git-arc.sh
Show First 20 Lines • Show All 336 Lines • ▼ Show 20 Lines | |||||
build_commit_list() | build_commit_list() | ||||
{ | { | ||||
local chash _commits commits | local chash _commits commits | ||||
for chash in "$@"; do | for chash in "$@"; do | ||||
_commits=$(git rev-parse "${chash}") | _commits=$(git rev-parse "${chash}") | ||||
if ! git cat-file -e "${chash}"'^{commit}' >/dev/null 2>&1; then | if ! git cat-file -e "${chash}"'^{commit}' >/dev/null 2>&1; then | ||||
_commits=$(git rev-list "$_commits" | tail -r) | _commits=$(git rev-list "$_commits" | tail -r) | ||||
freebsd_igalic.co: note that gnu tail doesn't support -r
http://manpages.ubuntu.com/manpages/bionic/man1/tail.1. | |||||
fi | fi | ||||
[ -n "$_commits" ] || err "invalid commit ID ${chash}" | [ -n "$_commits" ] || err "invalid commit ID ${chash}" | ||||
commits="$commits $_commits" | commits="$commits $_commits" | ||||
done | done | ||||
echo "$commits" | echo "$commits" | ||||
} | } | ||||
gitarc::create() | gitarc__create() | ||||
{ | { | ||||
local commit commits doprompt list o prev reviewers subscribers | local commit commits doprompt list o prev reviewers subscribers | ||||
list= | list= | ||||
if [ "$(git config --bool --default false --get arc.list)" != "false" ]; then | if [ "$(git config --bool --get arc.list 2>/dev/null || echo false)" != "false" ]; then | ||||
list=1 | list=1 | ||||
fi | fi | ||||
doprompt=1 | doprompt=1 | ||||
while getopts lr:s: o; do | while getopts lr:s: o; do | ||||
case "$o" in | case "$o" in | ||||
l) | l) | ||||
list=1 | list=1 | ||||
;; | ;; | ||||
Show All 30 Lines | for commit in ${commits}; do | ||||
prev=$(commit2diff "$commit") | prev=$(commit2diff "$commit") | ||||
else | else | ||||
prev="" | prev="" | ||||
fi | fi | ||||
done | done | ||||
restore_head | restore_head | ||||
} | } | ||||
gitarc::list() | gitarc__list() | ||||
{ | { | ||||
local chash commit commits diff title | local chash commit commits diff title | ||||
commits=$(build_commit_list "$@") | commits=$(build_commit_list "$@") | ||||
for commit in $commits; do | for commit in $commits; do | ||||
chash=$(git show -s --format='%C(auto)%h' "$commit") | chash=$(git show -s --format='%C(auto)%h' "$commit") | ||||
echo -n "${chash} " | echo -n "${chash} " | ||||
Show All 16 Lines | for commit in $commits; do | ||||
echo "$diff" | grep -E -o 'D[1-9][0-9]*:' | tr -d ':' \ | echo "$diff" | grep -E -o 'D[1-9][0-9]*:' | tr -d ':' \ | ||||
| paste -sd ',' - | sed 's/,/, /g' | | paste -sd ',' - | sed 's/,/, /g' | ||||
else | else | ||||
echo "$diff" | sed -e 's/^[^ ]* *//' | echo "$diff" | sed -e 's/^[^ ]* *//' | ||||
fi | fi | ||||
done | done | ||||
} | } | ||||
gitarc::patch() | gitarc__patch() | ||||
{ | { | ||||
local rev | local rev | ||||
if [ $# -eq 0 ]; then | if [ $# -eq 0 ]; then | ||||
err_usage | err_usage | ||||
fi | fi | ||||
for rev in "$@"; do | for rev in "$@"; do | ||||
arc patch --skip-dependencies --nocommit --nobranch --force "$rev" | arc patch --skip-dependencies --nocommit --nobranch --force "$rev" | ||||
echo "Applying ${rev}..." | echo "Applying ${rev}..." | ||||
[ $? -eq 0 ] || break | [ $? -eq 0 ] || break | ||||
done | done | ||||
} | } | ||||
gitarc::stage() | gitarc__stage() | ||||
{ | { | ||||
local author branch commit commits diff reviewers tmp | local author branch commit commits diff reviewers tmp | ||||
branch=main | branch=main | ||||
while getopts b: o; do | while getopts b: o; do | ||||
case "$o" in | case "$o" in | ||||
b) | b) | ||||
branch="$OPTARG" | branch="$OPTARG" | ||||
Show All 31 Lines | for commit in $commits; do | ||||
warn "Failed to apply $(git rev-parse --short "${commit}"). Are you staging patches in the wrong order?" | warn "Failed to apply $(git rev-parse --short "${commit}"). Are you staging patches in the wrong order?" | ||||
git checkout -f | git checkout -f | ||||
break | break | ||||
fi | fi | ||||
git commit --edit --file "$tmp" --author "${author}" | git commit --edit --file "$tmp" --author "${author}" | ||||
done | done | ||||
} | } | ||||
gitarc::update() | gitarc__update() | ||||
{ | { | ||||
local commit commits diff | local commit commits diff | ||||
commits=$(build_commit_list "$@") | commits=$(build_commit_list "$@") | ||||
save_head | save_head | ||||
for commit in ${commits}; do | for commit in ${commits}; do | ||||
diff=$(commit2diff "$commit") | diff=$(commit2diff "$commit") | ||||
Show All 9 Lines | for commit in ${commits}; do | ||||
arc diff --allow-untracked --never-apply-patches --update "$diff" HEAD~ | arc diff --allow-untracked --never-apply-patches --update "$diff" HEAD~ | ||||
done | done | ||||
restore_head | restore_head | ||||
} | } | ||||
set -e | set -e | ||||
ASSUME_YES= | ASSUME_YES= | ||||
if [ "$(git config --bool --default false --get arc.assume-yes)" != "false" ]; then | if [ "$(git config --bool --get arc.assume-yes 2>/dev/null || echo false)" != "false" ]; then | ||||
ASSUME_YES=1 | ASSUME_YES=1 | ||||
fi | fi | ||||
VERBOSE= | VERBOSE= | ||||
while getopts vy o; do | while getopts vy o; do | ||||
case "$o" in | case "$o" in | ||||
v) | v) | ||||
VERBOSE=1 | VERBOSE=1 | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | |||||
case $verb in | case $verb in | ||||
list|patch) | list|patch) | ||||
;; | ;; | ||||
*) | *) | ||||
require_clean_work_tree "$verb" | require_clean_work_tree "$verb" | ||||
;; | ;; | ||||
esac | esac | ||||
if [ "$(git config --bool --default false --get arc.browse)" != "false" ]; then | if [ "$(git config --bool --get arc.browse 2>/dev/null || echo false)" != "false" ]; then | ||||
BROWSE=--browse | BROWSE=--browse | ||||
fi | fi | ||||
trap restore_head EXIT INT | trap restore_head EXIT INT | ||||
gitarc::"${verb}" "$@" | gitarc__"${verb}" "$@" |
note that gnu tail doesn't support -r
http://manpages.ubuntu.com/manpages/bionic/man1/tail.1.html