From: Junio C Hamano Date: Thu, 5 May 2005 23:16:54 +0000 (-0700) Subject: Octopus merge of the following five patches. X-Git-Tag: v0.99~634^2 X-Git-Url: https://www.git.lorimer.id.au/gitweb.git/diff_plain/211232bae64bcc60bbf5d1b5e5b2344c22ed767e?hp=b28858bf65d4fd6d8bb070865518ec43817fe7f3 Octopus merge of the following five patches. Update git-apply-patch-script for symbolic links. Make git-prune-script executable again. Do not write out new index if nothing has changed. diff-cache shows differences for unmerged paths without --cache. Update diff engine for symlinks stored in the cache. Signed-off-by: Junio C Hamano --- diff --git a/diff-cache.c b/diff-cache.c index ef522cd233..7e87d28f3a 100644 --- a/diff-cache.c +++ b/diff-cache.c @@ -57,14 +57,17 @@ static void show_new_file(struct cache_entry *new) show_file("+", new, sha1, mode); } -static int show_modified(struct cache_entry *old, struct cache_entry *new) +static int show_modified(struct cache_entry *old, + struct cache_entry *new, + int report_missing) { unsigned int mode, oldmode; unsigned char *sha1; unsigned char old_sha1_hex[60]; if (get_stat_data(new, &sha1, &mode) < 0) { - show_file("-", old, old->sha1, old->ce_mode); + if (report_missing) + show_file("-", old, old->sha1, old->ce_mode); return -1; } @@ -101,7 +104,7 @@ static int diff_cache(struct cache_entry **ac, int entries) break; } /* Show difference between old and new */ - show_modified(ac[1], ce); + show_modified(ac[1], ce, 1); break; case 1: /* No stage 3 (merge) entry? That means it's been deleted */ @@ -109,7 +112,19 @@ static int diff_cache(struct cache_entry **ac, int entries) show_file("-", ce, ce->sha1, ce->ce_mode); break; } - /* Otherwise we fall through to the "unmerged" case */ + /* We come here with ce pointing at stage 1 + * (original tree) and ac[1] pointing at stage + * 3 (unmerged). show-modified with + * report-mising set to false does not say the + * file is deleted but reports true if work + * tree does not have it, in which case we + * fall through to report the unmerged state. + * Otherwise, we show the differences between + * the original tree and the work tree. + */ + if (!cached_only && !show_modified(ce, ac[1], 0)) + break; + /* fallthru */ case 3: if (generate_patch) diff_unmerge(ce->name); diff --git a/git-apply-patch-script b/git-apply-patch-script index dccad27061..13ec1c4490 100755 --- a/git-apply-patch-script +++ b/git-apply-patch-script @@ -8,71 +8,134 @@ # case "$#" in -2) exit 1 ;; # do not feed unmerged diff to me! +2) + echo >&2 "cannot handle unmerged diff on path $1." + exit 1 ;; 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 +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 -case "$mode1,$mode2" in -.,?x) - # newly created +-,?) dir=$(dirname "$name") - case "$dir" in '' | .) ;; *) mkdir -p "$dir" esac || { + case "$dir" in '' | .) ;; *) mkdir -p "$dir" ;; esac || { echo >&2 "cannot create leading path for $name." exit 1 } - if test -f "$name" + if test -e "$name" then - echo >&2 "file $name to be created already exists." + echo >&2 "path $name to be created already exists." exit 1 fi - cat "$tmp2" >"$name" || { - echo >&2 "cannot create $name." - exit 1 - } - case "$mode2" in - +x) - echo >&2 "created $name with mode +x." - chmod "$mode2" "$name" - ;; - -x) - echo >&2 "created $name." + 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" - ;; -?x,.) - # deleted - echo >&2 "deleted $name." + git-update-cache --add -- "$name" ;; + +?,-) rm -f "$name" || { - echo >&2 "cannot remove $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 } - git-update-cache --remove -- "$name" - ;; -*) + 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 || { + case "$dir" in '' | .) ;; *) mkdir -p "$dir";; esac || { echo >&2 "cannot create leading path for $name." exit 1 } - # This will say "patching ..." so we do not say anything outselves. - diff -u -L "a/$name" -L "b/$name" "$tmp1" "$tmp2" | patch -p1 || exit + 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") ;; *) - echo >&2 "changing mode from $mode1 to $mode2." chmod "$mode2" "$name" + echo >&2 "changed mode from $mode1 to $mode2." ;; esac git-update-cache -- "$name" + esac diff --git a/git-prune-script b/git-prune-script old mode 100644 new mode 100755 diff --git a/update-cache.c b/update-cache.c index 05d584ed48..893ba8679d 100644 --- a/update-cache.c +++ b/update-cache.c @@ -15,6 +15,12 @@ */ static int allow_add = 0, allow_remove = 0, not_new = 0; +/* + * update-cache --refresh may not touch anything at all, in which case + * writing 1.6MB of the same thing is a waste. + */ +static int cache_changed = 0; + /* Three functions to allow overloaded pointer return; see linux/err.h */ static inline void *ERR_PTR(long error) { @@ -51,7 +57,7 @@ static void fill_stat_cache_info(struct cache_entry *ce, struct stat *st) ce->ce_size = htonl(st->st_size); } -static int add_file_to_cache(char *path) +static int add_file_to_cache_1(char *path) { int size, namelen; struct cache_entry *ce; @@ -93,9 +99,35 @@ static int add_file_to_cache(char *path) default: return -1; } + if (!cache_changed) { + /* If we have not smudged the cache, be careful + * to keep it clean. Find out if we have a matching + * cache entry that add_cache_entry would replace with, + * and if it matches then do not bother calling it. + */ + int pos = cache_name_pos(ce->name, namelen); + if ((0 <= pos) && + !memcmp(active_cache[pos], ce, sizeof(*ce))) { + free(ce); + /* magic to tell add_file_to_cache that + * we have not updated anything. + */ + return 999; + } + } return add_cache_entry(ce, allow_add); } +static int add_file_to_cache(char *path) +{ + int ret = add_file_to_cache_1(path); + if (ret == 0) + cache_changed = 1; + else if (ret == 999) + ret = 0; + return ret; +} + static int match_data(int fd, void *buffer, unsigned long size) { while (size) { @@ -165,6 +197,7 @@ static struct cache_entry *refresh_entry(struct cache_entry *ce) if (compare_data(ce, st.st_size)) return ERR_PTR(-EINVAL); + cache_changed = 1; size = ce_size(ce); updated = xmalloc(size); memcpy(updated, ce, size); @@ -245,6 +278,7 @@ static int add_cacheinfo(char *arg1, char *arg2, char *arg3) if (!verify_path(arg3)) return -1; + cache_changed = 1; len = strlen(arg3); size = cache_entry_size(len); ce = xmalloc(size); @@ -339,9 +373,13 @@ int main(int argc, char **argv) if (add_file_to_cache(path)) die("Unable to add %s to database", path); } - if (write_cache(newfd, active_cache, active_nr) || rename(lockfile, indexfile)) + + if (!cache_changed) + unlink(lockfile); + else if (write_cache(newfd, active_cache, active_nr) || + rename(lockfile, indexfile)) die("Unable to write new cachefile"); lockfile_name = NULL; - return has_errors; + return has_errors ? 1 : 0; }