From 40689ae1ef9a05503c75298ec50b194ca9d15522 Mon Sep 17 00:00:00 2001 From: Martin Koegler Date: Sun, 22 Apr 2007 18:43:56 +0200 Subject: Add S_IFINVALID mode S_IFINVALID is used to signal, that no mode information is available. Signed-off-by: Martin Koegler Signed-off-by: Junio C Hamano --- cache.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cache.h b/cache.h index 89aaf0022d..b1adbe7b6e 100644 --- a/cache.h +++ b/cache.h @@ -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. * -- cgit v1.2.1 From a0cd87a57044efa8aef39b476fd9240af57a1853 Mon Sep 17 00:00:00 2001 From: Martin Koegler Date: Mon, 23 Apr 2007 22:55:05 +0200 Subject: add get_sha1_with_mode get_sha1_with_mode basically behaves as get_sha1. It has an additional parameter for storing the mode of the object. If the mode can not be determined, it stores S_IFINVALID. Signed-off-by: Martin Koegler Signed-off-by: Junio C Hamano --- cache.h | 1 + sha1_name.c | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/cache.h b/cache.h index b1adbe7b6e..23e8f24d5c 100644 --- a/cache.h +++ b/cache.h @@ -342,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); 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; } -- cgit v1.2.1 From e5709a4a6809e45bf59b851debf24a813e1c6b58 Mon Sep 17 00:00:00 2001 From: Martin Koegler Date: Sun, 22 Apr 2007 18:43:58 +0200 Subject: add add_object_array_with_mode Each object in struct object_array is extended with the mode. If not specified, S_IFINVALID is used. An object with an mode value can be added with add_object_array_with_mode. Signed-off-by: Martin Koegler Signed-off-by: Junio C Hamano --- object.c | 6 ++++++ object.h | 2 ++ 2 files changed, 8 insertions(+) diff --git a/object.c b/object.c index 7bd3fec556..37d1363359 100644 --- a/object.c +++ b/object.c @@ -230,6 +230,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; @@ -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; } diff --git a/object.h b/object.h index 3e26a0e8b9..94f19eed86 100644 --- a/object.h +++ b/object.h @@ -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 */ -- cgit v1.2.1 From bb6c2fba4103948445304493b6211998a02810ce Mon Sep 17 00:00:00 2001 From: Martin Koegler Date: Sun, 22 Apr 2007 18:43:59 +0200 Subject: store mode in rev_list, if : syntax is used Signed-off-by: Martin Koegler Signed-off-by: Junio C Hamano --- revision.c | 17 ++++++++++++----- revision.h | 1 + 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/revision.c b/revision.c index ce70f48ce0..49bd29225b 100644 --- a/revision.c +++ b/revision.c @@ -115,10 +115,15 @@ 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 -- cgit v1.2.1 From 01618a3ab131548582f4e2371b9b5e7328f61e4a Mon Sep 17 00:00:00 2001 From: Martin Koegler Date: Sun, 22 Apr 2007 18:44:00 +0200 Subject: use mode of the tree in git-diff, if : syntax is used Signed-off-by: Martin Koegler Signed-off-by: Junio C Hamano --- builtin-diff.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/builtin-diff.c b/builtin-diff.c index 2ae60097b8..4ba4d18f87 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[] = @@ -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; -- cgit v1.2.1 From 43342941dd736fe06fe607a1594422cc8ba461a1 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 22 Apr 2007 23:56:22 -0700 Subject: Diff between two blobs should take mode changes into account now. Signed-off-by: Junio C Hamano --- builtin-diff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin-diff.c b/builtin-diff.c index 4ba4d18f87..7f367b6b9d 100644 --- a/builtin-diff.c +++ b/builtin-diff.c @@ -32,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) { -- cgit v1.2.1