From f01cc14c3c70cfd820114505d2ddc153c28f6f89 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 2 Jul 2012 10:19:35 -0700 Subject: sha1_name.c: hide get_sha1_with_context_1() ugliness There is no outside caller that cares about the "only-to-die" ugliness. Signed-off-by: Junio C Hamano --- cache.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 10afd71d4..9ee470ce1 100644 --- a/cache.h +++ b/cache.h @@ -817,11 +817,7 @@ static inline int get_sha1_with_mode(const char *str, unsigned char *sha1, unsig { return get_sha1_with_mode_1(str, sha1, mode, 0, NULL); } -extern int get_sha1_with_context_1(const char *name, unsigned char *sha1, struct object_context *orc, int only_to_die, const char *prefix); -static inline int get_sha1_with_context(const char *str, unsigned char *sha1, struct object_context *orc) -{ - return get_sha1_with_context_1(str, sha1, orc, 0, NULL); -} +extern int get_sha1_with_context(const char *str, unsigned char *sha1, struct object_context *orc); /* * Try to read a SHA1 in hexadecimal format from the 40 characters -- cgit v1.2.1 From 8c135ea260a84ef71899c8bd23bb39425288f9fe Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 2 Jul 2012 11:01:25 -0700 Subject: sha1_name.c: get rid of get_sha1_with_mode_1() The only external caller is setup.c that tries to give a nicer error message when an object name is misspelt (e.g. "HEAD:cashe.h"). Retire it and give the caller a dedicated and more intuitive API function maybe_die_on_misspelt_object_name(). Signed-off-by: Junio C Hamano --- cache.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 9ee470ce1..beafa5b0c 100644 --- a/cache.h +++ b/cache.h @@ -812,11 +812,8 @@ struct object_context { }; extern int get_sha1(const char *str, unsigned char *sha1); -extern int get_sha1_with_mode_1(const char *str, unsigned char *sha1, unsigned *mode, int only_to_die, const char *prefix); -static inline int get_sha1_with_mode(const char *str, unsigned char *sha1, unsigned *mode) -{ - return get_sha1_with_mode_1(str, sha1, mode, 0, NULL); -} +extern int get_sha1_with_mode(const char *str, unsigned char *sha1, unsigned *mode); +extern void maybe_die_on_misspelt_object_name(const char *name, const char *prefix); extern int get_sha1_with_context(const char *str, unsigned char *sha1, struct object_context *orc); /* -- cgit v1.2.1 From 249c8f4a164c8502f8274c505a48b9c686f458d0 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 2 Jul 2012 12:56:44 -0700 Subject: sha1_name.c: get rid of get_sha1_with_mode() There are only two callers, and they will benefit from being able to pass disambiguation hints to underlying get_sha1_with_context() API once it happens. Signed-off-by: Junio C Hamano --- cache.h | 1 - 1 file changed, 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index beafa5b0c..2aa9fb6b2 100644 --- a/cache.h +++ b/cache.h @@ -812,7 +812,6 @@ struct object_context { }; 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 void maybe_die_on_misspelt_object_name(const char *name, const char *prefix); extern int get_sha1_with_context(const char *str, unsigned char *sha1, struct object_context *orc); -- cgit v1.2.1 From 37c00e5590605c9d3ba76b6c9d7a94ac0356f703 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 18 Jun 2012 11:32:03 -0700 Subject: sha1_name.c: allow get_short_sha1() to take other flags Instead of a separate "int quietly" argument, make it take "unsigned flags" so that we can pass other options to it. The bit assignment of this flag word is exposed in cache.h because the mechanism will be exposed to callers of the higher layer in later commits in this series. Signed-off-by: Junio C Hamano --- cache.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 2aa9fb6b2..1bafa45a7 100644 --- a/cache.h +++ b/cache.h @@ -811,6 +811,8 @@ struct object_context { unsigned mode; }; +#define GET_SHA1_QUIETLY 01 + extern int get_sha1(const char *str, unsigned char *sha1); extern void maybe_die_on_misspelt_object_name(const char *name, const char *prefix); extern int get_sha1_with_context(const char *str, unsigned char *sha1, struct object_context *orc); -- cgit v1.2.1 From aa1dec9ef6ff184792520eb4539af1555c01604c Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 20 Jun 2012 23:03:09 -0700 Subject: sha1_name.c: teach get_short_sha1() a commit-only option When the caller knows that the parameter is meant to name a commit, e.g. "56789a" in describe name "v1.2.3-4-g56789a", pass that as a hint so that lower level can use it to disambiguate objects when there is only one commit whose name begins with 56789a even if there are objects of other types whose names share the same prefix. Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 1bafa45a7..2d91dbd95 100644 --- a/cache.h +++ b/cache.h @@ -812,6 +812,7 @@ struct object_context { }; #define GET_SHA1_QUIETLY 01 +#define GET_SHA1_COMMIT 02 extern int get_sha1(const char *str, unsigned char *sha1); extern void maybe_die_on_misspelt_object_name(const char *name, const char *prefix); -- cgit v1.2.1 From e2643617d75e53e5a69278f8d7382553d1c14cf0 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 2 Jul 2012 10:00:40 -0700 Subject: sha1_name.c: many short names can only be committish We know that the token "$name" that appear in "$name^{commit}", "$name^4", "$name~4" etc. can only name a committish (either a commit or a tag that peels to a commit). Teach get_short_sha1() to take advantage of that knowledge when disambiguating an abbreviated SHA-1 given as an object name. Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 2d91dbd95..1508fdb77 100644 --- a/cache.h +++ b/cache.h @@ -813,6 +813,7 @@ struct object_context { #define GET_SHA1_QUIETLY 01 #define GET_SHA1_COMMIT 02 +#define GET_SHA1_COMMITTISH 04 extern int get_sha1(const char *str, unsigned char *sha1); extern void maybe_die_on_misspelt_object_name(const char *name, const char *prefix); -- cgit v1.2.1 From 33bd598c3902c40c5a10a68aeaa3004484239258 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 2 Jul 2012 10:32:11 -0700 Subject: sha1_name.c: teach lookup context to get_sha1_with_context() The function takes user input string and returns the object name (binary SHA-1) with mode bits and path when the object was looked up in a tree. Additionally give hints to help disambiguation of abbreviated object names when the caller knows what it is looking for. Signed-off-by: Junio C Hamano --- cache.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 1508fdb77..e1fa63b31 100644 --- a/cache.h +++ b/cache.h @@ -814,10 +814,11 @@ struct object_context { #define GET_SHA1_QUIETLY 01 #define GET_SHA1_COMMIT 02 #define GET_SHA1_COMMITTISH 04 +#define GET_SHA1_ONLY_TO_DIE 04000 extern int get_sha1(const char *str, unsigned char *sha1); extern void maybe_die_on_misspelt_object_name(const char *name, const char *prefix); -extern int get_sha1_with_context(const char *str, unsigned char *sha1, struct object_context *orc); +extern int get_sha1_with_context(const char *str, unsigned flags, unsigned char *sha1, struct object_context *orc); /* * Try to read a SHA1 in hexadecimal format from the 40 characters -- cgit v1.2.1 From cd74e4733db3e2353077bdc7021caa70bed2a483 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 2 Jul 2012 12:04:52 -0700 Subject: sha1_name.c: introduce get_sha1_committish() Many callers know that the user meant to name a committish by syntactical positions where the object name appears. Calling this function allows the machinery to disambiguate shorter-than-unique abbreviated object names between committish and others. Note that this does NOT error out when the named object is not a committish. It is merely to give a hint to the disambiguation machinery. Signed-off-by: Junio C Hamano --- cache.h | 1 + 1 file changed, 1 insertion(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index e1fa63b31..e947b48d0 100644 --- a/cache.h +++ b/cache.h @@ -817,6 +817,7 @@ struct object_context { #define GET_SHA1_ONLY_TO_DIE 04000 extern int get_sha1(const char *str, unsigned char *sha1); +extern int get_sha1_committish(const char *str, unsigned char *sha1); extern void maybe_die_on_misspelt_object_name(const char *name, const char *prefix); extern int get_sha1_with_context(const char *str, unsigned flags, unsigned char *sha1, struct object_context *orc); -- cgit v1.2.1 From daba53aeaf6565b4bbdd6783c659480453ec3c5e Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 2 Jul 2012 23:35:05 -0700 Subject: sha1_name.c: add support for disambiguating other types This teaches the revision parser that in "$name:$path" (used for a blob object name), "$name" must be a tree-ish. There are many more places where we know what types of objects are called for. This patch adds support for "commit", "treeish", "tree", and "blob", which could be used in the following contexts: - "git apply --build-fake-ancestor" reads the "index" lines from the patch; they must name blob objects (not even "blob-ish"); - "git commit-tree" reads a tree object name (not "tree-ish"), and zero or more commit object names (not "committish"); - "git reset $rev" wants a committish; "git reset $rev -- $path" wants a treeish. They will come in later patches in the series. Signed-off-by: Junio C Hamano --- cache.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index e947b48d0..c8d6406bc 100644 --- a/cache.h +++ b/cache.h @@ -811,13 +811,20 @@ struct object_context { unsigned mode; }; -#define GET_SHA1_QUIETLY 01 -#define GET_SHA1_COMMIT 02 -#define GET_SHA1_COMMITTISH 04 +#define GET_SHA1_QUIETLY 01 +#define GET_SHA1_COMMIT 02 +#define GET_SHA1_COMMITTISH 04 +#define GET_SHA1_TREE 010 +#define GET_SHA1_TREEISH 020 +#define GET_SHA1_BLOB 040 #define GET_SHA1_ONLY_TO_DIE 04000 extern int get_sha1(const char *str, unsigned char *sha1); +extern int get_sha1_commit(const char *str, unsigned char *sha1); extern int get_sha1_committish(const char *str, unsigned char *sha1); +extern int get_sha1_tree(const char *str, unsigned char *sha1); +extern int get_sha1_treeish(const char *str, unsigned char *sha1); +extern int get_sha1_blob(const char *str, unsigned char *sha1); extern void maybe_die_on_misspelt_object_name(const char *name, const char *prefix); extern int get_sha1_with_context(const char *str, unsigned flags, unsigned char *sha1, struct object_context *orc); -- cgit v1.2.1 From 957d74062c1f0e92368aeda335e27d2d61f584f6 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 3 Jul 2012 14:21:59 -0700 Subject: rev-parse --disambiguate= The new option allows you to feed an ambiguous prefix and enumerate all the objects that share it as a prefix of their object names. Signed-off-by: Junio C Hamano --- cache.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'cache.h') diff --git a/cache.h b/cache.h index c8d6406bc..63388780a 100644 --- a/cache.h +++ b/cache.h @@ -828,6 +828,9 @@ extern int get_sha1_blob(const char *str, unsigned char *sha1); extern void maybe_die_on_misspelt_object_name(const char *name, const char *prefix); extern int get_sha1_with_context(const char *str, unsigned flags, unsigned char *sha1, struct object_context *orc); +typedef int each_abbrev_fn(const unsigned char *sha1, void *); +extern int for_each_abbrev(const char *prefix, each_abbrev_fn, void *); + /* * Try to read a SHA1 in hexadecimal format from the 40 characters * starting at hex. Write the 20-byte result to sha1 in binary form. -- cgit v1.2.1