From patchwork Fri Feb 22 20:11:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 10826935 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 674821390 for ; Fri, 22 Feb 2019 20:11:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 56371321FA for ; Fri, 22 Feb 2019 20:11:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4AC5A322DE; Fri, 22 Feb 2019 20:11:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A6CEC321FA for ; Fri, 22 Feb 2019 20:11:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726490AbfBVULT (ORCPT ); Fri, 22 Feb 2019 15:11:19 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:40468 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726056AbfBVULT (ORCPT ); Fri, 22 Feb 2019 15:11:19 -0500 Received: by mail-wr1-f68.google.com with SMTP id q1so3671437wrp.7 for ; Fri, 22 Feb 2019 12:11:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wBV62S6hyP3GujCTK4VUSI3pqpLptAd4Jr8uZtcKQgo=; b=CBIOKBjP3/rN4S+7qBXcVRZV+lIlW3YC5jdRL9l5uyOZWN8aOjXjBDwoS0JNbbs/R4 QcimWLXI3kuJdf8287aE+744N4XQHuZNArwZVywlXmKDeqMQ5DnPSn2Q2i7ndVxwQC1P VUY2OaJ/JsuLUkOAtrmSMw74mVLoIpPGWbHzgdKubhyT5sIUqlXHI8rb8ixceoFLTnFp X1s1RGipwE5Qh9/znsEX0l0j6Cy350ZPcrJQJ9R+DpzZzx2oPPBw0cjp/eRhXuhoHm++ INy3pDvd5JumZf5uYtKTjRLFnN96u7EQ0T6jdnr4DCI6jyi/nndjNCkz9Mcm589jhK0+ pTGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=wBV62S6hyP3GujCTK4VUSI3pqpLptAd4Jr8uZtcKQgo=; b=W/B3SoeQQn3KqQgRs4VIBW73GcKNjXTw6e3w2GuG7NmsbAvgh06f5X/7AUImZ8Bk0X mnc4d6SIli6MrkaCyr+qRASIrYEYvNKtX6zvSZMoMsUcvFPcVQsNhrBclK4bBAvoweZV XXSk7MUNi0jizdySXs1LogERhOsB6YmAX5zsw3RtMIGeNN5MQ+HeG5VegkYjiSFEPJIp HAx6m0cBMpzx2LuWW/H/uwpPiS9nMDisU5XnhTAZ+mKoQG6BnhBISqBCbdRvgNhYqB3h K19yY+RDu7Gng/rS2NgT8owrTz1PFi/++mOgEqotCthBXIr1wxcCZtf2zsWQIZ6z74SF Xdrw== X-Gm-Message-State: AHQUAub6bp19KzZkgP5zd6oTt0M4BDE/3g5okhPBlsETg+mJSP7vQlM3 xa+erzYrqD0ypUbk9uYGfHfppAvw X-Google-Smtp-Source: AHgI3Iaz+V45jpdots0vm6hH2Ckc9FQyuFxVDRmSwkQOdnCeytFNhZD322tRh8lcTH5tPzqXuc1XKg== X-Received: by 2002:a5d:6785:: with SMTP id v5mr4538075wru.59.1550866275481; Fri, 22 Feb 2019 12:11:15 -0800 (PST) Received: from localhost (112.68.155.104.bc.googleusercontent.com. [104.155.68.112]) by smtp.gmail.com with ESMTPSA id a1sm3288556wrq.96.2019.02.22.12.11.13 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 22 Feb 2019 12:11:13 -0800 (PST) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH 1/3] builtin/log: downcase the beginning of error messages Date: Fri, 22 Feb 2019 12:11:09 -0800 Message-Id: <20190222201111.98196-2-gitster@pobox.com> X-Mailer: git-send-email 2.21.0-rc2 In-Reply-To: <20190222201111.98196-1-gitster@pobox.com> References: <20190222201111.98196-1-gitster@pobox.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Junio C Hamano --- builtin/log.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/builtin/log.c b/builtin/log.c index 57869267d8..f2d1fbf18a 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -513,7 +513,7 @@ static int show_blob_object(const struct object_id *oid, struct rev_info *rev, c if (get_oid_with_context(the_repository, obj_name, GET_OID_RECORD_PATH, &oidc, &obj_context)) - die(_("Not a valid object name %s"), obj_name); + die(_("not a valid object name %s"), obj_name); if (!obj_context.path || !textconv_object(the_repository, obj_context.path, obj_context.mode, &oidc, 1, &buf, &size)) { @@ -537,7 +537,7 @@ static int show_tag_object(const struct object_id *oid, struct rev_info *rev) int offset = 0; if (!buf) - return error(_("Could not read object %s"), oid_to_hex(oid)); + return error(_("could not read object %s"), oid_to_hex(oid)); assert(type == OBJ_TAG); while (offset < size && buf[offset] != '\n') { @@ -631,7 +631,7 @@ int cmd_show(int argc, const char **argv, const char *prefix) break; o = parse_object(the_repository, &t->tagged->oid); if (!o) - ret = error(_("Could not read object %s"), + ret = error(_("could not read object %s"), oid_to_hex(&t->tagged->oid)); objects[i].item = o; i--; @@ -656,7 +656,7 @@ int cmd_show(int argc, const char **argv, const char *prefix) ret = cmd_log_walk(&rev); break; default: - ret = error(_("Unknown type: %d"), o->type); + ret = error(_("unknown type: %d"), o->type); } } free(objects); @@ -894,7 +894,7 @@ static int open_next_file(struct commit *commit, const char *subject, printf("%s\n", filename.buf + outdir_offset); if ((rev->diffopt.file = fopen(filename.buf, "w")) == NULL) { - error_errno(_("Cannot open patch file %s"), filename.buf); + error_errno(_("cannot open patch file %s"), filename.buf); strbuf_release(&filename); return -1; } @@ -911,7 +911,7 @@ static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids) unsigned flags1, flags2; if (rev->pending.nr != 2) - die(_("Need exactly one range.")); + die(_("need exactly one range.")); o1 = rev->pending.objects[0].item; o2 = rev->pending.objects[1].item; @@ -921,7 +921,7 @@ static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids) c2 = lookup_commit_reference(the_repository, &o2->oid); if ((flags1 & UNINTERESTING) == (flags2 & UNINTERESTING)) - die(_("Not a range.")); + die(_("not a range.")); init_patch_ids(the_repository, ids); @@ -1044,7 +1044,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout, struct commit *head = list[0]; if (!cmit_fmt_is_mail(rev->commit_format)) - die(_("Cover letter needs email format")); + die(_("cover letter needs email format")); committer = git_committer_info(0); @@ -1214,7 +1214,7 @@ static int output_directory_callback(const struct option *opt, const char *arg, const char **dir = (const char **)opt->value; BUG_ON_OPT_NEG(unset); if (*dir) - die(_("Two output directories?")); + die(_("two output directories?")); *dir = arg; return 0; } @@ -1321,7 +1321,7 @@ static struct commit *get_base_commit(const char *base_commit, if (base_commit && strcmp(base_commit, "auto")) { base = lookup_commit_reference_by_name(base_commit); if (!base) - die(_("Unknown commit %s"), base_commit); + die(_("unknown commit %s"), base_commit); } else if ((base_commit && !strcmp(base_commit, "auto")) || base_auto) { struct branch *curr_branch = branch_get(NULL); const char *upstream = branch_get_upstream(curr_branch, NULL); @@ -1331,16 +1331,16 @@ static struct commit *get_base_commit(const char *base_commit, struct object_id oid; if (get_oid(upstream, &oid)) - die(_("Failed to resolve '%s' as a valid ref."), upstream); + die(_("failed to resolve '%s' as a valid ref."), upstream); commit = lookup_commit_or_die(&oid, "upstream base"); base_list = get_merge_bases_many(commit, total, list); /* There should be one and only one merge base. */ if (!base_list || base_list->next) - die(_("Could not find exact merge base.")); + die(_("could not find exact merge base.")); base = base_list->item; free_commit_list(base_list); } else { - die(_("Failed to get upstream, if you want to record base commit automatically,\n" + die(_("failed to get upstream, if you want to record base commit automatically,\n" "please use git branch --set-upstream-to to track a remote branch.\n" "Or you could specify base commit by --base= manually.")); } @@ -1360,7 +1360,7 @@ static struct commit *get_base_commit(const char *base_commit, struct commit_list *merge_base; merge_base = get_merge_bases(rev[2 * i], rev[2 * i + 1]); if (!merge_base || merge_base->next) - die(_("Failed to find exact merge base")); + die(_("failed to find exact merge base")); rev[i] = merge_base->item; } @@ -1739,7 +1739,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) if (use_stdout) die(_("standard output, or directory, which one?")); if (mkdir(output_directory, 0777) < 0 && errno != EEXIST) - die_errno(_("Could not create directory '%s'"), + die_errno(_("could not create directory '%s'"), output_directory); } @@ -1941,7 +1941,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) if (!use_stdout && open_next_file(rev.numbered_files ? NULL : commit, NULL, &rev, quiet)) - die(_("Failed to create output files")); + die(_("failed to create output files")); shown = log_tree_commit(&rev, commit); free_commit_buffer(the_repository->parsed_objects, commit); @@ -2065,9 +2065,9 @@ int cmd_cherry(int argc, const char **argv, const char *prefix) revs.max_parents = 1; if (add_pending_commit(head, &revs, 0)) - die(_("Unknown commit %s"), head); + die(_("unknown commit %s"), head); if (add_pending_commit(upstream, &revs, UNINTERESTING)) - die(_("Unknown commit %s"), upstream); + die(_("unknown commit %s"), upstream); /* Don't say anything if head and upstream are the same. */ if (revs.pending.nr == 2) { @@ -2079,7 +2079,7 @@ int cmd_cherry(int argc, const char **argv, const char *prefix) get_patch_ids(&revs, &ids); if (limit && add_pending_commit(limit, &revs, UNINTERESTING)) - die(_("Unknown commit %s"), limit); + die(_("unknown commit %s"), limit); /* reverse the list of commits */ if (prepare_revision_walk(&revs)) From patchwork Fri Feb 22 20:11:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 10826937 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 462251390 for ; Fri, 22 Feb 2019 20:11:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 34849321FA for ; Fri, 22 Feb 2019 20:11:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2942F322DE; Fri, 22 Feb 2019 20:11:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C84F3321FA for ; Fri, 22 Feb 2019 20:11:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726610AbfBVULU (ORCPT ); Fri, 22 Feb 2019 15:11:20 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:33030 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726261AbfBVULT (ORCPT ); Fri, 22 Feb 2019 15:11:19 -0500 Received: by mail-wm1-f68.google.com with SMTP id h22so9629444wmb.0 for ; Fri, 22 Feb 2019 12:11:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZNDxXppE7nH0fWCErNbMZhZ1yF5puIu3VXNpVSWJHrQ=; b=KdCAV/ziBJC0otZCAjytpwgkltEFWP8jLAPdyO8MDSwDnJTL9wRkZ6x8qj9lPQWKBl esbBFp8COPz5oyq2p2iHIPo6a5fpypG6yA/QrPBURvVv0Uz8xMVb8pfe7KW94xTPRlG5 KyBpAiq9Xhyw7E/XYKKD7M2u6KlrqbcgsIbw6u8ljahffBQTfPnKcqs7s0woMbQkTjfM QJwcjX7o3AI9diN+iyMxpKTEVGn6YCm88n/LlwDUr+Oyv8t9nLEKh+CDJb9C5fY2ncob sRFelk+yU09SKGwbEkykQKI/1QIn9cS3uH7arSW1W7FUvABKg5BeNMD2XQyuXk/N8pFO DCpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=ZNDxXppE7nH0fWCErNbMZhZ1yF5puIu3VXNpVSWJHrQ=; b=EKBPUHaLKRlsEnuPMN/Z2nEdmsT2CBIgbTXWVMxJK/A+iF2b0DYHb42v64oGbVeOz+ dL1pmYiQ3ZYnq9l6WQonFlHoFTLazxsRgJqhiP/Wm80Ta3cI4XAQsQVOJA3a/RrAPNyY nNJNB2VpeaQEJl2SBbR5KdyDcJ+2zFf6MdRy7C34l72LFcziHIXvX3y7hwhoD1/O8AjB TbjeOGlULW8FMETiFt2Fx488XZyk80ms/C/GjLBRZh6I7jLhBI4W6y+1Ni57DdgijIZ5 36bEziw+N4b4XUSaRWSBLXcQwhOHemux6Ny3Ddzg5DYiQzOsRrB6SQipeEzgmTN2n9Xg TFfw== X-Gm-Message-State: AHQUAuYI3h/YuU6ieGvlGWE3fLJ4dNTtCwSGmlyZ/JSw2d5LCj2BY02s eIC+TmBYKbWKyocOWK/Y2yF0fMJF X-Google-Smtp-Source: AHgI3IY22O8rHVNuZ9q/UnJdUEpulNAsoi8snUser7rRxcPyNb9kvpIKQ8p7H4yhTY+vNjOv/t/Kvw== X-Received: by 2002:a1c:e701:: with SMTP id e1mr3456416wmh.1.1550866277191; Fri, 22 Feb 2019 12:11:17 -0800 (PST) Received: from localhost (168.50.187.35.bc.googleusercontent.com. [35.187.50.168]) by smtp.gmail.com with ESMTPSA id c8sm1312116wrx.6.2019.02.22.12.11.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 22 Feb 2019 12:11:15 -0800 (PST) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH 2/3] format-patch: notice failure to open cover letter for writing Date: Fri, 22 Feb 2019 12:11:10 -0800 Message-Id: <20190222201111.98196-3-gitster@pobox.com> X-Mailer: git-send-email 2.21.0-rc2 In-Reply-To: <20190222201111.98196-1-gitster@pobox.com> References: <20190222201111.98196-1-gitster@pobox.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The make_cover_letter() function is supposed to open a new file for writing, and let the caller write into it via FILE *rev->diffopt.file but because the function does not return anything, the caller does not bother checking the return value. Make sure it dies, instead of keep going with a NULL output filestream and relying on it to cause a crash, when it fails to open the file. Signed-off-by: Junio C Hamano --- builtin/log.c | 2 +- t/t4014-format-patch.sh | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/builtin/log.c b/builtin/log.c index f2d1fbf18a..ca86611efe 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -1050,7 +1050,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout, if (!use_stdout && open_next_file(NULL, rev->numbered_files ? NULL : "cover-letter", rev, quiet)) - return; + die(_("failed to create cover-letter file")); log_write_email_headers(rev, head, &pp.after_subject, &need_8bit_cte, 0); diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh index 909c743c13..b6e2fdbc44 100755 --- a/t/t4014-format-patch.sh +++ b/t/t4014-format-patch.sh @@ -589,6 +589,12 @@ test_expect_success 'excessive subject' ' ls patches/0004-This-is-an-excessively-long-subject-line-for-a-messa.patch ' +test_expect_success 'failure to write cover-letter aborts gracefully' ' + test_when_finished "rmdir 0000-cover-letter.patch" && + mkdir 0000-cover-letter.patch && + test_must_fail git format-patch --no-renames --cover-letter -1 +' + test_expect_success 'cover-letter inherits diff options' ' git mv file foo && git commit -m foo && From patchwork Fri Feb 22 20:11:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 10826939 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5B2AA922 for ; Fri, 22 Feb 2019 20:11:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 49E03316FD for ; Fri, 22 Feb 2019 20:11:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3E5FF32211; Fri, 22 Feb 2019 20:11:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1AE6F321FA for ; Fri, 22 Feb 2019 20:11:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726023AbfBVULW (ORCPT ); Fri, 22 Feb 2019 15:11:22 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:51466 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726770AbfBVULW (ORCPT ); Fri, 22 Feb 2019 15:11:22 -0500 Received: by mail-wm1-f65.google.com with SMTP id n19so3039788wmi.1 for ; Fri, 22 Feb 2019 12:11:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MYg+qRPhzgJQ5b9SjZSbZuWQ/CsSGE+0ce2fhPvM/X8=; b=BWpsUmTErhMADcEQq93COE0NtRBI3PGgWEuZUtWm9cly8JaRq3jxvF+5najWAKX4TJ eyoI+IB8gfC1ylt9Y34qJbvohkMlUlRPo3MTK/jCf+4j0hh4iUilx2+E6kGvj55RUGKY 8ttQtBARg/HJon6zCYh3mqdlQYLr+Mnr4QIoMu6Wd8nZCKIKIjpGi5jc5Jg2mTRbJGkc e/Q38BTq8yGBCrZP6nRJyjGsIpiU2NQM6OK2f4y4NlGZVzkW/nMSX1Vg/Ju/uMpaRdFm NMzYSvudt1NoGgcOG7K9qJPdYjJQ4Dl4CJe14BJ60YRg9lrV+hYnCRMjz3ShF52Ag1qW KLIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=MYg+qRPhzgJQ5b9SjZSbZuWQ/CsSGE+0ce2fhPvM/X8=; b=WegAi8J04e/sUJN96Cyoi9T1qmjKuUFB0otjqVl+YxWjSQ3+4xtaQ3WojhoAODSYSt isL1rm2kR++MrGNfymD0VzUqQKPueaT69h8rEFQCY08tPN+aKwaVdwxnXGebsw2BUHqa IGWCmJOu0ly6jKuUsJEqmD4i6AimBjJSBE7+9zzgAOU+1HfSM/alGT0WMu6OYLhTAyRe 4YCXKYtUfZQJh8ziRgwaTV39Gr0q2AhIs8wyilUn2x05EDCJPImbOVeD015Ap8NgmmPP iEY9Cl6oO4sKrnvkxiDbxjPIg/elIFDI7JiOl4/RYUjQ1SL2qHhCarx2UtOmDgkmmKIL zuTg== X-Gm-Message-State: AHQUAuYSqrhHiboMlgTyzuf/UedlkJEKkezKyHyZQgkYbK6es9juJMe3 l7DpE/LpiDLCE2Vu127pwfJ7jezI X-Google-Smtp-Source: AHgI3IZmoxyJY90dnCyWWBLppilldHq5rliddjD+qnslBd6KDgd64wWfdNBdwC01w3c6BDIHaWoHQw== X-Received: by 2002:a05:600c:224c:: with SMTP id a12mr3464541wmm.103.1550866279644; Fri, 22 Feb 2019 12:11:19 -0800 (PST) Received: from localhost (168.50.187.35.bc.googleusercontent.com. [35.187.50.168]) by smtp.gmail.com with ESMTPSA id a1sm3288830wrq.96.2019.02.22.12.11.17 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 22 Feb 2019 12:11:17 -0800 (PST) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH 3/3] format-patch: --no-clobber refrains from overwriting output files Date: Fri, 22 Feb 2019 12:11:11 -0800 Message-Id: <20190222201111.98196-4-gitster@pobox.com> X-Mailer: git-send-email 2.21.0-rc2 In-Reply-To: <20190222201111.98196-1-gitster@pobox.com> References: <20190222201111.98196-1-gitster@pobox.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If you keep an output for an older iteration of the same topic in the same directory around and use "git format-patch" to prepare a newer iteration of the topic, those commits that happen to be at the same position in the series that have not been retitled will get the same filename---and the command opens them for writing without any check. Existing "-o outdir" and "-v number" options are both good ways to avoid such name collisions, and in general helps to give good ways to compare the latest iteration with older iteration(s), but let's see if "--no-clobber" option that forbids overwrting existing files would also help people. Signed-off-by: Junio C Hamano --- Documentation/git-format-patch.txt | 8 +++++++- builtin/log.c | 32 ++++++++++++++++++++++++------ t/t4014-format-patch.sh | 16 +++++++++++++++ 3 files changed, 49 insertions(+), 7 deletions(-) diff --git a/Documentation/git-format-patch.txt b/Documentation/git-format-patch.txt index 1af85d404f..540822b3b4 100644 --- a/Documentation/git-format-patch.txt +++ b/Documentation/git-format-patch.txt @@ -25,7 +25,7 @@ SYNOPSIS [--[no-]cover-letter] [--quiet] [--notes[=]] [--interdiff=] [--range-diff= [--creation-factor=]] - [--progress] + [--progress] [--[no-]clobber] [] [ | ] @@ -93,6 +93,12 @@ include::diff-options.txt[] Use to store the resulting files, instead of the current working directory. +--clobber:: +--no-clobber:: + (experimental) + Allow overwriting existing files, which is the default. To + make the command refrain from overwriting, use `--no-clobber`. + -n:: --numbered:: Name output in '[PATCH n/m]' format, even with a single patch. diff --git a/builtin/log.c b/builtin/log.c index ca86611efe..7421f1cc93 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -867,8 +867,16 @@ static int git_format_config(const char *var, const char *value, void *cb) static const char *output_directory = NULL; static int outdir_offset; +static FILE *fopen_excl(const char *filename) +{ + int fd = open(filename, O_CREAT | O_EXCL | O_WRONLY, 0666); + if (fd < 0) + return NULL; + return fdopen(fd, "w"); +} + static int open_next_file(struct commit *commit, const char *subject, - struct rev_info *rev, int quiet) + struct rev_info *rev, int quiet, int clobber) { struct strbuf filename = STRBUF_INIT; int suffix_len = strlen(rev->patch_suffix) + 1; @@ -893,7 +901,12 @@ static int open_next_file(struct commit *commit, const char *subject, if (!quiet) printf("%s\n", filename.buf + outdir_offset); - if ((rev->diffopt.file = fopen(filename.buf, "w")) == NULL) { + if (clobber) + rev->diffopt.file = fopen(filename.buf, "w"); + else + rev->diffopt.file = fopen_excl(filename.buf); + + if (!rev->diffopt.file) { error_errno(_("cannot open patch file %s"), filename.buf); strbuf_release(&filename); return -1; @@ -1030,7 +1043,8 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout, struct commit *origin, int nr, struct commit **list, const char *branch_name, - int quiet) + int quiet, + int clobber) { const char *committer; const char *body = "*** SUBJECT HERE ***\n\n*** BLURB HERE ***\n"; @@ -1049,7 +1063,8 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout, committer = git_committer_info(0); if (!use_stdout && - open_next_file(NULL, rev->numbered_files ? NULL : "cover-letter", rev, quiet)) + open_next_file(NULL, rev->numbered_files ? NULL : "cover-letter", + rev, quiet, clobber)) die(_("failed to create cover-letter file")); log_write_email_headers(rev, head, &pp.after_subject, &need_8bit_cte, 0); @@ -1509,6 +1524,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) struct strbuf buf = STRBUF_INIT; int use_patch_format = 0; int quiet = 0; + int clobber = 1; int reroll_count = -1; char *branch_name = NULL; char *base_commit = NULL; @@ -1595,6 +1611,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) OPT__QUIET(&quiet, N_("don't print the patch filenames")), OPT_BOOL(0, "progress", &show_progress, N_("show progress while generating patches")), + OPT_BOOL(0, "clobber", &clobber, + N_("allow overwriting output files")), OPT_CALLBACK(0, "interdiff", &idiff_prev, N_("rev"), N_("show changes against in cover letter or single patch"), parse_opt_object_name), @@ -1885,7 +1903,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) if (thread) gen_message_id(&rev, "cover"); make_cover_letter(&rev, use_stdout, - origin, nr, list, branch_name, quiet); + origin, nr, list, branch_name, + quiet, clobber); print_bases(&bases, rev.diffopt.file); print_signature(rev.diffopt.file); total++; @@ -1940,7 +1959,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) } if (!use_stdout && - open_next_file(rev.numbered_files ? NULL : commit, NULL, &rev, quiet)) + open_next_file(rev.numbered_files ? NULL : commit, NULL, + &rev, quiet, clobber)) die(_("failed to create output files")); shown = log_tree_commit(&rev, commit); free_commit_buffer(the_repository->parsed_objects, diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh index b6e2fdbc44..384a1fd9e7 100755 --- a/t/t4014-format-patch.sh +++ b/t/t4014-format-patch.sh @@ -595,6 +595,22 @@ test_expect_success 'failure to write cover-letter aborts gracefully' ' test_must_fail git format-patch --no-renames --cover-letter -1 ' +test_expect_success 'refrain from overwriting a patch with --no-clobber' ' + rm -f 000[01]-*.patch && + git format-patch --no-clobber --no-renames --cover-letter -1 >filelist && + # empty the files output by the command ... + for f in $(cat filelist) + do + : >"$f" || return 1 + done && + test_must_fail git format-patch --no-clobber --cover-letter --no-renames -1 && + # ... and make sure they stay empty + for f in $(cat filelist) + do + ! test -s "$f" || return 1 + done +' + test_expect_success 'cover-letter inherits diff options' ' git mv file foo && git commit -m foo &&