{"thread":{"id":"33743","subject":"[PATCH v4 0/2] New @ shortcut for HEAD","startedAt":"2013-05-07T22:04:29Z","lastAt":"2013-05-07T22:04:31Z","messageCount":3,"participants":["Felipe Contreras"],"isPatch":true,"patchVersion":4,"patchTotal":2},"messages":[{"id":"216658","messageId":"1367964271-11422-1-git-send-email-felipe.contreras@gmail.com","threadId":"33743","inReplyTo":null,"subject":"[PATCH v4 0/2] New @ shortcut for HEAD","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2013-05-07T22:04:29Z","receivedAt":"2013-05-07T22:04:29Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Hi,\n\nSame patches as before, except that the cleanup ones are in a different series,\nand this one doesn't depend on the other one.\n\nFelipe Contreras (2):\n  sha1_name: refactor reinterpret()\n  Add new @ shortcut for HEAD\n\n Documentation/git-check-ref-format.txt |  2 ++\n Documentation/revisions.txt            |  3 ++\n refs.c                                 |  4 +++\n sha1_name.c                            | 59 +++++++++++++++++++++++-----------\n t/t1508-at-combinations.sh             |  2 ++\n 5 files changed, 51 insertions(+), 19 deletions(-)\n\n-- \n1.8.3.rc0.401.g45bba44\n"},{"id":"216659","messageId":"1367964271-11422-2-git-send-email-felipe.contreras@gmail.com","threadId":"33743","inReplyTo":"1367964271-11422-1-git-send-email-felipe.contreras@gmail.com","subject":"[PATCH v4 1/2] sha1_name: refactor reinterpret()","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2013-05-07T22:04:30Z","receivedAt":"2013-05-07T22:04:30Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"This code essentially replaces part of ref with another ref, for example\n'@{-1}@{u}' is replaced with 'master@{u}', but this can be reused for\nother purposes other than nth prior checkouts.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n sha1_name.c | 42 +++++++++++++++++++++++-------------------\n 1 file changed, 23 insertions(+), 19 deletions(-)\n\ndiff --git a/sha1_name.c b/sha1_name.c\nindex 3820f28..fd2a95a 100644\n--- a/sha1_name.c\n+++ b/sha1_name.c\n@@ -966,6 +966,27 @@ int get_sha1_mb(const char *name, unsigned char *sha1)\n \treturn st;\n }\n \n+static int reinterpret(const char *name, int namelen, int len, struct strbuf *buf)\n+{\n+\t/* we have extra data, which might need further processing */\n+\tstruct strbuf tmp = STRBUF_INIT;\n+\tint used = buf->len;\n+\tint ret;\n+\n+\tstrbuf_add(buf, name + len, namelen - len);\n+\tret = interpret_branch_name(buf->buf, &tmp);\n+\t/* that data was not interpreted, remove our cruft */\n+\tif (ret < 0) {\n+\t\tstrbuf_setlen(buf, used);\n+\t\treturn len;\n+\t}\n+\tstrbuf_reset(buf);\n+\tstrbuf_addbuf(buf, &tmp);\n+\tstrbuf_release(&tmp);\n+\t/* tweak for size of {-N} versus expanded ref name */\n+\treturn ret - used + len;\n+}\n+\n /*\n  * This reads short-hand syntax that not only evaluates to a commit\n  * object name, but also can act as if the end user spelled the name\n@@ -999,25 +1020,8 @@ int interpret_branch_name(const char *name, struct strbuf *buf)\n \t\treturn len; /* syntax Ok, not enough switches */\n \tif (0 < len && len == namelen)\n \t\treturn len; /* consumed all */\n-\telse if (0 < len) {\n-\t\t/* we have extra data, which might need further processing */\n-\t\tstruct strbuf tmp = STRBUF_INIT;\n-\t\tint used = buf->len;\n-\t\tint ret;\n-\n-\t\tstrbuf_add(buf, name + len, namelen - len);\n-\t\tret = interpret_branch_name(buf->buf, &tmp);\n-\t\t/* that data was not interpreted, remove our cruft */\n-\t\tif (ret < 0) {\n-\t\t\tstrbuf_setlen(buf, used);\n-\t\t\treturn len;\n-\t\t}\n-\t\tstrbuf_reset(buf);\n-\t\tstrbuf_addbuf(buf, &tmp);\n-\t\tstrbuf_release(&tmp);\n-\t\t/* tweak for size of {-N} versus expanded ref name */\n-\t\treturn ret - used + len;\n-\t}\n+\telse if (0 < len)\n+\t\treturn reinterpret(name, namelen, len, buf);\n \n \tcp = strchr(name, '@');\n \tif (!cp)\n-- \n1.8.3.rc0.401.g45bba44\n"},{"id":"216660","messageId":"1367964271-11422-3-git-send-email-felipe.contreras@gmail.com","threadId":"33743","inReplyTo":"1367964271-11422-1-git-send-email-felipe.contreras@gmail.com","subject":"[PATCH v4 2/2] Add new @ shortcut for HEAD","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2013-05-07T22:04:31Z","receivedAt":"2013-05-07T22:04:31Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Typing 'HEAD' is tedious, especially when we can use '@' instead.\n\nThe reason for choosing '@' is that it follows naturally from the\nref@op syntax (e.g. HEAD@{u}), except we have no ref, and no\noperation, and when we don't have those, it makes sens to assume\n'HEAD'.\n\nSo now we can use 'git show @~1', and all that goody goodness.\n\nUntil now '@' was a valid name, but it conflicts with this idea, so\nlet's make it invalid. Probably very few people, if any, used this name.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n Documentation/git-check-ref-format.txt |  2 ++\n Documentation/revisions.txt            |  3 +++\n refs.c                                 |  4 ++++\n sha1_name.c                            | 17 +++++++++++++++++\n t/t1508-at-combinations.sh             |  2 ++\n 5 files changed, 28 insertions(+)\n\ndiff --git a/Documentation/git-check-ref-format.txt b/Documentation/git-check-ref-format.txt\nindex ec1739a..e8035ec 100644\n--- a/Documentation/git-check-ref-format.txt\n+++ b/Documentation/git-check-ref-format.txt\n@@ -54,6 +54,8 @@ Git imposes the following rules on how references are named:\n \n . They cannot contain a sequence `@{`.\n \n+. They cannot be the single character `@`.\n+\n . They cannot contain a `\\`.\n \n These rules make it easy for shell script based tools to parse\ndiff --git a/Documentation/revisions.txt b/Documentation/revisions.txt\nindex d477b3f..09896a3 100644\n--- a/Documentation/revisions.txt\n+++ b/Documentation/revisions.txt\n@@ -58,6 +58,9 @@ the '$GIT_DIR/refs' directory or from the '$GIT_DIR/packed-refs' file.\n While the ref name encoding is unspecified, UTF-8 is preferred as\n some output processing may assume ref names in UTF-8.\n \n+'@'::\n+  '@' alone is a shortcut for 'HEAD'.\n+\n '<refname>@\\{<date>\\}', e.g. 'master@\\{yesterday\\}', 'HEAD@\\{5 minutes ago\\}'::\n   A ref followed by the suffix '@' with a date specification\n   enclosed in a brace\ndiff --git a/refs.c b/refs.c\nindex de2d8eb..4e70b3e 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -72,6 +72,10 @@ int check_refname_format(const char *refname, int flags)\n {\n \tint component_len, component_count = 0;\n \n+\tif (!strcmp(refname, \"@\"))\n+\t\t/* Refname is a single character '@'. */\n+\t\treturn -1;\n+\n \twhile (1) {\n \t\t/* We are at the start of a path component. */\n \t\tcomponent_len = check_refname_component(refname, flags);\ndiff --git a/sha1_name.c b/sha1_name.c\nindex fd2a95a..dd30c7c 100644\n--- a/sha1_name.c\n+++ b/sha1_name.c\n@@ -966,6 +966,17 @@ int get_sha1_mb(const char *name, unsigned char *sha1)\n \treturn st;\n }\n \n+/* parse @something syntax, when 'something' is not {.*} */\n+static int interpret_empty_at(const char *name, int namelen, int len, struct strbuf *buf)\n+{\n+\tif (len || name[1] == '{')\n+\t\treturn -1;\n+\n+\tstrbuf_reset(buf);\n+\tstrbuf_add(buf, \"HEAD\", 4);\n+\treturn 1;\n+}\n+\n static int reinterpret(const char *name, int namelen, int len, struct strbuf *buf)\n {\n \t/* we have extra data, which might need further processing */\n@@ -1026,9 +1037,15 @@ int interpret_branch_name(const char *name, struct strbuf *buf)\n \tcp = strchr(name, '@');\n \tif (!cp)\n \t\treturn -1;\n+\n+\tlen = interpret_empty_at(name, namelen, cp - name, buf);\n+\tif (len > 0)\n+\t\treturn reinterpret(name, namelen, len, buf);\n+\n \ttmp_len = upstream_mark(cp, namelen - (cp - name));\n \tif (!tmp_len)\n \t\treturn -1;\n+\n \tlen = cp + tmp_len - name;\n \tcp = xstrndup(name, cp - name);\n \tupstream = branch_get(*cp ? cp : NULL);\ndiff --git a/t/t1508-at-combinations.sh b/t/t1508-at-combinations.sh\nindex d5d6244..277a1a2 100755\n--- a/t/t1508-at-combinations.sh\n+++ b/t/t1508-at-combinations.sh\n@@ -45,6 +45,8 @@ check \"@{u}\" upstream-two\n check \"@{u}@{1}\" upstream-one\n check \"@{-1}@{u}\" master-two\n check \"@{-1}@{u}@{1}\" master-one\n+check \"@\" new-two\n+check \"@@{u}\" upstream-two\n nonsense \"@{u}@{-1}\"\n nonsense \"@{1}@{u}\"\n \n-- \n1.8.3.rc0.401.g45bba44\n"}]}