Junio C Hamano
20 years ago
22 changed files with 1264 additions and 496 deletions
@ -1,32 +0,0 @@
@@ -1,32 +0,0 @@
|
||||
git-apply-patch-script(1) |
||||
========================= |
||||
v0.99.4, May 2005 |
||||
|
||||
NAME |
||||
---- |
||||
git-apply-patch-script - Sample script to apply the diffs from git-diff-* |
||||
|
||||
|
||||
SYNOPSIS |
||||
-------- |
||||
'git-apply-patch-script' |
||||
|
||||
DESCRIPTION |
||||
----------- |
||||
This is a sample script to be used via the 'GIT_EXTERNAL_DIFF' |
||||
environment variable to apply the differences that the "git-diff-*" |
||||
family of commands report to the current work tree. |
||||
|
||||
|
||||
Author |
||||
------ |
||||
Written by Junio C Hamano <junkio@cox.net> |
||||
|
||||
Documentation |
||||
-------------- |
||||
Documentation by David Greaves, Junio C Hamano and the git-list <git@vger.kernel.org>. |
||||
|
||||
GIT |
||||
--- |
||||
Part of the link:git.html[git] suite |
||||
|
@ -0,0 +1,57 @@
@@ -0,0 +1,57 @@
|
||||
git-cherry-pick-script(1) |
||||
========================= |
||||
v0.99.5 Aug 2005 |
||||
|
||||
NAME |
||||
---- |
||||
git-cherry-pick-script - Apply the change introduced by an existing commit. |
||||
|
||||
SYNOPSIS |
||||
-------- |
||||
'git-cherry-pick-script' [-n] [-r] <commit> |
||||
|
||||
DESCRIPTION |
||||
----------- |
||||
Given one existing commit, apply the change the patch introduces, and record a |
||||
new commit that records it. This requires your working tree to be clean (no |
||||
modifications from the HEAD commit). |
||||
|
||||
OPTIONS |
||||
------- |
||||
<commit>:: |
||||
Commit to cherry-pick. |
||||
|
||||
-r:: |
||||
Usuall the command appends which commit was |
||||
cherry-picked after the original commit message when |
||||
making a commit. This option, '--replay', causes it to |
||||
use the original commit message intact. This is useful |
||||
when you are reordering the patches in your private tree |
||||
before publishing, and is used by 'git rebase'. |
||||
|
||||
-n:: |
||||
Usually the command automatically creates a commit with |
||||
a commit log message stating which commit was |
||||
cherry-picked. This flag applies the change necessary |
||||
to cherry-pick the named commit to your working tree, |
||||
but does not make the commit. In addition, when this |
||||
option is used, your working tree does not have to match |
||||
the HEAD commit. The cherry-pick is done against the |
||||
beginning state of your working tree. |
||||
|
||||
This is useful when cherry-picking more than one commits' |
||||
effect to your working tree in a row. |
||||
|
||||
|
||||
Author |
||||
------ |
||||
Written by Junio C Hamano <junkio@cox.net> |
||||
|
||||
Documentation |
||||
-------------- |
||||
Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>. |
||||
|
||||
GIT |
||||
--- |
||||
Part of the link:git.html[git] suite |
||||
|
@ -1,144 +0,0 @@
@@ -1,144 +0,0 @@
|
||||
#!/bin/sh |
||||
# Copyright (C) 2005 Junio C Hamano |
||||
# |
||||
# Applying diff between two trees to the work tree can be |
||||
# done with the following single command: |
||||
# |
||||
# GIT_EXTERNAL_DIFF=git-apply-patch-script git-diff-tree -p $tree1 $tree2 |
||||
# |
||||
|
||||
case "$#" in |
||||
1) |
||||
echo >&2 "cannot handle unmerged diff on path $1." |
||||
exit 1 ;; |
||||
8 | 9) |
||||
echo >&2 "cannot handle rename diff between $1 and $8 yet." |
||||
exit 1 ;; |
||||
esac |
||||
name="$1" tmp1="$2" hex1="$3" mode1="$4" tmp2="$5" hex2="$6" mode2="$7" |
||||
|
||||
type1=f |
||||
case "$mode1" in |
||||
*120???) type1=l ;; |
||||
*1007??) mode1=+x ;; |
||||
*1006??) mode1=-x ;; |
||||
.) type1=- ;; |
||||
esac |
||||
|
||||
type2=f |
||||
case "$mode2" in |
||||
*120???) type2=l ;; |
||||
*1007??) mode2=+x ;; |
||||
*1006??) mode2=-x ;; |
||||
.) type2=- ;; |
||||
esac |
||||
|
||||
case "$type1,$type2" in |
||||
|
||||
-,?) |
||||
dir=$(dirname "$name") |
||||
case "$dir" in '' | .) ;; *) mkdir -p "$dir" ;; esac || { |
||||
echo >&2 "cannot create leading path for $name." |
||||
exit 1 |
||||
} |
||||
if test -e "$name" |
||||
then |
||||
echo >&2 "path $name to be created already exists." |
||||
exit 1 |
||||
fi |
||||
case "$type2" in |
||||
f) |
||||
# creating a regular file |
||||
cat "$tmp2" >"$name" || { |
||||
echo >&2 "cannot create a regular file $name." |
||||
exit 1 |
||||
} |
||||
case "$mode2" in |
||||
+x) |
||||
echo >&2 "created a regular file $name with mode +x." |
||||
chmod "$mode2" "$name" |
||||
;; |
||||
-x) |
||||
echo >&2 "created a regular file $name." |
||||
;; |
||||
esac |
||||
;; |
||||
l) |
||||
# creating a symlink |
||||
ln -s "$(cat "$tmp2")" "$name" || { |
||||
echo >&2 "cannot create a symbolic link $name." |
||||
exit 1 |
||||
} |
||||
echo >&2 "created a symbolic link $name." |
||||
;; |
||||
*) |
||||
echo >&2 "do not know how to create $name of type $type2." |
||||
exit 1 |
||||
esac |
||||
git-update-cache --add -- "$name" ;; |
||||
|
||||
?,-) |
||||
rm -f "$name" || { |
||||
echo >&2 "cannot remove $name" |
||||
exit 1 |
||||
} |
||||
echo >&2 "deleted $name." |
||||
git-update-cache --remove -- "$name" ;; |
||||
|
||||
l,f|f,l) |
||||
echo >&2 "cannot change a regular file $name and a symbolic link $name." |
||||
exit 1 ;; |
||||
|
||||
l,l) |
||||
# symlink to symlink |
||||
current=$(readlink "$name") || { |
||||
echo >&2 "cannot read the target of the symbolic link $name." |
||||
exit 1 |
||||
} |
||||
original=$(cat "$tmp1") |
||||
next=$(cat "$tmp2") |
||||
test "$original" != "$current" || { |
||||
echo >&2 "cannot apply symbolic link target change ($original->$next) to $name which points to $current." |
||||
exit 1 |
||||
} |
||||
if test "$next" != "$current" |
||||
then |
||||
rm -f "$name" && ln -s "$next" "$name" || { |
||||
echo >&2 "cannot create symbolic link $name." |
||||
exit 1 |
||||
} |
||||
echo >&2 "changed symbolic target of $name." |
||||
git-update-cache -- "$name" |
||||
fi ;; |
||||
|
||||
f,f) |
||||
# changed |
||||
test -e "$name" || { |
||||
echo >&2 "regular file $name to be patched does not exist." |
||||
exit 1 |
||||
} |
||||
dir=$(dirname "$name") |
||||
case "$dir" in '' | .) ;; *) mkdir -p "$dir";; esac || { |
||||
echo >&2 "cannot create leading path for $name." |
||||
exit 1 |
||||
} |
||||
tmp=.git-apply-patch-$$ |
||||
trap "rm -f $tmp-*" 0 1 2 3 15 |
||||
|
||||
# Be careful, in case "$tmp2" is borrowed path from the work tree |
||||
# we are looking at... |
||||
diff -u -L "a/$name" -L "b/$name" "$tmp1" "$tmp2" >$tmp-patch |
||||
|
||||
# This will say "patching ..." so we do not say anything outselves. |
||||
patch -p1 <$tmp-patch || exit |
||||
rm -f $tmp-patch |
||||
case "$mode1,$mode2" in |
||||
"$mode2,$mode1") ;; |
||||
*) |
||||
chmod "$mode2" "$name" |
||||
echo >&2 "changed mode from $mode1 to $mode2." |
||||
;; |
||||
esac |
||||
git-update-cache -- "$name" |
||||
|
||||
esac |
@ -1,37 +1,164 @@
@@ -1,37 +1,164 @@
|
||||
#!/bin/sh |
||||
# |
||||
# Copyright (c) 2005 Linus Torvalds |
||||
# Copyright (c) 2005 Junio C Hamano |
||||
# |
||||
. git-sh-setup-script || die "Not a git archive" |
||||
|
||||
# We want a clean tree and clean index to be able to revert. |
||||
status=$(git status) |
||||
case "$status" in |
||||
'nothing to commit') ;; |
||||
case "$0" in |
||||
*-revert-* ) |
||||
me=revert ;; |
||||
*-cherry-pick-* ) |
||||
me=cherry-pick ;; |
||||
esac |
||||
|
||||
usage () { |
||||
case "$me" in |
||||
cherry-pick) |
||||
die "usage git $me [-n] [-r] <commit-ish>" |
||||
;; |
||||
revert) |
||||
die "usage git $me [-n] <commit-ish>" |
||||
;; |
||||
esac |
||||
} |
||||
|
||||
no_commit= replay= |
||||
while case "$#" in 0) break ;; esac |
||||
do |
||||
case "$1" in |
||||
-n|--n|--no|--no-|--no-c|--no-co|--no-com|--no-comm|\ |
||||
--no-commi|--no-commit) |
||||
no_commit=t |
||||
;; |
||||
-r|--r|--re|--rep|--repl|--repla|--replay) |
||||
replay=t |
||||
;; |
||||
-*) |
||||
usage |
||||
;; |
||||
*) |
||||
break |
||||
;; |
||||
esac |
||||
shift |
||||
done |
||||
|
||||
test "$me,$replay" = "revert,t" && usage |
||||
|
||||
case "$no_commit" in |
||||
t) |
||||
# We do not intend to commit immediately. We just want to |
||||
# merge the differences in. |
||||
head=$(git-write-tree) || |
||||
die "Your index file is unmerged." |
||||
;; |
||||
*) |
||||
echo "$status" |
||||
die "Your working tree is dirty; cannot revert a previous patch." ;; |
||||
check_clean_tree || die "Cannot run $me from a dirty tree." |
||||
head=$(git-rev-parse --verify HEAD) || |
||||
die "You do not have a valid HEAD" |
||||
;; |
||||
esac |
||||
|
||||
rev=$(git-rev-parse --verify "$@") && |
||||
commit=$(git-rev-parse --verify "$rev^0") || exit |
||||
if git-diff-tree -R -M -p $commit | git-apply --index && |
||||
msg=$(git-rev-list --pretty=oneline --max-count=1 $commit) |
||||
then |
||||
{ |
||||
echo "$msg" | sed -e ' |
||||
s/^[^ ]* /Revert "/ |
||||
s/$/"/' |
||||
echo |
||||
echo "This reverts $commit commit." |
||||
test "$rev" = "$commit" || |
||||
echo "(original 'git revert' arguments: $@)" |
||||
} | git commit -F - |
||||
else |
||||
# Now why did it fail? |
||||
parents=`git-cat-file commit "$commit" 2>/dev/null | |
||||
sed -ne '/^$/q;/^parent /p' | |
||||
wc -l` |
||||
case $parents in |
||||
0) die "Cannot revert the root commit nor non commit-ish." ;; |
||||
1) die "The patch does not apply." ;; |
||||
*) die "Cannot revert a merge commit." ;; |
||||
esac |
||||
fi |
||||
commit=$(git-rev-parse --verify "$rev^0") || |
||||
die "Not a single commit $@" |
||||
prev=$(git-rev-parse --verify "$commit^1" 2>/dev/null) || |
||||
die "Cannot run $me a root commit" |
||||
git-rev-parse --verify "$commit^2" >/dev/null 2>&1 && |
||||
die "Cannot run $me a multi-parent commit." |
||||
|
||||
# "commit" is an existing commit. We would want to apply |
||||
# the difference it introduces since its first parent "prev" |
||||
# on top of the current HEAD if we are cherry-pick. Or the |
||||
# reverse of it if we are revert. |
||||
|
||||
case "$me" in |
||||
revert) |
||||
git-rev-list --pretty=oneline --max-count=1 $commit | |
||||
sed -e ' |
||||
s/^[^ ]* /Revert "/ |
||||
s/$/"/' |
||||
echo |
||||
echo "This reverts $commit commit." |
||||
test "$rev" = "$commit" || |
||||
echo "(original 'git revert' arguments: $@)" |
||||
base=$commit next=$prev |
||||
;; |
||||
|
||||
cherry-pick) |
||||
pick_author_script=' |
||||
/^author /{ |
||||
h |
||||
s/^author \([^<]*\) <[^>]*> .*$/\1/ |
||||
s/'\''/'\''\'\'\''/g |
||||
s/.*/GIT_AUTHOR_NAME='\''&'\''/p |
||||
|
||||
g |
||||
s/^author [^<]* <\([^>]*\)> .*$/\1/ |
||||
s/'\''/'\''\'\'\''/g |
||||
s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p |
||||
|
||||
g |
||||
s/^author [^<]* <[^>]*> \(.*\)$/\1/ |
||||
s/'\''/'\''\'\'\''/g |
||||
s/.*/GIT_AUTHOR_DATE='\''&'\''/p |
||||
|
||||
q |
||||
}' |
||||
set_author_env=`git-cat-file commit "$commit" | |
||||
sed -ne "$pick_author_script"` |
||||
eval "$set_author_env" |
||||
export GIT_AUTHOR_NAME |
||||
export GIT_AUTHOR_EMAIL |
||||
export GIT_AUTHOR_DATE |
||||
|
||||
git-cat-file commit $commit | sed -e '1,/^$/d' |
||||
case "$replay" in |
||||
'') |
||||
echo "(cherry picked from $commit commit)" |
||||
test "$rev" = "$commit" || |
||||
echo "(original 'git cherry-pick' arguments: $@)" |
||||
;; |
||||
esac |
||||
base=$prev next=$commit |
||||
;; |
||||
|
||||
esac >.msg |
||||
|
||||
# This three way merge is an interesting one. We are at |
||||
# $head, and would want to apply the change between $commit |
||||
# and $prev on top of us (when reverting), or the change between |
||||
# $prev and $commit on top of us (when cherry-picking or replaying). |
||||
|
||||
echo >&2 "First trying simple merge strategy to $me." |
||||
git-read-tree -m -u $base $head $next && |
||||
result=$(git-write-tree 2>/dev/null) || { |
||||
echo >&2 "Simple $me fails; trying Automatic $me." |
||||
git-merge-cache -o git-merge-one-file-script -a || { |
||||
echo >&2 "Automatic $me failed. After fixing it up," |
||||
echo >&2 "you can use \"git commit -F .msg\"" |
||||
case "$me" in |
||||
cherry-pick) |
||||
echo >&2 "You may choose to use the following when making" |
||||
echo >&2 "the commit:" |
||||
echo >&2 "$set_author_env" |
||||
esac |
||||
exit 1 |
||||
} |
||||
result=$(git-write-tree) || exit |
||||
} |
||||
echo >&2 "Finished one $me." |
||||
|
||||
# If we are cherry-pick, and if the merge did not result in |
||||
# hand-editing, we will hit this commit and inherit the original |
||||
# author date and name. |
||||
# If we are revert, or if our cherry-pick results in a hand merge, |
||||
# we had better say that the current user is responsible for that. |
||||
|
||||
case "$no_commit" in |
||||
'') |
||||
git commit -F .msg |
||||
rm -f .msg |
||||
;; |
||||
esac |
||||
|
Loading…
Reference in new issue