{"thread":{"id":"4127","subject":"[PATCH] Add \"--branches\" and \"--tags\" options to git-rev-parse.","startedAt":"2006-05-13T15:13:32Z","lastAt":"2006-05-15T20:11:17Z","messageCount":6,"participants":["Sean Estabrooks","Junio C Hamano","Sean","Jakub Narebski"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"19883","messageId":"BAYC1-PASMTP0299DC98A51B55188BDF96AEAD0@CEZ.ICE","threadId":"4127","inReplyTo":null,"subject":"[PATCH] Add \"--branches\" and \"--tags\" options to git-rev-parse.","fromName":"Sean Estabrooks","fromEmail":"seanlkml@sympatico.ca","sentAt":"2006-05-13T15:13:32Z","receivedAt":"2006-05-13T15:13:32Z","isPatch":true,"sender":{"key":"seanlkml@sympatico.ca","avatar":"https://gravatar.com/avatar/f92923f54fc08c401fc59b71829d4b89e9b8087fbba45ff87c82e6a83aee02ae?d=mp&s=160"},"body":"\"git branch\" uses rev-parse and can become slow when there are many\ntags.  Use the new \"--branches\" option of rev-parse to speed things up.\n\nSigned-off-by: Sean Estabrooks <seanlkml@sympatico.ca>\n\n---\n\n Documentation/git-rev-parse.txt |    6 ++++++\n git-branch.sh                   |    3 +--\n refs.c                          |   18 ++++++++++++++----\n refs.h                          |    2 ++\n rev-parse.c                     |    8 ++++++++\n 5 files changed, 31 insertions(+), 6 deletions(-)\n\n7898e1e58b18e992e3d90516fc9e6f3476a385ed\ndiff --git a/Documentation/git-rev-parse.txt b/Documentation/git-rev-parse.txt\nindex 8b95df0..c1da2bf 100644\n--- a/Documentation/git-rev-parse.txt\n+++ b/Documentation/git-rev-parse.txt\n@@ -67,6 +67,12 @@ OPTIONS\n --all::\n \tShow all refs found in `$GIT_DIR/refs`.\n \n+--branches::\n+\tShow branch refs found in `$GIT_DIR/refs/heads`.\n+\n+--tags::\n+\tShow tag refs found in `$GIT_DIR/refs/tags`.\n+\n --show-prefix::\n \tWhen the command is invoked from a subdirectory, show the\n \tpath of the current directory relative to the top-level\ndiff --git a/git-branch.sh b/git-branch.sh\nindex ebcc898..134e68c 100755\n--- a/git-branch.sh\n+++ b/git-branch.sh\n@@ -82,8 +82,7 @@ done\n \n case \"$#\" in\n 0)\n-\tgit-rev-parse --symbolic --all |\n-\tsed -ne 's|^refs/heads/||p' |\n+\tgit-rev-parse --symbolic --branches |\n \tsort |\n \twhile read ref\n \tdo\ndiff --git a/refs.c b/refs.c\nindex 275b914..9c29a73 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -114,7 +114,7 @@ int read_ref(const char *filename, unsig\n \treturn -1;\n }\n \n-static int do_for_each_ref(const char *base, int (*fn)(const char *path, const unsigned char *sha1))\n+static int do_for_each_ref(const char *base, int (*fn)(const char *path, const unsigned char *sha1), int trim)\n {\n \tint retval = 0;\n \tDIR *dir = opendir(git_path(\"%s\", base));\n@@ -146,7 +146,7 @@ static int do_for_each_ref(const char *b\n \t\t\tif (stat(git_path(\"%s\", path), &st) < 0)\n \t\t\t\tcontinue;\n \t\t\tif (S_ISDIR(st.st_mode)) {\n-\t\t\t\tretval = do_for_each_ref(path, fn);\n+\t\t\t\tretval = do_for_each_ref(path, fn, trim);\n \t\t\t\tif (retval)\n \t\t\t\t\tbreak;\n \t\t\t\tcontinue;\n@@ -160,7 +160,7 @@ static int do_for_each_ref(const char *b\n \t\t\t\t      \"commit object!\", path);\n \t\t\t\tcontinue;\n \t\t\t}\n-\t\t\tretval = fn(path, sha1);\n+\t\t\tretval = fn(path + trim, sha1);\n \t\t\tif (retval)\n \t\t\t\tbreak;\n \t\t}\n@@ -180,7 +180,17 @@ int head_ref(int (*fn)(const char *path,\n \n int for_each_ref(int (*fn)(const char *path, const unsigned char *sha1))\n {\n-\treturn do_for_each_ref(\"refs\", fn);\n+\treturn do_for_each_ref(\"refs\", fn, 0);\n+}\n+\n+int for_each_tag(int (*fn)(const char *path, const unsigned char *sha1))\n+{\n+\treturn do_for_each_ref(\"refs/tags\", fn, 10);\n+}\n+\n+int for_each_branch(int (*fn)(const char *path, const unsigned char *sha1))\n+{\n+\treturn do_for_each_ref(\"refs/heads\", fn, 11);\n }\n \n static char *ref_file_name(const char *ref)\ndiff --git a/refs.h b/refs.h\nindex 2625596..f270b62 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -7,6 +7,8 @@ #define REFS_H\n  */\n extern int head_ref(int (*fn)(const char *path, const unsigned char *sha1));\n extern int for_each_ref(int (*fn)(const char *path, const unsigned char *sha1));\n+extern int for_each_tag(int (*fn)(const char *path, const unsigned char *sha1));\n+extern int for_each_branch(int (*fn)(const char *path, const unsigned char *sha1));\n \n /** Reads the refs file specified into sha1 **/\n extern int get_ref_sha1(const char *ref, unsigned char *sha1);\ndiff --git a/rev-parse.c b/rev-parse.c\nindex 62e16af..4eb38de 100644\n--- a/rev-parse.c\n+++ b/rev-parse.c\n@@ -255,6 +255,14 @@ int main(int argc, char **argv)\n \t\t\t\tfor_each_ref(show_reference);\n \t\t\t\tcontinue;\n \t\t\t}\n+\t\t\tif (!strcmp(arg, \"--branches\")) {\n+\t\t\t\tfor_each_branch(show_reference);\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\t\t\tif (!strcmp(arg, \"--tags\")) {\n+\t\t\t\tfor_each_tag(show_reference);\n+\t\t\t\tcontinue;\n+\t\t\t}\n \t\t\tif (!strcmp(arg, \"--show-prefix\")) {\n \t\t\t\tif (prefix)\n \t\t\t\t\tputs(prefix);\n-- \n1.3.2.g419f\n"},{"id":"19887","messageId":"7vd5ehu8og.fsf@assigned-by-dhcp.cox.net","threadId":"4127","inReplyTo":"BAYC1-PASMTP0299DC98A51B55188BDF96AEAD0@CEZ.ICE","subject":"Re: [PATCH] Add \"--branches\" and \"--tags\" options to git-rev-parse.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-05-13T17:38:23Z","receivedAt":"2006-05-13T17:38:23Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Sean Estabrooks <seanlkml@sympatico.ca> writes:\n\n> \"git branch\" uses rev-parse and can become slow when there are many\n> tags.  Use the new \"--branches\" option of rev-parse to speed things up.\n\nMakes sense perhaps.\n\nI understand you added --tags for completeness.  Probably it\nwould make sense to add --remotes if you are shooting for that.\n"},{"id":"19899","messageId":"BAYC1-PASMTP043948149786B7EE06DED3AEA20@CEZ.ICE","threadId":"4127","inReplyTo":"7vd5ehu8og.fsf@assigned-by-dhcp.cox.net","subject":"[PATCH] Add \"--branches\", \"--tags\" and \"--remotes\" options to git-rev-parse.","fromName":"Sean","fromEmail":"seanlkml@sympatico.ca","sentAt":"2006-05-14T01:43:00Z","receivedAt":"2006-05-14T01:43:00Z","isPatch":true,"sender":{"key":"seanlkml@sympatico.ca","avatar":"https://gravatar.com/avatar/f92923f54fc08c401fc59b71829d4b89e9b8087fbba45ff87c82e6a83aee02ae?d=mp&s=160"},"body":"\n\"git branch\" uses \"rev-parse --all\" and becomes much too slow when\nthere are many tags (it scans all refs).  Use the new \"--branches\"\noption of rev-parse to speed things up.\n\nSigned-off-by: Sean Estabrooks <seanlkml@sympatico.ca>\n\n---\n\nOn Sat, 13 May 2006 10:38:23 -0700\nJunio C Hamano <junkio@cox.net> wrote:\n\n> Makes sense perhaps.\n> \n> I understand you added --tags for completeness.  Probably it\n> would make sense to add --remotes if you are shooting for that.\n> \n\nHi Junio,\n\nHere's an updated patch with --remotes as you asked.  I appened _ref to the\nnew functions to make it clear that for_each_remote didn't have anything to\ndo with remote files.  Also updated the \"is_rev_argument\" function which was\nmissed first time around.\n\nOn a related note, would it be okay to change \"git tag -l\" to produce a list\nof tags without the \"tags/\" prefix in front of every tag as it does now?\nWanted to use the new \"git rev-parse --tags\" instead of \"find\" to produce \nthe list but am not sure how important backward compatibility is in that case.\n\nSean\n\n Documentation/git-rev-parse.txt |    9 +++++++++\n git-branch.sh                   |    3 +--\n refs.c                          |   23 +++++++++++++++++++----\n refs.h                          |    3 +++\n rev-parse.c                     |   17 ++++++++++++++++-\n 5 files changed, 48 insertions(+), 7 deletions(-)\n\n260bda5eb4effca1a1dd33beb7f7e962d3eab602\ndiff --git a/Documentation/git-rev-parse.txt b/Documentation/git-rev-parse.txt\nindex 8b95df0..ab896fc 100644\n--- a/Documentation/git-rev-parse.txt\n+++ b/Documentation/git-rev-parse.txt\n@@ -67,6 +67,15 @@ OPTIONS\n --all::\n \tShow all refs found in `$GIT_DIR/refs`.\n \n+--branches::\n+\tShow branch refs found in `$GIT_DIR/refs/heads`.\n+\n+--tags::\n+\tShow tag refs found in `$GIT_DIR/refs/tags`.\n+\n+--remotes::\n+\tShow tag refs found in `$GIT_DIR/refs/remotes`.\n+\n --show-prefix::\n \tWhen the command is invoked from a subdirectory, show the\n \tpath of the current directory relative to the top-level\ndiff --git a/git-branch.sh b/git-branch.sh\nindex ebcc898..134e68c 100755\n--- a/git-branch.sh\n+++ b/git-branch.sh\n@@ -82,8 +82,7 @@ done\n \n case \"$#\" in\n 0)\n-\tgit-rev-parse --symbolic --all |\n-\tsed -ne 's|^refs/heads/||p' |\n+\tgit-rev-parse --symbolic --branches |\n \tsort |\n \twhile read ref\n \tdo\ndiff --git a/refs.c b/refs.c\nindex 275b914..6c91ae6 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -114,7 +114,7 @@ int read_ref(const char *filename, unsig\n \treturn -1;\n }\n \n-static int do_for_each_ref(const char *base, int (*fn)(const char *path, const unsigned char *sha1))\n+static int do_for_each_ref(const char *base, int (*fn)(const char *path, const unsigned char *sha1), int trim)\n {\n \tint retval = 0;\n \tDIR *dir = opendir(git_path(\"%s\", base));\n@@ -146,7 +146,7 @@ static int do_for_each_ref(const char *b\n \t\t\tif (stat(git_path(\"%s\", path), &st) < 0)\n \t\t\t\tcontinue;\n \t\t\tif (S_ISDIR(st.st_mode)) {\n-\t\t\t\tretval = do_for_each_ref(path, fn);\n+\t\t\t\tretval = do_for_each_ref(path, fn, trim);\n \t\t\t\tif (retval)\n \t\t\t\t\tbreak;\n \t\t\t\tcontinue;\n@@ -160,7 +160,7 @@ static int do_for_each_ref(const char *b\n \t\t\t\t      \"commit object!\", path);\n \t\t\t\tcontinue;\n \t\t\t}\n-\t\t\tretval = fn(path, sha1);\n+\t\t\tretval = fn(path + trim, sha1);\n \t\t\tif (retval)\n \t\t\t\tbreak;\n \t\t}\n@@ -180,7 +180,22 @@ int head_ref(int (*fn)(const char *path,\n \n int for_each_ref(int (*fn)(const char *path, const unsigned char *sha1))\n {\n-\treturn do_for_each_ref(\"refs\", fn);\n+\treturn do_for_each_ref(\"refs\", fn, 0);\n+}\n+\n+int for_each_tag_ref(int (*fn)(const char *path, const unsigned char *sha1))\n+{\n+\treturn do_for_each_ref(\"refs/tags\", fn, 10);\n+}\n+\n+int for_each_branch_ref(int (*fn)(const char *path, const unsigned char *sha1))\n+{\n+\treturn do_for_each_ref(\"refs/heads\", fn, 11);\n+}\n+\n+int for_each_remote_ref(int (*fn)(const char *path, const unsigned char *sha1))\n+{\n+\treturn do_for_each_ref(\"refs/remotes\", fn, 13);\n }\n \n static char *ref_file_name(const char *ref)\ndiff --git a/refs.h b/refs.h\nindex 2625596..fa816c1 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -7,6 +7,9 @@ #define REFS_H\n  */\n extern int head_ref(int (*fn)(const char *path, const unsigned char *sha1));\n extern int for_each_ref(int (*fn)(const char *path, const unsigned char *sha1));\n+extern int for_each_tag_ref(int (*fn)(const char *path, const unsigned char *sha1));\n+extern int for_each_branch_ref(int (*fn)(const char *path, const unsigned char *sha1));\n+extern int for_each_remote_ref(int (*fn)(const char *path, const unsigned char *sha1));\n \n /** Reads the refs file specified into sha1 **/\n extern int get_ref_sha1(const char *ref, unsigned char *sha1);\ndiff --git a/rev-parse.c b/rev-parse.c\nindex 62e16af..4e2d9fb 100644\n--- a/rev-parse.c\n+++ b/rev-parse.c\n@@ -36,6 +36,7 @@ static int is_rev_argument(const char *a\n \t\t\"--all\",\n \t\t\"--bisect\",\n \t\t\"--dense\",\n+\t\t\"--branches\",\n \t\t\"--header\",\n \t\t\"--max-age=\",\n \t\t\"--max-count=\",\n@@ -45,7 +46,9 @@ static int is_rev_argument(const char *a\n \t\t\"--objects-edge\",\n \t\t\"--parents\",\n \t\t\"--pretty\",\n+\t\t\"--remotes\",\n \t\t\"--sparse\",\n+\t\t\"--tags\",\n \t\t\"--topo-order\",\n \t\t\"--date-order\",\n \t\t\"--unpacked\",\n@@ -165,7 +168,7 @@ int main(int argc, char **argv)\n \tint i, as_is = 0, verify = 0;\n \tunsigned char sha1[20];\n \tconst char *prefix = setup_git_directory();\n-\t\n+\n \tgit_config(git_default_config);\n \n \tfor (i = 1; i < argc; i++) {\n@@ -255,6 +258,18 @@ int main(int argc, char **argv)\n \t\t\t\tfor_each_ref(show_reference);\n \t\t\t\tcontinue;\n \t\t\t}\n+\t\t\tif (!strcmp(arg, \"--branches\")) {\n+\t\t\t\tfor_each_branch_ref(show_reference);\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\t\t\tif (!strcmp(arg, \"--tags\")) {\n+\t\t\t\tfor_each_tag_ref(show_reference);\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\t\t\tif (!strcmp(arg, \"--remotes\")) {\n+\t\t\t\tfor_each_remote_ref(show_reference);\n+\t\t\t\tcontinue;\n+\t\t\t}\n \t\t\tif (!strcmp(arg, \"--show-prefix\")) {\n \t\t\t\tif (prefix)\n \t\t\t\t\tputs(prefix);\n-- \n1.3.2.g575a1\n"},{"id":"19937","messageId":"7v8xp4196e.fsf@assigned-by-dhcp.cox.net","threadId":"4127","inReplyTo":"BAYC1-PASMTP043948149786B7EE06DED3AEA20@CEZ.ICE","subject":"Re: [PATCH] Add \"--branches\", \"--tags\" and \"--remotes\" options to git-rev-parse.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-05-14T23:24:57Z","receivedAt":"2006-05-14T23:24:57Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Sean <seanlkml@sympatico.ca> writes:\n\n> On a related note, would it be okay to change \"git tag -l\" to\n> produce a list of tags without the \"tags/\" prefix in front of\n> every tag as it does now?  Wanted to use the new \"git\n> rev-parse --tags\" instead of \"find\" to produce the list but am\n> not sure how important backward compatibility is in that case.\n\nI do not have problem with that, but somebody else's script\nmight; Cogito seems not to mind.\n\nSomething like this perhaps?\n\n-- >8 --\ndiff --git a/git-tag.sh b/git-tag.sh\nindex dc6aa95..2286ad5 100755\n--- a/git-tag.sh\n+++ b/git-tag.sh\n@@ -28,11 +28,10 @@ do\n         cd \"$GIT_DIR/refs\" &&\n \tcase \"$#\" in\n \t1)\n-\t\tfind tags -type f -print ;;\n-\t*)\n-\t\tshift\n-\t\tfind tags -type f -print | grep \"$@\" ;;\n+\t\tset x . ;;\n \tesac\n+\tshift\n+\tfind tags -type f -print | sed -e 's|^tags/||' | grep \"$@\"\n \texit $?\n \t;;\n     -m)\n"},{"id":"19944","messageId":"BAYC1-PASMTP079744DE4B299C5B567F30AEA30@CEZ.ICE","threadId":"4127","inReplyTo":"7v8xp4196e.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Add \"--branches\", \"--tags\" and \"--remotes\" options to git-rev-parse.","fromName":"Sean","fromEmail":"seanlkml@sympatico.ca","sentAt":"2006-05-15T00:07:39Z","receivedAt":"2006-05-15T00:07:39Z","isPatch":true,"sender":{"key":"seanlkml@sympatico.ca","avatar":"https://gravatar.com/avatar/f92923f54fc08c401fc59b71829d4b89e9b8087fbba45ff87c82e6a83aee02ae?d=mp&s=160"},"body":"On Sun, 14 May 2006 16:24:57 -0700\nJunio C Hamano <junkio@cox.net> wrote:\n\n> I do not have problem with that, but somebody else's script\n> might; Cogito seems not to mind.\n> \n> Something like this perhaps?\n\nThat looks good.  If you accept the rev-parse patch, then i'd suggest the\npatch below instead.\n\nSean\n\n\ndiff --git a/git-tag.sh b/git-tag.sh\nindex dc6aa95..a0afa25 100755\n--- a/git-tag.sh\n+++ b/git-tag.sh\n@@ -25,14 +25,12 @@ do\n \tforce=1\n \t;;\n     -l)\n-        cd \"$GIT_DIR/refs\" &&\n \tcase \"$#\" in\n \t1)\n-\t\tfind tags -type f -print ;;\n-\t*)\n-\t\tshift\n-\t\tfind tags -type f -print | grep \"$@\" ;;\n+\t\tset x . ;;\n \tesac\n+\tshift\n+\tgit rev-parse --symbolic --tags | sort | grep \"$@\"\n \texit $?\n \t;;\n     -m)\n"},{"id":"20024","messageId":"e4an8j$cti$1@sea.gmane.org","threadId":"4127","inReplyTo":"BAYC1-PASMTP043948149786B7EE06DED3AEA20@CEZ.ICE","subject":"Re: [PATCH] Add \"--branches\", \"--tags\" and \"--remotes\" options to git-rev-parse.","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2006-05-15T20:11:17Z","receivedAt":"2006-05-15T20:11:17Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Sean Estabrooks wrote:\n\n> On Sat, 13 May 2006 10:38:23 -0700\n> Junio C Hamano <junkio@cox.net> wrote:\n> \n>> Makes sense perhaps.\n>> \n>> I understand you added --tags for completeness.  Probably it\n>> would make sense to add --remotes if you are shooting for that.\n[...]\n\n> +--remotes::\n> +     Show tag refs found in `$GIT_DIR/refs/remotes`.\n> +\n\nIn `Documentation/repository-layout.txt' there is information about\n`$GIT_DIR/remotes' not `$GIT_DIR/refs/remotes` so either the patch should\nbe amended, or the layout documentation should be updated, or the layout\nrepository should be changed.\n\n-- \nJakub Narebski\nWarsaw, Poland\n"}]}