diff options
author | Junio C Hamano <junkio@cox.net> | 2007-04-25 09:12:48 +0400 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2007-04-25 09:12:48 +0400 |
commit | 7c9375e7d1c64862c32749dac2fc873fa923ae7c (patch) | |
tree | ec989a86cff36bed234e077e1997391603338f3b | |
parent | b01c7c0ee3b692055c6026a9e22380d6ad35811b (diff) | |
parent | 43342941dd736fe06fe607a1594422cc8ba461a1 (diff) |
Merge branch 'mk/diff'
* mk/diff:
Diff between two blobs should take mode changes into account now.
use mode of the tree in git-diff, if <tree>:<file> syntax is used
store mode in rev_list, if <tree>:<filename> syntax is used
add add_object_array_with_mode
add get_sha1_with_mode
Add S_IFINVALID mode
-rw-r--r-- | builtin-diff.c | 22 | ||||
-rw-r--r-- | cache.h | 4 | ||||
-rw-r--r-- | object.c | 6 | ||||
-rw-r--r-- | object.h | 2 | ||||
-rw-r--r-- | revision.c | 17 | ||||
-rw-r--r-- | revision.h | 1 | ||||
-rw-r--r-- | sha1_name.c | 11 |
7 files changed, 49 insertions, 14 deletions
diff --git a/builtin-diff.c b/builtin-diff.c index 2ae60097b8..7f367b6b9d 100644 --- a/builtin-diff.c +++ b/builtin-diff.c @@ -13,13 +13,10 @@ #include "log-tree.h" #include "builtin.h" -/* NEEDSWORK: struct object has place for name but we _do_ - * know mode when we extracted the blob out of a tree, which - * we currently lose. - */ struct blobinfo { unsigned char sha1[20]; const char *name; + unsigned mode; }; static const char builtin_diff_usage[] = @@ -35,7 +32,7 @@ static void stuff_change(struct diff_options *opt, struct diff_filespec *one, *two; if (!is_null_sha1(old_sha1) && !is_null_sha1(new_sha1) && - !hashcmp(old_sha1, new_sha1)) + !hashcmp(old_sha1, new_sha1) && (old_mode == new_mode)) return; if (opt->reverse_diff) { @@ -70,8 +67,12 @@ static int builtin_diff_b_f(struct rev_info *revs, die("'%s': %s", path, strerror(errno)); if (!(S_ISREG(st.st_mode) || S_ISLNK(st.st_mode))) die("'%s': not a regular file or symlink", path); + + if (blob[0].mode == S_IFINVALID) + blob[0].mode = canon_mode(st.st_mode); + stuff_change(&revs->diffopt, - canon_mode(st.st_mode), canon_mode(st.st_mode), + blob[0].mode, canon_mode(st.st_mode), blob[0].sha1, null_sha1, path, path); diffcore_std(&revs->diffopt); @@ -88,8 +89,14 @@ static int builtin_diff_blobs(struct rev_info *revs, if (argc > 1) usage(builtin_diff_usage); + if (blob[0].mode == S_IFINVALID) + blob[0].mode = mode; + + if (blob[1].mode == S_IFINVALID) + blob[1].mode = mode; + stuff_change(&revs->diffopt, - mode, mode, + blob[0].mode, blob[1].mode, blob[0].sha1, blob[1].sha1, blob[0].name, blob[1].name); diffcore_std(&revs->diffopt); @@ -272,6 +279,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix) die("more than two blobs given: '%s'", name); hashcpy(blob[blobs].sha1, obj->sha1); blob[blobs].name = name; + blob[blobs].mode = list->mode; blobs++; continue; @@ -24,6 +24,9 @@ #define DTYPE(de) DT_UNKNOWN #endif +/* unknown mode (impossible combination S_IFIFO|S_IFCHR) */ +#define S_IFINVALID 0030000 + /* * A "directory link" is a link to another git directory. * @@ -339,6 +342,7 @@ static inline unsigned int hexval(unsigned int c) #define DEFAULT_ABBREV 7 extern int get_sha1(const char *str, unsigned char *sha1); +extern int get_sha1_with_mode(const char *str, unsigned char *sha1, unsigned *mode); extern int get_sha1_hex(const char *hex, unsigned char *sha1); extern char *sha1_to_hex(const unsigned char *sha1); /* static buffer result! */ extern int read_ref(const char *filename, unsigned char *sha1); @@ -231,6 +231,11 @@ int object_list_contains(struct object_list *list, struct object *obj) void add_object_array(struct object *obj, const char *name, struct object_array *array) { + add_object_array_with_mode(obj, name, array, S_IFINVALID); +} + +void add_object_array_with_mode(struct object *obj, const char *name, struct object_array *array, unsigned mode) +{ unsigned nr = array->nr; unsigned alloc = array->alloc; struct object_array_entry *objects = array->objects; @@ -243,5 +248,6 @@ void add_object_array(struct object *obj, const char *name, struct object_array } objects[nr].item = obj; objects[nr].name = name; + objects[nr].mode = mode; array->nr = ++nr; } @@ -17,6 +17,7 @@ struct object_array { struct object_array_entry { struct object *item; const char *name; + unsigned mode; } *objects; }; @@ -77,5 +78,6 @@ int object_list_contains(struct object_list *list, struct object *obj); /* Object array handling .. */ void add_object_array(struct object *obj, const char *name, struct object_array *array); +void add_object_array_with_mode(struct object *obj, const char *name, struct object_array *array, unsigned mode); #endif /* OBJECT_H */ diff --git a/revision.c b/revision.c index ce70f48ce0..49bd29225b 100644 --- a/revision.c +++ b/revision.c @@ -116,9 +116,14 @@ void mark_parents_uninteresting(struct commit *commit) void add_pending_object(struct rev_info *revs, struct object *obj, const char *name) { + add_pending_object_with_mode(revs, obj, name, S_IFINVALID); +} + +void add_pending_object_with_mode(struct rev_info *revs, struct object *obj, const char *name, unsigned mode) +{ if (revs->no_walk && (obj->flags & UNINTERESTING)) die("object ranges do not make sense when not walking revisions"); - add_object_array(obj, name, &revs->pending); + add_object_array_with_mode(obj, name, &revs->pending, mode); if (revs->reflog_info && obj->type == OBJ_COMMIT) add_reflog_for_walk(revs->reflog_info, (struct commit *)obj, name); @@ -723,6 +728,7 @@ int handle_revision_arg(const char *arg, struct rev_info *revs, int flags, int cant_be_filename) { + unsigned mode; char *dotdot; struct object *object; unsigned char sha1[20]; @@ -796,12 +802,12 @@ int handle_revision_arg(const char *arg, struct rev_info *revs, local_flags = UNINTERESTING; arg++; } - if (get_sha1(arg, sha1)) + if (get_sha1_with_mode(arg, sha1, &mode)) return -1; if (!cant_be_filename) verify_non_filename(revs->prefix, arg); object = get_reference(revs, arg, sha1, flags ^ local_flags); - add_pending_object(revs, object, arg); + add_pending_object_with_mode(revs, object, arg, mode); return 0; } @@ -1177,10 +1183,11 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch if (def && !revs->pending.nr) { unsigned char sha1[20]; struct object *object; - if (get_sha1(def, sha1)) + unsigned mode; + if (get_sha1_with_mode(def, sha1, &mode)) die("bad default revision '%s'", def); object = get_reference(revs, def, sha1, 0); - add_pending_object(revs, object, def); + add_pending_object_with_mode(revs, object, def, mode); } if (revs->topo_order) diff --git a/revision.h b/revision.h index 8a02618428..5b41e2da20 100644 --- a/revision.h +++ b/revision.h @@ -131,5 +131,6 @@ extern void add_object(struct object *obj, const char *name); extern void add_pending_object(struct rev_info *revs, struct object *obj, const char *name); +extern void add_pending_object_with_mode(struct rev_info *revs, struct object *obj, const char *name, unsigned mode); #endif diff --git a/sha1_name.c b/sha1_name.c index b0b12bbe9d..55f25a2d3b 100644 --- a/sha1_name.c +++ b/sha1_name.c @@ -643,11 +643,17 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1) */ int get_sha1(const char *name, unsigned char *sha1) { - int ret, bracket_depth; unsigned unused; + return get_sha1_with_mode(name, sha1, &unused); +} + +int get_sha1_with_mode(const char *name, unsigned char *sha1, unsigned *mode) +{ + int ret, bracket_depth; int namelen = strlen(name); const char *cp; + *mode = S_IFINVALID; prepare_alt_odb(); ret = get_sha1_1(name, namelen, sha1); if (!ret) @@ -685,6 +691,7 @@ int get_sha1(const char *name, unsigned char *sha1) break; if (ce_stage(ce) == stage) { hashcpy(sha1, ce->sha1); + *mode = ntohl(ce->ce_mode); return 0; } pos++; @@ -703,7 +710,7 @@ int get_sha1(const char *name, unsigned char *sha1) unsigned char tree_sha1[20]; if (!get_sha1_1(name, cp-name, tree_sha1)) return get_tree_entry(tree_sha1, cp+1, sha1, - &unused); + mode); } return ret; } |