{"thread":{"id":"3591","subject":"[PATCH] ls-tree: add --abbrev[=<n>] option","startedAt":"2006-03-07T13:52:02Z","lastAt":"2006-03-07T19:59:17Z","messageCount":4,"participants":["Eric Wong","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"17295","messageId":"20060307135202.GA17891@localdomain","threadId":"3591","inReplyTo":null,"subject":"[PATCH] ls-tree: add --abbrev[=<n>] option","fromName":"Eric Wong","fromEmail":"normalperson@yhbt.net","sentAt":"2006-03-07T13:52:02Z","receivedAt":"2006-03-07T13:52:02Z","isPatch":true,"sender":{"key":"e@80x24.org","avatar":null},"body":"Signed-off-by: Eric Wong <normalperson@yhbt.net>\n\n---\n\n Documentation/git-ls-tree.txt |    9 ++++++++-\n ls-tree.c                     |   19 +++++++++++++++++--\n 2 files changed, 25 insertions(+), 3 deletions(-)\n\n24fa229085e3090eea54adbb18e906fed8a63a40\ndiff --git a/Documentation/git-ls-tree.txt b/Documentation/git-ls-tree.txt\nindex b92a8b2..b30b766 100644\n--- a/Documentation/git-ls-tree.txt\n+++ b/Documentation/git-ls-tree.txt\n@@ -8,7 +8,9 @@ git-ls-tree - Lists the contents of a tr\n \n SYNOPSIS\n --------\n-'git-ls-tree' [-d] [-r] [-t] [-z] [--name-only] [--name-status] <tree-ish> [paths...]\n+'git-ls-tree' [-d] [-r] [-t] [-z]\n+\t[--name-only] [--name-status] [--full-name] [--abbrev=[<n>]]\n+\t<tree-ish> [paths...]\n \n DESCRIPTION\n -----------\n@@ -40,6 +42,11 @@ OPTIONS\n --name-status::\n \tList only filenames (instead of the \"long\" output), one per line.\n \n+--abbrev[=<n>]::\n+\tInstead of showing the full 40-byte hexadecimal object\n+\tlines, show only handful hexdigits prefix.\n+\tNon default number of digits can be specified with --abbrev=<n>.\n+\n paths::\n \tWhen paths are given, show them (note that this isn't really raw\n \tpathnames, but rather a list of patterns to match).  Otherwise\ndiff --git a/ls-tree.c b/ls-tree.c\nindex d005643..97f09bd 100644\n--- a/ls-tree.c\n+++ b/ls-tree.c\n@@ -13,13 +13,14 @@ static int line_termination = '\\n';\n #define LS_TREE_ONLY 2\n #define LS_SHOW_TREES 4\n #define LS_NAME_ONLY 8\n+static int abbrev = 0;\n static int ls_options = 0;\n const char **pathspec;\n static int chomp_prefix = 0;\n static const char *prefix;\n \n static const char ls_tree_usage[] =\n-\t\"git-ls-tree [-d] [-r] [-t] [-z] [--name-only] [--name-status] [--full-name] <tree-ish> [path...]\";\n+\t\"git-ls-tree [-d] [-r] [-t] [-z] [--name-only] [--name-status] [--full-name] [--abbrev[=<n>]] <tree-ish> [path...]\";\n \n static int show_recursive(const char *base, int baselen, const char *pathname)\n {\n@@ -73,7 +74,9 @@ static int show_tree(unsigned char *sha1\n \t\treturn 0;\n \n \tif (!(ls_options & LS_NAME_ONLY))\n-\t\tprintf(\"%06o %s %s\\t\", mode, type, sha1_to_hex(sha1));\n+\t\tprintf(\"%06o %s %s\\t\", mode, type,\n+\t\t\t\tabbrev ? find_unique_abbrev(sha1,abbrev)\n+\t\t\t\t\t: sha1_to_hex(sha1));\n \twrite_name_quoted(base + chomp_prefix, baselen - chomp_prefix,\n \t\t\t  pathname,\n \t\t\t  line_termination, stdout);\n@@ -113,6 +116,18 @@ int main(int argc, const char **argv)\n \t\t\t\tchomp_prefix = 0;\n \t\t\t\tbreak;\n \t\t\t}\n+\t\t\tif (!strncmp(argv[1]+2, \"abbrev=\",7)) {\n+\t\t\t\tabbrev = strtoul(argv[1]+9, NULL, 10);\n+\t\t\t\tif (abbrev && abbrev < MINIMUM_ABBREV)\n+\t\t\t\t\tabbrev = MINIMUM_ABBREV;\n+\t\t\t\telse if (abbrev > 40)\n+\t\t\t\t\tabbrev = 40;\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t\tif (!strcmp(argv[1]+2, \"abbrev\")) {\n+\t\t\t\tabbrev = DEFAULT_ABBREV;\n+\t\t\t\tbreak;\n+\t\t\t}\n \t\t\t/* otherwise fallthru */\n \t\tdefault:\n \t\t\tusage(ls_tree_usage);\n-- \n1.2.4.g76f4\n"},{"id":"17303","messageId":"7vzmk2jfzr.fsf@assigned-by-dhcp.cox.net","threadId":"3591","inReplyTo":"20060307135202.GA17891@localdomain","subject":"Re: [PATCH] ls-tree: add --abbrev[=<n>] option","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-03-07T17:56:24Z","receivedAt":"2006-03-07T17:56:24Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Output from ls-tree and ls-files -s are primarily for script\nconsumption.  diff-raw output which already has abbrev is also\nprimarily for scripts, but we have an excuse there that human\neyes can spot differences easier in abbreviated form and two\nvalues on the same row being different is the only information\nwe are conveying in \"git whatchanged\" default output, and not\nabbreviating the object names makes pathnames pushed to far\nright of the display which will be chopped by \"less -S\".\n\nSo I am not quite sure if I should take this, and a subsequent\none you would probably send for ls-files ;-).\n\nCare to point out a use case I might have missed that this is\nuseful?  I've never done ls-tree to be read by _me_ (not by\nscript) unless I am debugging ls-tree itself.\n\nAlthough I doubt this adds much practical value, this might make\nthings consistent, which by itself might be a reason to do this,\nthough.\n"},{"id":"17308","messageId":"20060307195826.GA26870@localdomain","threadId":"3591","inReplyTo":"7vzmk2jfzr.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] ls-tree: add --abbrev[=<n>] option","fromName":"Eric Wong","fromEmail":"normalperson@yhbt.net","sentAt":"2006-03-07T19:58:26Z","receivedAt":"2006-03-07T19:58:26Z","isPatch":true,"sender":{"key":"e@80x24.org","avatar":null},"body":"Junio C Hamano <junkio@cox.net> wrote:\n> Output from ls-tree and ls-files -s are primarily for script\n> consumption.  diff-raw output which already has abbrev is also\n> primarily for scripts, but we have an excuse there that human\n> eyes can spot differences easier in abbreviated form and two\n> values on the same row being different is the only information\n> we are conveying in \"git whatchanged\" default output, and not\n> abbreviating the object names makes pathnames pushed to far\n> right of the display which will be chopped by \"less -S\".\n> \n> So I am not quite sure if I should take this, and a subsequent\n> one you would probably send for ls-files ;-).\n\nI've never used ls-files with -s, but it's a simple patch on its way :>\n\n> Care to point out a use case I might have missed that this is\n> useful?  I've never done ls-tree to be read by _me_ (not by\n> script) unless I am debugging ls-tree itself.\n\nI'm a weirdo and I use vim as a repository browser:\n(ref: http://www.gelato.unsw.edu.au/archives/git/0511/13088.html ,\nI've since renamed my 'git-show' script to 'git-cat-any').\n\nMy usual buffer width is 80 columns.  So when I want to see a file from\na certain tree that's not checked out: I'll run git-ls-tree -r <tree>\nand output it to my vim buffer, find the corresponding sha1 for the\nfile, and hit my ',G' macro with my cursor over the blob sha1 to display\nits contents.  Abbreviating the sha1 is very useful for seeing longer\nfile paths on an 80 column buffer.\n\n-- \nEric Wong\n"},{"id":"17309","messageId":"20060307195917.GA29042@localdomain","threadId":"3591","inReplyTo":"20060307195826.GA26870@localdomain","subject":"[PATCH] ls-files: add --abbrev[=<n>] option","fromName":"Eric Wong","fromEmail":"normalperson@yhbt.net","sentAt":"2006-03-07T19:59:17Z","receivedAt":"2006-03-07T19:59:17Z","isPatch":true,"sender":{"key":"e@80x24.org","avatar":null},"body":"Signed-off-by: Eric Wong <normalperson@yhbt.net>\n\n---\n\n Documentation/git-ls-files.txt |    7 ++++++-\n ls-files.c                     |   19 +++++++++++++++++--\n 2 files changed, 23 insertions(+), 3 deletions(-)\n\n1aa70bab7a4af7b79db3c86b9f88884c1dfad6ee\ndiff --git a/Documentation/git-ls-files.txt b/Documentation/git-ls-files.txt\nindex e813f84..68d32a8 100644\n--- a/Documentation/git-ls-files.txt\n+++ b/Documentation/git-ls-files.txt\n@@ -16,7 +16,7 @@ SYNOPSIS\n \t\t[-X <file>|--exclude-from=<file>]\n \t\t[--exclude-per-directory=<file>] \n \t\t[--error-unmatch]\n-\t\t[--full-name] [--] [<file>]\\*\n+\t\t[--full-name] [--abbrev] [--] [<file>]\\*\n \n DESCRIPTION\n -----------\n@@ -98,6 +98,11 @@ OPTIONS\n \toption forces paths to be output relative to the project\n \ttop directory.\n \n+--abbrev[=<n>]::\n+\tInstead of showing the full 40-byte hexadecimal object\n+\tlines, show only handful hexdigits prefix.\n+\tNon default number of digits can be specified with --abbrev=<n>.\n+\n --::\n \tDo not interpret any more arguments as options.\n \ndiff --git a/ls-files.c b/ls-files.c\nindex df25c8c..585f6a7 100644\n--- a/ls-files.c\n+++ b/ls-files.c\n@@ -11,6 +11,7 @@\n #include \"cache.h\"\n #include \"quote.h\"\n \n+static int abbrev = 0;\n static int show_deleted = 0;\n static int show_cached = 0;\n static int show_others = 0;\n@@ -488,7 +489,8 @@ static void show_ce_entry(const char *ta\n \t\tprintf(\"%s%06o %s %d\\t\",\n \t\t       tag,\n \t\t       ntohl(ce->ce_mode),\n-\t\t       sha1_to_hex(ce->sha1),\n+\t\t       abbrev ? find_unique_abbrev(ce->sha1,abbrev)\n+\t\t\t\t: sha1_to_hex(ce->sha1),\n \t\t       ce_stage(ce));\n \t\twrite_name_quoted(\"\", 0, ce->name + offset,\n \t\t\t\t  line_terminator, stdout);\n@@ -629,7 +631,8 @@ static void verify_pathspec(void)\n static const char ls_files_usage[] =\n \t\"git-ls-files [-z] [-t] [-v] (--[cached|deleted|others|stage|unmerged|killed|modified])* \"\n \t\"[ --ignored ] [--exclude=<pattern>] [--exclude-from=<file>] \"\n-\t\"[ --exclude-per-directory=<filename> ] [--full-name] [--] [<file>]*\";\n+\t\"[ --exclude-per-directory=<filename> ] [--full-name] [--abbrev] \"\n+\t\"[--] [<file>]*\";\n \n int main(int argc, const char **argv)\n {\n@@ -736,6 +739,18 @@ int main(int argc, const char **argv)\n \t\t\terror_unmatch = 1;\n \t\t\tcontinue;\n \t\t}\n+\t\tif (!strncmp(arg, \"--abbrev=\", 9)) {\n+\t\t\tabbrev = strtoul(arg+9, NULL, 10);\n+\t\t\tif (abbrev && abbrev < MINIMUM_ABBREV)\n+\t\t\t\tabbrev = MINIMUM_ABBREV;\n+\t\t\telse if (abbrev > 40)\n+\t\t\t\tabbrev = 40;\n+\t\t\tcontinue;\n+\t\t}\n+\t\tif (!strcmp(arg, \"--abbrev\")) {\n+\t\t\tabbrev = DEFAULT_ABBREV;\n+\t\t\tcontinue;\n+\t\t}\n \t\tif (*arg == '-')\n \t\t\tusage(ls_files_usage);\n \t\tbreak;\n-- \n1.2.4.gc279\n"}]}