diff options
author | Junio C Hamano <junkio@cox.net> | 2005-05-01 09:33:12 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-05-01 09:33:12 -0700 |
commit | 5d2f8b2753183e6cf2238a6f2d847e54211ba11f (patch) | |
tree | 875735be17d24d11433354682a32e96a12f003d8 /git-apply-patch-script | |
parent | c983370e5e208cca4deda82184478ba445a156e6 (diff) | |
download | git-5d2f8b2753183e6cf2238a6f2d847e54211ba11f.tar.gz |
[PATCH] Add git-apply-patch-script.
I said:
- Stop attempting to be compatible with cg-patch, and drop
(mode:XXXXXX) bits from the diff.
- Do keep the /dev/null change for created and deleted case.
- No "Index:" line, no "Mode change:" line, anywhere in the
output. Anything that wants the mode bits and sha1 hash can
do things from GIT_EXTERNAL_DIFF mechanism. Maybe document
suggested usage better.
This adds an example script git-apply-patch-script, that can be
used as the GIT_EXTERNAL_DIFF to apply changes between two trees
directly on the current work tree, like this:
GIT_EXTERNAL_DIFF=git-apply-patch-script git-diff-tree -p <tree> <tree>
Signed-off-by: Junio C Hamano <junkio@cox.net>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'git-apply-patch-script')
-rw-r--r-- | git-apply-patch-script | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/git-apply-patch-script b/git-apply-patch-script new file mode 100644 index 0000000000..b6387f6646 --- /dev/null +++ b/git-apply-patch-script @@ -0,0 +1,60 @@ +#!/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 +2) exit 1 ;; # do not feed unmerged diff to me! +esac +name="$1" tmp1="$2" hex1="$3" mode1="$4" tmp2="$5" hex2="$6" mode2="$7" +case "$mode1" in *7??) mode1=+x ;; *6??) mode1=-x ;; esac +case "$mode2" in *7??) mode2=+x ;; *6??) mode2=-x ;; esac + +if test -f "$name.orig" || test -f "$name.rej" +then + echo >&2 "Unresolved patch conflicts in the previous run found." + exit 1 +fi +# This will say "patching ..." so we do not say anything outselves. + +diff -u -L "a/$name" -L "b/$name" "$tmp1" "$tmp2" | patch -p1 +test -f "$name.rej" || { + case "$mode1,$mode2" in + .,?x) + # newly created + case "$mode2" in + +x) + echo >&2 "created $name with mode +x." + chmod "$mode2" "$name" + ;; + -) + echo >&2 "created $name." + ;; + esac + git-update-cache --add -- "$name" + ;; + ?x,.) + # deleted + echo >&2 "deleted $name." + rm -f "$name" + git-update-cache --remove -- "$name" + ;; + *) + # changed + case "$mode1,$mode2" in + "$mode2,$mode1") ;; + *) + echo >&2 "changing mode from $mode1 to $mode2." + chmod "$mode2" "$name" + ;; + esac + esac + # This bit is debatable---the SCM may not want to keep + # cache in sync with the work tree (JIT does want to). + git-update-cache -- "$name" +} +exit 0 |