{"thread":{"id":"54089","subject":"[PATCH 0/2] minor refspec cleanups","startedAt":"2020-08-21T21:48:42Z","lastAt":"2020-08-21T21:48:44Z","messageCount":3,"participants":["Jacob Keller"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"404233","messageId":"20200821214820.757222-1-jacob.e.keller@intel.com","threadId":"54089","inReplyTo":null,"subject":"[PATCH 0/2] minor refspec cleanups","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2020-08-21T21:48:18Z","receivedAt":"2020-08-21T21:48:42Z","isPatch":true,"sender":{"key":"jacob.e.keller@intel.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"From: Jacob Keller <jacob.keller@gmail.com>\n\nWhile preparing some patches for implementing support for negative refspecs,\nI found a couple of minor nits. The first patch fixes the documentation in\nrefspec.h to refer to the correct structures. The second patch cleans up a\npotential issue with refspec_item structures that weren't initialized\nproperly. While nothing breaks today, future extensions to refspec_item\nwould break if the structure wasn't properly initialized to zero.\n\nJacob Keller (2):\n  refspec: fix documentation referring to refspec_item\n  refspec: make sure stack refspec_item variables are zeroed\n\n builtin/remote.c |  1 +\n refspec.h        | 27 ++++++++++++++-------------\n transport.c      |  1 +\n 3 files changed, 16 insertions(+), 13 deletions(-)\n\n\nbase-commit: 878e727637ec5815ccb3301eb994a54df95b21b8\n-- \n2.28.0.218.ge27853923b9d.dirty\n\n"},{"id":"404234","messageId":"20200821214820.757222-2-jacob.e.keller@intel.com","threadId":"54089","inReplyTo":"20200821214820.757222-1-jacob.e.keller@intel.com","subject":"[PATCH 1/2] refspec: fix documentation referring to refspec_item","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2020-08-21T21:48:19Z","receivedAt":"2020-08-21T21:48:43Z","isPatch":true,"sender":{"key":"jacob.e.keller@intel.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"From: Jacob Keller <jacob.keller@gmail.com>\n\nIn commit d27eb356bf25 (\"remote: move doc to remote.h and refspec.h\")\nthe documentation for the refspec structure was moved into refspec.h\n\nThis documentation refers to elements of the refspec_item, not the\nstruct refspec. Move the documentation slightly in order to align it\nwith the structure it is actually referring to.\n\nSigned-off-by: Jacob Keller <jacob.keller@gmail.com>\n---\n refspec.h | 27 ++++++++++++++-------------\n 1 file changed, 14 insertions(+), 13 deletions(-)\n\ndiff --git a/refspec.h b/refspec.h\nindex 23e1555b88ac..8d654e3a3ac4 100644\n--- a/refspec.h\n+++ b/refspec.h\n@@ -4,6 +4,19 @@\n #define TAG_REFSPEC \"refs/tags/*:refs/tags/*\"\n extern const struct refspec_item *tag_refspec;\n \n+/**\n+ * A struct refspec_item holds the parsed interpretation of a refspec.  If it will\n+ * force updates (starts with a '+'), force is true.  If it is a pattern\n+ * (sides end with '*') pattern is true.  src and dest are the two sides\n+ * (including '*' characters if present); if there is only one side, it is src,\n+ * and dst is NULL; if sides exist but are empty (i.e., the refspec either\n+ * starts or ends with ':'), the corresponding side is \"\".\n+ *\n+ * remote_find_tracking(), given a remote and a struct refspec_item with either src\n+ * or dst filled out, will fill out the other such that the result is in the\n+ * \"fetch\" specification for the remote (note that this evaluates patterns and\n+ * returns a single result).\n+ */\n struct refspec_item {\n \tunsigned force : 1;\n \tunsigned pattern : 1;\n@@ -21,20 +34,8 @@ struct refspec_item {\n #define REFSPEC_INIT_PUSH { .fetch = REFSPEC_PUSH }\n \n /**\n- * A struct refspec holds the parsed interpretation of a refspec.  If it will\n- * force updates (starts with a '+'), force is true.  If it is a pattern\n- * (sides end with '*') pattern is true.  src and dest are the two sides\n- * (including '*' characters if present); if there is only one side, it is src,\n- * and dst is NULL; if sides exist but are empty (i.e., the refspec either\n- * starts or ends with ':'), the corresponding side is \"\".\n- *\n- * An array of strings can be parsed into an array of struct refspecs using\n+ * An array of strings can be parsed into a struct refspec using\n  * parse_fetch_refspec() or parse_push_refspec().\n- *\n- * remote_find_tracking(), given a remote and a struct refspec with either src\n- * or dst filled out, will fill out the other such that the result is in the\n- * \"fetch\" specification for the remote (note that this evaluates patterns and\n- * returns a single result).\n  */\n struct refspec {\n \tstruct refspec_item *items;\n-- \n2.28.0.218.ge27853923b9d.dirty\n\n"},{"id":"404235","messageId":"20200821214820.757222-3-jacob.e.keller@intel.com","threadId":"54089","inReplyTo":"20200821214820.757222-1-jacob.e.keller@intel.com","subject":"[PATCH 2/2] refspec: make sure stack refspec_item variables are zeroed","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2020-08-21T21:48:20Z","receivedAt":"2020-08-21T21:48:44Z","isPatch":true,"sender":{"key":"jacob.e.keller@intel.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"From: Jacob Keller <jacob.keller@gmail.com>\n\nA couple of functions that used struct refspec_item did not zero out the\nstructure memory. This can result in unexpected behavior, especially if\nadditional parameters are ever added to refspec_item in the future. Use\nmemset to ensure that unset structure members are zero.\n\nIt may make sense to convert most of these uses of struct refspec_item\nto use either struct initializers or refspec_item_init_or_die. However,\nother similar code uses memset. Converting all of these uses has been\nleft as a future exercise.\n\nSigned-off-by: Jacob Keller <jacob.keller@gmail.com>\n---\n builtin/remote.c | 1 +\n transport.c      | 1 +\n 2 files changed, 2 insertions(+)\n\ndiff --git a/builtin/remote.c b/builtin/remote.c\nindex c8240e9fcd58..542f56e3878b 100644\n--- a/builtin/remote.c\n+++ b/builtin/remote.c\n@@ -478,6 +478,7 @@ static int get_head_names(const struct ref *remote_refs, struct ref_states *stat\n \tstruct ref *fetch_map = NULL, **fetch_map_tail = &fetch_map;\n \tstruct refspec_item refspec;\n \n+\tmemset(&refspec, 0, sizeof(refspec));\n \trefspec.force = 0;\n \trefspec.pattern = 1;\n \trefspec.src = refspec.dst = \"refs/heads/*\";\ndiff --git a/transport.c b/transport.c\nindex 2d4fd851dc0f..419be0b6ea4b 100644\n--- a/transport.c\n+++ b/transport.c\n@@ -443,6 +443,7 @@ void transport_update_tracking_ref(struct remote *remote, struct ref *ref, int v\n \tif (ref->status != REF_STATUS_OK && ref->status != REF_STATUS_UPTODATE)\n \t\treturn;\n \n+\tmemset(&rs, 0, sizeof(rs));\n \trs.src = ref->name;\n \trs.dst = NULL;\n \n-- \n2.28.0.218.ge27853923b9d.dirty\n\n"}]}