{"thread":{"id":"18515","subject":"[PATCH] Don't permit ref/branch names to end with \".lock\"","startedAt":"2009-03-24T23:31:01Z","lastAt":"2009-03-24T23:31:01Z","messageCount":1,"participants":["Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"109267","messageId":"20090324233101.GU23521@spearce.org","threadId":"18515","inReplyTo":null,"subject":"[PATCH] Don't permit ref/branch names to end with \".lock\"","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-03-24T23:31:01Z","receivedAt":"2009-03-24T23:31:01Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"We already skip over loose refs under $GIT_DIR/refs if the name\nends with \".lock\", so creating a branch named \"foo.lock\" will not\nappear in the output of \"git branch\", \"git for-each-ref\", nor will\nits commit be considered reachable by \"git rev-list --all\".\n\nIn the latter case this is especially evil, as it may cause\nrepository corruption when objects reachable only through such a\nref are deleted by \"git prune\".\n\nIt should be reasonably safe to deny use of \".lock\" as a ref suffix.\nIn prior versions of Git such branches would be \"phantom branches\";\nyou can create it, but you can't see it in \"git branch\" output.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n\n This goes on top of your jc/name-branch-iffy currently in pu.\n\n Documentation/git-check-ref-format.txt |    2 ++\n refs.c                                 |    3 +++\n 2 files changed, 5 insertions(+), 0 deletions(-)\n\ndiff --git a/Documentation/git-check-ref-format.txt b/Documentation/git-check-ref-format.txt\nindex d23fd21..9b707a7 100644\n--- a/Documentation/git-check-ref-format.txt\n+++ b/Documentation/git-check-ref-format.txt\n@@ -34,6 +34,8 @@ imposes the following rules on how refs are named:\n \n . They cannot end with a slash `/` nor a dot `.`.\n \n+. They cannot end with the sequence `.lock`.\n+\n . They cannot contain a sequence `@{`.\n \n These rules makes it easy for shell script based tools to parse\ndiff --git a/refs.c b/refs.c\nindex e355489..f3fdcbd 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -676,6 +676,7 @@ int for_each_rawref(each_ref_fn fn, void *cb_data)\n  * - it has double dots \"..\", or\n  * - it has ASCII control character, \"~\", \"^\", \":\" or SP, anywhere, or\n  * - it ends with a \"/\".\n+ * - it ends with \".lock\"\n  */\n \n static inline int bad_ref_char(int ch)\n@@ -737,6 +738,8 @@ int check_ref_format(const char *ref)\n \t\t\t\treturn CHECK_REF_FORMAT_ERROR;\n \t\t\tif (level < 2)\n \t\t\t\treturn CHECK_REF_FORMAT_ONELEVEL;\n+\t\t\tif (has_extension(ref, \".lock\"))\n+\t\t\t\treturn CHECK_REF_FORMAT_ERROR;\n \t\t\treturn ret;\n \t\t}\n \t}\n-- \n1.6.2.1.471.g682837\n"}]}