{"thread":{"id":"34130","subject":"[PATCH] match-trees: factor out fill_tree_desc_strict","startedAt":"2013-06-13T18:19:28Z","lastAt":"2013-06-13T21:00:30Z","messageCount":2,"participants":["René Scharfe","Eric Sunshine"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"220761","messageId":"1371147568-31348-1-git-send-email-rene.scharfe@lsrfire.ath.cx","threadId":"34130","inReplyTo":null,"subject":"[PATCH] match-trees: factor out fill_tree_desc_strict","fromName":"René Scharfe","fromEmail":"rene.scharfe@lsrfire.ath.cx","sentAt":"2013-06-13T18:19:28Z","receivedAt":"2013-06-13T18:19:28Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Deduplicate code by moving tree_desc initialtization into a helper\nfunction, fill_tree_desc_strict.  It is like fill_tree_descriptor,\nexcept that it only accepts tree hashes and no tree references (tags,\ncommits).  No functional change.\n\nSigned-off-by: René Scharfe <rene.scharfe@lsrfire.ath.cx>\n---\n match-trees.c | 44 +++++++++++++++++++-------------------------\n 1 file changed, 19 insertions(+), 25 deletions(-)\n\ndiff --git a/match-trees.c b/match-trees.c\nindex 2bb734d..7873cde 100644\n--- a/match-trees.c\n+++ b/match-trees.c\n@@ -47,6 +47,22 @@ static int score_matches(unsigned mode1, unsigned mode2, const char *path)\n \treturn score;\n }\n \n+static void *fill_tree_desc_strict(struct tree_desc *desc,\n+\t\t\t\t   const unsigned char *hash)\n+{\n+\tvoid *buffer;\n+\tenum object_type type;\n+\tunsigned long size;\n+\n+\tbuffer = read_sha1_file(hash, &type, &size);\n+\tif (!buffer)\n+\t\tdie(\"unable to read tree (%s)\", sha1_to_hex(hash));\n+\tif (type != OBJ_TREE)\n+\t\tdie(\"%s is not a tree\", sha1_to_hex(hash));\n+\tinit_tree_desc(desc, buffer, size);\n+\treturn buffer;\n+}\n+\n static int base_name_entries_compare(const struct name_entry *a,\n \t\t\t\t     const struct name_entry *b)\n {\n@@ -61,23 +77,10 @@ static int score_trees(const unsigned char *hash1, const unsigned char *hash2)\n {\n \tstruct tree_desc one;\n \tstruct tree_desc two;\n-\tvoid *one_buf, *two_buf;\n+\tvoid *one_buf = fill_tree_desc_strict(&one, hash1);\n+\tvoid *two_buf = fill_tree_desc_strict(&two, hash2);\n \tint score = 0;\n-\tenum object_type type;\n-\tunsigned long size;\n \n-\tone_buf = read_sha1_file(hash1, &type, &size);\n-\tif (!one_buf)\n-\t\tdie(\"unable to read tree (%s)\", sha1_to_hex(hash1));\n-\tif (type != OBJ_TREE)\n-\t\tdie(\"%s is not a tree\", sha1_to_hex(hash1));\n-\tinit_tree_desc(&one, one_buf, size);\n-\ttwo_buf = read_sha1_file(hash2, &type, &size);\n-\tif (!two_buf)\n-\t\tdie(\"unable to read tree (%s)\", sha1_to_hex(hash2));\n-\tif (type != OBJ_TREE)\n-\t\tdie(\"%s is not a tree\", sha1_to_hex(hash2));\n-\tinit_tree_desc(&two, two_buf, size);\n \tfor (;;) {\n \t\tstruct name_entry e1, e2;\n \t\tint got_entry_from_one = tree_entry(&one, &e1);\n@@ -124,16 +127,7 @@ static void match_trees(const unsigned char *hash1,\n \t\t\tint recurse_limit)\n {\n \tstruct tree_desc one;\n-\tvoid *one_buf;\n-\tenum object_type type;\n-\tunsigned long size;\n-\n-\tone_buf = read_sha1_file(hash1, &type, &size);\n-\tif (!one_buf)\n-\t\tdie(\"unable to read tree (%s)\", sha1_to_hex(hash1));\n-\tif (type != OBJ_TREE)\n-\t\tdie(\"%s is not a tree\", sha1_to_hex(hash1));\n-\tinit_tree_desc(&one, one_buf, size);\n+\tvoid *one_buf = fill_tree_desc_strict(&one, hash1);\n \n \twhile (one.size) {\n \t\tconst char *path;\n-- \n1.8.3\n"},{"id":"220769","messageId":"CAPig+cQGTWBPhC1L1+-b9UE1u-tyNKwNQhVdauojzc984LPNrA@mail.gmail.com","threadId":"34130","inReplyTo":"1371147568-31348-1-git-send-email-rene.scharfe@lsrfire.ath.cx","subject":"Re: [PATCH] match-trees: factor out fill_tree_desc_strict","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2013-06-13T21:00:30Z","receivedAt":"2013-06-13T21:00:30Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Thu, Jun 13, 2013 at 2:19 PM, René Scharfe\n<rene.scharfe@lsrfire.ath.cx> wrote:\n> Deduplicate code by moving tree_desc initialtization into a helper\n\ns/initialtization/initialization/\n\n> function, fill_tree_desc_strict.  It is like fill_tree_descriptor,\n> except that it only accepts tree hashes and no tree references (tags,\n> commits).  No functional change.\n>\n> Signed-off-by: René Scharfe <rene.scharfe@lsrfire.ath.cx>\n"}]}