Warmcat homepage andy@warmcat.com
libwebsockets
{"schema":"libjg2-1", "vpath":"/git/", "avatar":"/git/avatar/", "alang":"", "gen_ut":1746511706, "reponame":"cgit", "desc":"CGI gitweb", "owner": { "name": "Andy Green", "email": "andy@warmcat.com", "md5": "c50933ca2aa61e0fe2c43d46bb6b59cb" },"url":"https://warmcat.com/repo/cgit", "f":3, "items": [ {"schema":"libjg2-1", "cid":"2ed86ffcedd1b4eb9efadf4cbb086ca5", "commit": {"type":"commit", "time": 1467728080, "time_ofs": 120, "oid_tree": { "oid": "1f3a53622746e5fe43e9d5c7c9bc27ab2da22761", "alias": []}, "oid":{ "oid": "9984e7ab49c59e49a0d7e62c3435e7133f7a53ec", "alias": []}, "msg": "Avoid ambiguities when prettifying snapshot names", "sig_commit": { "git_time": { "time": 1467728080, "offset": 120 }, "name": "Jason A. Donenfeld", "email": "Jason@zx2c4.com", "md5": "689e78dac56e3d77d7f74984912487d3" }, "sig_author": { "git_time": { "time": 1464106518, "offset": 120 }, "name": "Lukas Fleischer", "email": "lfleischer@lfos.de", "md5": "564a12abc584fef24e562ae9881c45bb" }}, "body": "Avoid ambiguities when prettifying snapshot names\n\nWhen composing snapshot file names for a tag with a prefix of the form\nv[0-9] (resp. V[0-9]), the leading \u0022v\u0022 (resp. \u0022V\u0022) is stripped. This\nleads to conflicts if a tag with the stripped name already exists or if\nthere are tags only differing in the capitalization of the leading \u0022v\u0022.\nMake sure we do not strip the \u0022v\u0022 in these cases.\n\nReported-by: Juuso Lapinlampi \u003cwub@partyvan.eu\u003e\nSigned-off-by: Lukas Fleischer \u003clfleischer@lfos.de\u003e\n" , "diff": "diff --git a/ui-refs.c b/ui-refs.c\nindex 5b4530e..75f2789 100644\n--- a/ui-refs.c\n+++ b/ui-refs.c\n@@ -93,34 +93,28 @@ static void print_tag_header(void)\n static void print_tag_downloads(const struct cgit_repo *repo, const char *ref)\n {\n \tconst struct cgit_snapshot_format* f;\n-\tstruct strbuf filename \u003d STRBUF_INIT;\n \tconst char *basename;\n-\tint free_ref \u003d 0;\n+\tstruct strbuf filename \u003d STRBUF_INIT;\n+\tsize_t prefixlen;\n \n \tif (!ref || strlen(ref) \u003c 1)\n \t\treturn;\n \n \tbasename \u003d cgit_repobasename(repo-\u003eurl);\n-\tif (!starts_with(ref, basename)) {\n-\t\tif ((ref[0] \u003d\u003d 'v' || ref[0] \u003d\u003d 'V') \u0026\u0026 isdigit(ref[1]))\n-\t\t\tref++;\n-\t\tif (isdigit(ref[0])) {\n-\t\t\tref \u003d fmtalloc(\u0022%s-%s\u0022, basename, ref);\n-\t\t\tfree_ref \u003d 1;\n-\t\t}\n-\t}\n-\n+\tif (starts_with(ref, basename))\n+\t\tstrbuf_addstr(\u0026filename, ref);\n+\telse\n+\t\tcgit_compose_snapshot_prefix(\u0026filename, basename, ref);\n+\tprefixlen \u003d filename.len;\n \tfor (f \u003d cgit_snapshot_formats; f-\u003esuffix; f++) {\n \t\tif (!(repo-\u003esnapshots \u0026 f-\u003ebit))\n \t\t\tcontinue;\n-\t\tstrbuf_reset(\u0026filename);\n-\t\tstrbuf_addf(\u0026filename, \u0022%s%s\u0022, ref, f-\u003esuffix);\n+\t\tstrbuf_setlen(\u0026filename, prefixlen);\n+\t\tstrbuf_addstr(\u0026filename, f-\u003esuffix);\n \t\tcgit_snapshot_link(filename.buf, NULL, NULL, NULL, NULL, filename.buf);\n \t\thtml(\u0022\u0026nbsp;\u0026nbsp;\u0022);\n \t}\n \n-\tif (free_ref)\n-\t\tfree((char *)ref);\n \tstrbuf_release(\u0026filename);\n }\n \ndiff --git a/ui-shared.c b/ui-shared.c\nindex 562fa0e..b1a6c46 100644\n--- a/ui-shared.c\n+++ b/ui-shared.c\n@@ -1069,18 +1069,34 @@ void cgit_print_filemode(unsigned short mode)\n \thtml_fileperm(mode);\n }\n \n+void cgit_compose_snapshot_prefix(struct strbuf *filename, const char *base,\n+\t\t\t\t const char *ref)\n+{\n+\tunsigned char sha1[20];\n+\n+\t/*\n+\t * Prettify snapshot names by stripping leading \u0022v\u0022 or \u0022V\u0022 if the tag\n+\t * name starts with {v,V}[0-9] and the prettify mapping is injective,\n+\t * i.e. each stripped tag can be inverted without ambiguities.\n+\t */\n+\tif (get_sha1(fmt(\u0022refs/tags/%s\u0022, ref), sha1) \u003d\u003d 0 \u0026\u0026\n+\t (ref[0] \u003d\u003d 'v' || ref[0] \u003d\u003d 'V') \u0026\u0026 isdigit(ref[1]) \u0026\u0026\n+\t ((get_sha1(fmt(\u0022refs/tags/%s\u0022, ref + 1), sha1) \u003d\u003d 0) +\n+\t (get_sha1(fmt(\u0022refs/tags/v%s\u0022, ref + 1), sha1) \u003d\u003d 0) +\n+\t (get_sha1(fmt(\u0022refs/tags/V%s\u0022, ref + 1), sha1) \u003d\u003d 0) \u003d\u003d 1))\n+\t\tref++;\n+\n+\tstrbuf_addf(filename, \u0022%s-%s\u0022, base, ref);\n+}\n+\n void cgit_print_snapshot_links(const char *repo, const char *head,\n \t\t\t const char *hex, int snapshots)\n {\n \tconst struct cgit_snapshot_format* f;\n \tstruct strbuf filename \u003d STRBUF_INIT;\n \tsize_t prefixlen;\n-\tunsigned char sha1[20];\n \n-\tif (get_sha1(fmt(\u0022refs/tags/%s\u0022, hex), sha1) \u003d\u003d 0 \u0026\u0026\n-\t (hex[0] \u003d\u003d 'v' || hex[0] \u003d\u003d 'V') \u0026\u0026 isdigit(hex[1]))\n-\t\thex++;\n-\tstrbuf_addf(\u0026filename, \u0022%s-%s\u0022, cgit_repobasename(repo), hex);\n+\tcgit_compose_snapshot_prefix(\u0026filename, cgit_repobasename(repo), hex);\n \tprefixlen \u003d filename.len;\n \tfor (f \u003d cgit_snapshot_formats; f-\u003esuffix; f++) {\n \t\tif (!(snapshots \u0026 f-\u003ebit))\ndiff --git a/ui-shared.h b/ui-shared.h\nindex b457c97..87799f1 100644\n--- a/ui-shared.h\n+++ b/ui-shared.h\n@@ -71,6 +71,8 @@ __attribute__((format (printf,3,4)))\n extern void cgit_print_error_page(int code, const char *msg, const char *fmt, ...);\n extern void cgit_print_pageheader(void);\n extern void cgit_print_filemode(unsigned short mode);\n+extern void cgit_compose_snapshot_prefix(struct strbuf *filename,\n+\t\t\t\t\t const char *base, const char *ref);\n extern void cgit_print_snapshot_links(const char *repo, const char *head,\n \t\t\t\t const char *hex, int snapshots);\n extern void cgit_add_hidden_formfields(int incl_head, int incl_search,\n","s":{"c":1746511706,"u": 1150}} ],"g": 1862,"chitpc": 0,"ehitpc": 0,"indexed":0 , "ab": 0, "si": 0, "db":0, "di":0, "sat":0, "lfc": "0000"}