From d50125085a6c4775a77d45a6d294d723f6de8869 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 25 Jan 2006 01:35:38 -0800 Subject: rev-parse: --abbrev option. The new option behaves just like --verify, but outputs an abbreviated object name that is unique within the repository. Signed-off-by: Junio C Hamano --- rev-parse.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'rev-parse.c') diff --git a/rev-parse.c b/rev-parse.c index 7abad35de9..42969a6fc1 100644 --- a/rev-parse.c +++ b/rev-parse.c @@ -20,6 +20,7 @@ static char *def = NULL; #define REVERSED 1 static int show_type = NORMAL; static int symbolic = 0; +static int abbrev = 0; static int output_sq = 0; static int revs_count = 0; @@ -95,6 +96,8 @@ static void show_rev(int type, const unsigned char *sha1, const char *name) putchar('^'); if (symbolic && name) show(name); + else if (abbrev) + show(find_unique_abbrev(sha1, abbrev)); else show(sha1_to_hex(sha1)); } @@ -196,6 +199,17 @@ int main(int argc, char **argv) verify = 1; continue; } + if (!strcmp(arg, "--abbrev") || + !strncmp(arg, "--abbrev=", 9)) { + filter &= ~(DO_FLAGS|DO_NOREV); + verify = 1; + abbrev = DEFAULT_ABBREV; + if (arg[8] == '=') + abbrev = strtoul(arg + 9, NULL, 10); + if (abbrev < 0 || 40 <= abbrev) + abbrev = DEFAULT_ABBREV; + continue; + } if (!strcmp(arg, "--sq")) { output_sq = 1; continue; -- cgit v1.2.3 From 1dc4fb84b5914621cf59b6b508ad7c9c86c61fa4 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 26 Jan 2006 00:48:19 -0800 Subject: rev-parse --abbrev: do not try abbrev shorter than minimum. We do not allow abbreviation shorter than 4 letters in other parts of the system so do not attempt to generate such. Noticed by Uwe Zeisberger. Signed-off-by: Junio C Hamano --- rev-parse.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'rev-parse.c') diff --git a/rev-parse.c b/rev-parse.c index 42969a6fc1..8bf316eedd 100644 --- a/rev-parse.c +++ b/rev-parse.c @@ -206,8 +206,10 @@ int main(int argc, char **argv) abbrev = DEFAULT_ABBREV; if (arg[8] == '=') abbrev = strtoul(arg + 9, NULL, 10); - if (abbrev < 0 || 40 <= abbrev) - abbrev = DEFAULT_ABBREV; + if (abbrev < MINIMUM_ABBREV) + abbrev = MINIMUM_ABBREV; + else if (40 <= abbrev) + abbrev = 40; continue; } if (!strcmp(arg, "--sq")) { -- cgit v1.2.3 From 62a604ba1c8f1ebcb135039ab04c9ca6c96b67f4 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 26 Jan 2006 17:02:07 -0800 Subject: Rename rev-parse --abbrev to --short. The usage of rev-parse to serve as a flag/option parser for git-whatchanged and other commands have serious limitation that the flags cannot be something that is supported by rev-parse itself, and it cannot worked around easily. Since this is rarely used "poor-man's describe", rename the option for now as an easier workaround. Signed-off-by: Junio C Hamano --- rev-parse.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'rev-parse.c') diff --git a/rev-parse.c b/rev-parse.c index 8bf316eedd..a1aa86398a 100644 --- a/rev-parse.c +++ b/rev-parse.c @@ -199,8 +199,8 @@ int main(int argc, char **argv) verify = 1; continue; } - if (!strcmp(arg, "--abbrev") || - !strncmp(arg, "--abbrev=", 9)) { + if (!strcmp(arg, "--short") || + !strncmp(arg, "--short=", 9)) { filter &= ~(DO_FLAGS|DO_NOREV); verify = 1; abbrev = DEFAULT_ABBREV; -- cgit v1.2.3 From b33aba518456bee97bde1fef4fe17ab6bf401bbe Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 26 Jan 2006 17:24:52 -0800 Subject: rev-parse: make "whatchanged -- git-fetch-script" work again. The latest update to avoid misspelled revs interfered when we were not interested in parsing non flags or arguments not meant for rev-list. This makes these two forms work again: git whatchanged -- git-fetch-script We could enable "!def" in the part this change touches to make the above work without '--', but then it would cause misspelled v2.6.14..v2.6.16 to be given to diff-tree and defeats the whole point of the previous fix. Signed-off-by: Junio C Hamano --- rev-parse.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'rev-parse.c') diff --git a/rev-parse.c b/rev-parse.c index 7abad35de9..9567b0f5b9 100644 --- a/rev-parse.c +++ b/rev-parse.c @@ -294,7 +294,9 @@ int main(int argc, char **argv) } if (verify) die("Needed a single revision"); - if (lstat(arg, &st) < 0) + if ((filter & DO_REVS) && + (filter & DO_NONFLAGS) && /* !def && */ + lstat(arg, &st) < 0) die("'%s': %s", arg, strerror(errno)); as_is = 1; show_file(arg); -- cgit v1.2.3