[PATCH/RFC] Add [] as an alias for a reference to the empty tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Instead of specifying the SHA1 for the empty tree (i.e.,
4b825dc642cb6eb9a060e54bf8d69288fbee4904) one can now say [], e.g.,
'git diff [] v1.7.1' would give all the changes between the empty tree
and the tag v1.7.1.

The rationale for selecting [] as the alias for the empty tree was that
it looks empty, the brackets are not used for anything related to
references (AFAIK), they are not allowed in references according to
'man git-check-ref-format', and the syntax can easily be extended to
allow other types of references by adding information between the
brackets.

Signed-off-by: Peter Kjellerstedt <pkj@xxxxxxxx>
---
 sha1_name.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

This is in response to the discussion in [1]. I am not sure the use of
'[]' as an alias for the empty tree will be accepted, but I think having
an alias similar to this is much easier to implement than adding support
for a --root option to all commands which can take a <tree-ish>...

Since this is mostly an RFC I have not included any new tests (though
the existsing once still pass after this change).

[1] http://thread.gmane.org/gmane.comp.version-control.git/146468/focus=146484

diff --git a/sha1_name.c b/sha1_name.c
index bf92417..ba58eab 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -347,6 +347,9 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
 	int refs_found = 0;
 	int at, reflog_len;
 
+	if (len == 2 && str[0] == '[' && str[1] == ']')
+		return get_sha1_hex(EMPTY_TREE_SHA1_HEX, sha1);
+
 	if (len == 40 && !get_sha1_hex(str, sha1))
 		return 0;
 
-- 
1.7.0.1

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]