{"thread":{"id":"48419","subject":"[PATCH 1/5] t/helper/test-write-cache: clean up lock-handling","startedAt":"2018-05-06T14:11:05Z","lastAt":"2018-05-06T14:11:05Z","messageCount":1,"participants":["Martin Ågren"],"isPatch":true,"patchVersion":1,"patchTotal":5},"messages":[{"id":"346763","messageId":"20180506141031.30204-2-martin.agren@gmail.com","threadId":"48419","inReplyTo":null,"subject":"[PATCH 1/5] t/helper/test-write-cache: clean up lock-handling","fromName":"Martin Ågren","fromEmail":"martin.agren@gmail.com","sentAt":"2018-05-06T14:10:27Z","receivedAt":"2018-05-06T14:11:05Z","isPatch":true,"sender":{"key":"martin.agren@gmail.com","avatar":null},"body":"Die in case writing the index fails, so that the caller can notice\n(instead of, say, being impressed by how performant the writing is).\n\nWhile at it, note that after opening a lock with `LOCK_DIE_ON_ERROR`, we\ndo not need to worry about whether we succeeded. Also, we can move the\n`struct lock_file` into the function and drop the staticness.\n\nSigned-off-by: Martin Ågren <martin.agren@gmail.com>\n---\n t/helper/test-write-cache.c | 14 +++++---------\n 1 file changed, 5 insertions(+), 9 deletions(-)\n\ndiff --git a/t/helper/test-write-cache.c b/t/helper/test-write-cache.c\nindex 017dc30380..8837717d36 100644\n--- a/t/helper/test-write-cache.c\n+++ b/t/helper/test-write-cache.c\n@@ -2,22 +2,18 @@\n #include \"cache.h\"\n #include \"lockfile.h\"\n \n-static struct lock_file index_lock;\n-\n int cmd__write_cache(int argc, const char **argv)\n {\n-\tint i, cnt = 1, lockfd;\n+\tstruct lock_file index_lock = LOCK_INIT;\n+\tint i, cnt = 1;\n \tif (argc == 2)\n \t\tcnt = strtol(argv[1], NULL, 0);\n \tsetup_git_directory();\n \tread_cache();\n \tfor (i = 0; i < cnt; i++) {\n-\t\tlockfd = hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);\n-\t\tif (0 <= lockfd) {\n-\t\t\twrite_locked_index(&the_index, &index_lock, COMMIT_LOCK);\n-\t\t} else {\n-\t\t\trollback_lock_file(&index_lock);\n-\t\t}\n+\t\thold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);\n+\t\tif (write_locked_index(&the_index, &index_lock, COMMIT_LOCK))\n+\t\t\tdie(\"unable to write index file\");\n \t}\n \n \treturn 0;\n-- \n2.17.0.411.g9fd64c8e46\n\n"}]}