{"thread":{"id":"38529","subject":"[PATCH] merge-file: correctly open files when in a subdir","startedAt":"2015-02-08T16:53:53Z","lastAt":"2015-02-09T10:06:37Z","messageCount":2,"participants":["Aleksander Boruch-Gruszecki","Duy Nguyen"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"255780","messageId":"CAPHKiG7yP=QZBVdDbyQp=uyMX0EsmUqgO-LO8pscn7hcbP0RCw@mail.gmail.com","threadId":"38529","inReplyTo":null,"subject":"[PATCH] merge-file: correctly open files when in a subdir","fromName":"Aleksander Boruch-Gruszecki","fromEmail":"aleksander.boruchgruszecki@gmail.com","sentAt":"2015-02-08T16:53:53Z","receivedAt":"2015-02-08T16:53:53Z","isPatch":true,"sender":{"key":"aleksander.boruchgruszecki@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8414373?v=4"},"body":"run_setup_gently() is called before merge-file. This may result in changing\ncurrent working directory, which wasn't taken into account when opening a file\nfor writing.\n\nFix by prepending the passed prefix. Previous var is left so that error\nmessages keep referring to the file from the user's working directory\nperspective.\n\nSigned-off-by: Aleksander Boruch-Gruszecki\n    <aleksander.boruchgruszecki@gmail.com>\n---\nI'm sorry if I'm sending the copies to wrong people, but I had no idea\nwho to send them to since there were barely any changes to the file.\nSince the fix is so trivial I didn't add any tests, but I can create\nsome if they're needed.\n\n builtin/merge-file.c | 3 ++-\n 1 file changed, 2 insertions(+), 1 deletion(-)\n\ndiff --git a/builtin/merge-file.c b/builtin/merge-file.c\nindex 844f84f..232b768 100644\n--- a/builtin/merge-file.c\n+++ b/builtin/merge-file.c\n@@ -90,7 +90,8 @@ int cmd_merge_file(int argc, const char **argv,\nconst char *prefix)\n\n     if (ret >= 0) {\n         const char *filename = argv[0];\n-        FILE *f = to_stdout ? stdout : fopen(filename, \"wb\");\n+        const char *fpath = prefix_filename(prefix, prefixlen, argv[0]);\n+        FILE *f = to_stdout ? stdout : fopen(fpath, \"wb\");\n\n         if (!f)\n             ret = error(\"Could not open %s for writing\", filename);\n-- \n1.9.1\n"},{"id":"255812","messageId":"CACsJy8Abyi00UeDBWCoz6_+KE=k1-KkZCw8yww_g2pWbB+RYqg@mail.gmail.com","threadId":"38529","inReplyTo":"CAPHKiG7yP=QZBVdDbyQp=uyMX0EsmUqgO-LO8pscn7hcbP0RCw@mail.gmail.com","subject":"Re: [PATCH] merge-file: correctly open files when in a subdir","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2015-02-09T10:06:37Z","receivedAt":"2015-02-09T10:06:37Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Sun, Feb 8, 2015 at 11:53 PM, Aleksander Boruch-Gruszecki\n<aleksander.boruchgruszecki@gmail.com> wrote:\n> run_setup_gently() is called before merge-file. This may result in changing\n> current working directory, which wasn't taken into account when opening a file\n> for writing.\n>\n> Fix by prepending the passed prefix. Previous var is left so that error\n> messages keep referring to the file from the user's working directory\n> perspective.\n\nSounds about right. Thomas Rast fixed something similar in 55846b9\n(merge-file: correctly find files when called in subdir - 2010-10-17)\nbut he missed this part :-D. Perhaps a test case in\nt/t6023-merge-file.sh to prove this patch is working?\n-- \nDuy\n"}]}