From patchwork Thu Sep 9 23:24:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 12484151 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3730C433FE for ; Thu, 9 Sep 2021 23:24:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D3E096108B for ; Thu, 9 Sep 2021 23:24:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349555AbhIIXZn (ORCPT ); Thu, 9 Sep 2021 19:25:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230367AbhIIXZl (ORCPT ); Thu, 9 Sep 2021 19:25:41 -0400 Received: from mail-il1-x135.google.com (mail-il1-x135.google.com [IPv6:2607:f8b0:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1A48C061575 for ; Thu, 9 Sep 2021 16:24:31 -0700 (PDT) Received: by mail-il1-x135.google.com with SMTP id q14so100912ils.5 for ; Thu, 09 Sep 2021 16:24:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=jVjmHPs9Vzn+FL0BItXKX43L71zgap2RPxsgO9/F3J4=; b=CaJ6lF9+siHmTQlNvqRfONnAZIOHvgwK2Glk+hhVYmJ7mxxqTBFK/Q+DvaX4IXWqkP 9m9hjS7vLbffjKZ50sq3Cnt84D9olUlPuYXYSHr0ofttQKbZpGE5858oumjXbCvyw2fT gqHKLnkVNhadU3jmT1SI7pGFaz12lR9ViKdp2w5YzFttbKRJy7EvcN12oTqlkOHFIivd DvVSuVje68FOOoI3+GHkp1OgLARpjG4n+cRe370BTYzkSdq3W1lYPkEHhKlAfaTsYY9d vwnxMwtjuZqB49gv1jvv78+q5aljdp7256cNi0+oQo29RVqxEfzr4bNtBOztwcVVp2YX WJRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=jVjmHPs9Vzn+FL0BItXKX43L71zgap2RPxsgO9/F3J4=; b=MFovf/C5xeOY4b+u9iJgdojx77UbAv5k7Z4P5+ht+CXA+CACr76Cc2urUFfHnqIemE uS8sPmry70b+Yd1ZwR6g8AGniiKJk34W4HHOrpiws5uecyOLOsnmi4ea57+tQmuNHiPq PHixkHVKGbcctu5zmGiVmxb5Eb8oqdPimKcbKlx1az+KowGsk4yTZghyATpqRYaRHSFX ozXxr+ceAlckO6xwi4lFopuTM8LRb5xqS84f6N3PlYAbYyMFLhDJPYOvD6HV8bYzzNQH 9K80O1/1ODKfQmK/tHMNDaS0D5Ph3JM57XJWRJ0G4W10Gqg3Qt1Dr34Ay1im5q25KXE+ QeXQ== X-Gm-Message-State: AOAM530HM+cLASRjQ6fAOlnYZyXCWNZ48pChBS1gV3AEJ6BttzR5rtb4 CqFXw5Vac09btwqKPjVjyhvJJxMNJoHoyNbr X-Google-Smtp-Source: ABdhPJyn/CwZUKffkxJbI0JsVOQgOE74VTner8iGDHqv+hf/uDnqNKul3xtaajLJjyoYYolNlVbdRw== X-Received: by 2002:a92:cb4b:: with SMTP id f11mr4255731ilq.189.1631229871281; Thu, 09 Sep 2021 16:24:31 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id y27sm1582735iot.10.2021.09.09.16.24.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Sep 2021 16:24:30 -0700 (PDT) Date: Thu, 9 Sep 2021 19:24:30 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: avarab@gmail.com, gitster@pobox.com Subject: [PATCH v2 1/9] pack.h: line-wrap the definition of finish_tmp_packfile() Message-ID: <0b07aa4947caff53878a9000e2866f98146e2ccd.1631228928.git.me@ttaylorr.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Ævar Arnfjörð Bjarmason Line-wrap the definition of finish_tmp_packfile() to make subsequent changes easier to read. See 0e990530ae (finish_tmp_packfile(): a helper function, 2011-10-28) for the commit that introduced this overly long line. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Taylor Blau --- pack.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pack.h b/pack.h index fa13954526..1c17254c0a 100644 --- a/pack.h +++ b/pack.h @@ -110,6 +110,11 @@ int encode_in_pack_object_header(unsigned char *hdr, int hdr_len, int read_pack_header(int fd, struct pack_header *); struct hashfile *create_tmp_packfile(char **pack_tmp_name); -void finish_tmp_packfile(struct strbuf *name_buffer, const char *pack_tmp_name, struct pack_idx_entry **written_list, uint32_t nr_written, struct pack_idx_option *pack_idx_opts, unsigned char sha1[]); +void finish_tmp_packfile(struct strbuf *name_buffer, + const char *pack_tmp_name, + struct pack_idx_entry **written_list, + uint32_t nr_written, + struct pack_idx_option *pack_idx_opts, + unsigned char sha1[]); #endif From patchwork Thu Sep 9 23:24:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 12484153 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 24FA1C433F5 for ; Thu, 9 Sep 2021 23:24:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 09CE1610E8 for ; Thu, 9 Sep 2021 23:24:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349658AbhIIXZs (ORCPT ); Thu, 9 Sep 2021 19:25:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349580AbhIIXZo (ORCPT ); Thu, 9 Sep 2021 19:25:44 -0400 Received: from mail-il1-x12e.google.com (mail-il1-x12e.google.com [IPv6:2607:f8b0:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95185C061575 for ; Thu, 9 Sep 2021 16:24:34 -0700 (PDT) Received: by mail-il1-x12e.google.com with SMTP id v16so80683ilo.10 for ; Thu, 09 Sep 2021 16:24:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=Mzrow7ycQLXalkEw2wrFECFsQ3V8XGkViNlR9HvpOsc=; b=m3MEHk7ucS3iQLiEYvsXeUAj5YvCLqlSKzOA7p2pLczHqv7eBhIhQEUDxVZOyBjF63 r4ZRSwU16MLQwS33uS2Jj7neBS0pFIcRiBQ7N9leQmoaL86VWRUJAWKb0QjhAWjf9P8b lr7ZyFV4ieqPzpNfvAgibZfYb3u0Mo8c+LkNndXCbTNOLmhQ9F7qR6Pt06LT68K6gx/c vXPCNoO5ocA5nN5bSRITaZzL2lfvwkt8loc6FsmWKKgPddBxgDJGZSa3/qiRERT/bpZ9 2r0JOwd+7qWljJx13JM3fKpQwWHUyIONmsFGVY/n4prggDFidMBA8V3cXoZs3Xq7p/hN oXoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Mzrow7ycQLXalkEw2wrFECFsQ3V8XGkViNlR9HvpOsc=; b=IEG0IoX3UdqVhyWaACRHPpcdPW4XiriJw6IhMm8CRJrpoLlcEoHz/g3tU1DyMkdZoF n+9REzUOjCrt9F4izAihCyHwUBCy0B6USb1y82hivLra8ckzAye70FLNK+sAGzTeILbH e4fVuOPyHXmvVUlKOh2Mkb1Wu5EvZTnviizuSwP/PuwvcHmkuNznrmhC/IjnF/EnOy9G lo0iFGGkkuv7y25C+MXewXw404fJaQIxXCDwvMYfFRi8TgWH60twBNpxzM81Qlb88Oc5 BxhoAkMs0nlrGzbS83On/kn5iDgZimE5dpTNi2qgJoaf3x7MIEP9VBl83mCsQizmYs9i tQLw== X-Gm-Message-State: AOAM530jX01IICGW8sPZ/QJMiOhnhv4oZsDYEVC55XZsXz7zQjNdRSNA Z83fPFrxXtTXTZ76ejTks3+6yokaHOQm10PB X-Google-Smtp-Source: ABdhPJzbQa0y4bjdDvK1awPhTfKA8TXBird6fF701AtwRTPhzZsBMSAQxRg9D66UDgxpiXoQUxMoBg== X-Received: by 2002:a92:6b0a:: with SMTP id g10mr4039724ilc.27.1631229873865; Thu, 09 Sep 2021 16:24:33 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id s7sm1584005ioc.42.2021.09.09.16.24.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Sep 2021 16:24:33 -0700 (PDT) Date: Thu, 9 Sep 2021 19:24:32 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: avarab@gmail.com, gitster@pobox.com Subject: [PATCH v2 2/9] bulk-checkin.c: store checksum directly Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org finish_bulk_checkin() stores the checksum from finalize_hashfile() by writing to the `hash` member of `struct object_id`, but that hash has nothing to do with an object id (it's just a convenient location that happens to be sized correctly). Store the hash directly in an unsigned char array. This behaves the same as writing to the `hash` member, but makes the intent clearer (and avoids allocating an extra four bytes for the `algo` member of `struct object_id`). It likewise prevents the possibility of a segfault when reading `algo` (e.g., by calling `oid_to_hex()`) if it is uninitialized. Signed-off-by: Taylor Blau --- bulk-checkin.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bulk-checkin.c b/bulk-checkin.c index b023d9959a..6283bc8bd9 100644 --- a/bulk-checkin.c +++ b/bulk-checkin.c @@ -25,7 +25,7 @@ static struct bulk_checkin_state { static void finish_bulk_checkin(struct bulk_checkin_state *state) { - struct object_id oid; + unsigned char hash[GIT_MAX_RAWSZ]; struct strbuf packname = STRBUF_INIT; int i; @@ -37,11 +37,11 @@ static void finish_bulk_checkin(struct bulk_checkin_state *state) unlink(state->pack_tmp_name); goto clear_exit; } else if (state->nr_written == 1) { - finalize_hashfile(state->f, oid.hash, CSUM_HASH_IN_STREAM | CSUM_FSYNC | CSUM_CLOSE); + finalize_hashfile(state->f, hash, CSUM_HASH_IN_STREAM | CSUM_FSYNC | CSUM_CLOSE); } else { - int fd = finalize_hashfile(state->f, oid.hash, 0); - fixup_pack_header_footer(fd, oid.hash, state->pack_tmp_name, - state->nr_written, oid.hash, + int fd = finalize_hashfile(state->f, hash, 0); + fixup_pack_header_footer(fd, hash, state->pack_tmp_name, + state->nr_written, hash, state->offset); close(fd); } @@ -49,7 +49,7 @@ static void finish_bulk_checkin(struct bulk_checkin_state *state) strbuf_addf(&packname, "%s/pack/pack-", get_object_directory()); finish_tmp_packfile(&packname, state->pack_tmp_name, state->written, state->nr_written, - &state->pack_idx_opts, oid.hash); + &state->pack_idx_opts, hash); for (i = 0; i < state->nr_written; i++) free(state->written[i]); From patchwork Thu Sep 9 23:24:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 12484155 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 18723C433EF for ; Thu, 9 Sep 2021 23:24:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BFF106108B for ; Thu, 9 Sep 2021 23:24:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349523AbhIIXZv (ORCPT ); Thu, 9 Sep 2021 19:25:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349505AbhIIXZt (ORCPT ); Thu, 9 Sep 2021 19:25:49 -0400 Received: from mail-il1-x134.google.com (mail-il1-x134.google.com [IPv6:2607:f8b0:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C796C061575 for ; Thu, 9 Sep 2021 16:24:39 -0700 (PDT) Received: by mail-il1-x134.google.com with SMTP id a1so97334ilj.6 for ; Thu, 09 Sep 2021 16:24:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=bxlP6grsu7AHCij5ooE7s+bVcCw7x0vhJi9PjutdNts=; b=CZ/59zp9oG2eqbKlj2army5YRs45Faed/J+mIy/jAJmCz9Bza9dd+WkQdjZQFUBNt1 wZARIxa4fsA0IPS7VigaQOfS2VE/ZXT0jmreP30mzSqsSmdwKGjdSNbtf+R31wwOeWX9 7PRi09wld9r0QP43qhiMSpm8KZDsBZyJtf3QxAAyAtLf2o4wkTU3ucqDRjh0oFfZDFJr 1EpnHHj+kIA7NFoYi1L5ZnJj7f5YaXpaXZ5o6Ga8hE3+hPnhWIVejkzpzr6f8N6puOXJ CjgGXGe26AEANX/ibq83vVSfe8ejEZ4+taBrbTA50z6VWZ8FEruoW5h6ELBVNdqtuTyf CaCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=bxlP6grsu7AHCij5ooE7s+bVcCw7x0vhJi9PjutdNts=; b=73By5H72zzMvgcPXtOcLV02iya7zt/D8WfXzqi9jZPEdHUY92c9PPRt6dxUZX1lOvu TyOdaaP3hJ4mqAo/e9uS+JT9W0A4uLDLjmkNKprP7Q+SwfNHkj8/HNqId5WUneUFDwMN LezT2e2puz5WoD9dJ3iZmX0NvnJ9UzmzmONwSjffJh2Tkg8DzZ4TJERdL+48/zxJ6uBU hJETKchfjffsY/vWg5OEONFE4QPGL8pw2r/xiF/X8ScVGmhXBaks+jsYl22olOr5tkTf tAzoLUh4jPd+q8P1og2q4cTZQPcTKRglKIuRu8eZgoviYtuFMCCX6m+wbGc58DuZ5udq UjRw== X-Gm-Message-State: AOAM530ScKu1IW9lAh+gNfmD3a5RYdNg9fRlFP7nVAVv3Nt2BOnx6s6/ r0WCOuSkCVEvMSHSko+1FIO902Oyhyi5AVpR X-Google-Smtp-Source: ABdhPJxYxWQAFMGC14ZFpihY1Fp2zrj6zsQcR1hixiFB/+ZTmsZblyAwUuiXSzhus0x8EMfY3bEXdQ== X-Received: by 2002:a92:c6cf:: with SMTP id v15mr210853ilm.106.1631229878771; Thu, 09 Sep 2021 16:24:38 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id c11sm1657961ilu.74.2021.09.09.16.24.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Sep 2021 16:24:38 -0700 (PDT) Date: Thu, 9 Sep 2021 19:24:37 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: avarab@gmail.com, gitster@pobox.com Subject: [PATCH v2 3/9] pack-write: refactor renaming in finish_tmp_packfile() Message-ID: <2e907e309de6804c329a9efb6a6d89fb318683f3.1631228928.git.me@ttaylorr.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Ævar Arnfjörð Bjarmason Refactor the renaming in finish_tmp_packfile() into a helper function. The callers are now expected to pass a "name_buffer" ending in "pack-OID." instead of the previous "pack-", we then append "pack", "idx" or "rev" to it. By doing the strbuf_setlen() in rename_tmp_packfile() we reuse the buffer and avoid the repeated allocations we'd get if that function had its own temporary "struct strbuf". This approach of reusing the buffer does make the last user in pack-object.c's write_pack_file() slightly awkward, since we needlessly do a strbuf_setlen() before calling strbuf_release() for consistency. In subsequent changes we'll move that bitmap writing code around, so let's not skip the strbuf_setlen() now. The previous strbuf_reset() idiom originated with 5889271114a (finish_tmp_packfile():use strbuf for pathname construction, 2014-03-03), which in turn was a minimal adjustment of pre-strbuf code added in 0e990530ae (finish_tmp_packfile(): a helper function, 2011-10-28). Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Taylor Blau --- builtin/pack-objects.c | 7 +++++-- bulk-checkin.c | 3 ++- pack-write.c | 37 ++++++++++++++++--------------------- 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index df49f656b9..2a105c8d6e 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -1237,7 +1237,8 @@ static void write_pack_file(void) warning_errno(_("failed utime() on %s"), pack_tmp_name); } - strbuf_addf(&tmpname, "%s-", base_name); + strbuf_addf(&tmpname, "%s-%s.", base_name, + hash_to_hex(hash)); if (write_bitmap_index) { bitmap_writer_set_checksum(hash); @@ -1250,8 +1251,9 @@ static void write_pack_file(void) &pack_idx_opts, hash); if (write_bitmap_index) { - strbuf_addf(&tmpname, "%s.bitmap", hash_to_hex(hash)); + size_t tmpname_len = tmpname.len; + strbuf_addstr(&tmpname, "bitmap"); stop_progress(&progress_state); bitmap_writer_show_progress(progress); @@ -1260,6 +1262,7 @@ static void write_pack_file(void) bitmap_writer_finish(written_list, nr_written, tmpname.buf, write_bitmap_options); write_bitmap_index = 0; + strbuf_setlen(&tmpname, tmpname_len); } strbuf_release(&tmpname); diff --git a/bulk-checkin.c b/bulk-checkin.c index 6283bc8bd9..c19d471f0b 100644 --- a/bulk-checkin.c +++ b/bulk-checkin.c @@ -46,7 +46,8 @@ static void finish_bulk_checkin(struct bulk_checkin_state *state) close(fd); } - strbuf_addf(&packname, "%s/pack/pack-", get_object_directory()); + strbuf_addf(&packname, "%s/pack/pack-%s.", get_object_directory(), + hash_to_hex(hash)); finish_tmp_packfile(&packname, state->pack_tmp_name, state->written, state->nr_written, &state->pack_idx_opts, hash); diff --git a/pack-write.c b/pack-write.c index 2767b78619..58bc5fbcdf 100644 --- a/pack-write.c +++ b/pack-write.c @@ -458,6 +458,18 @@ struct hashfile *create_tmp_packfile(char **pack_tmp_name) return hashfd(fd, *pack_tmp_name); } +static void rename_tmp_packfile(struct strbuf *name_prefix, const char *source, + const char *ext) +{ + size_t name_prefix_len = name_prefix->len; + + strbuf_addstr(name_prefix, ext); + if (rename(source, name_prefix->buf)) + die_errno("unable to rename temporary file to '%s'", + name_prefix->buf); + strbuf_setlen(name_prefix, name_prefix_len); +} + void finish_tmp_packfile(struct strbuf *name_buffer, const char *pack_tmp_name, struct pack_idx_entry **written_list, @@ -466,7 +478,6 @@ void finish_tmp_packfile(struct strbuf *name_buffer, unsigned char hash[]) { const char *idx_tmp_name, *rev_tmp_name = NULL; - int basename_len = name_buffer->len; if (adjust_shared_perm(pack_tmp_name)) die_errno("unable to make temporary pack file readable"); @@ -479,26 +490,10 @@ void finish_tmp_packfile(struct strbuf *name_buffer, rev_tmp_name = write_rev_file(NULL, written_list, nr_written, hash, pack_idx_opts->flags); - strbuf_addf(name_buffer, "%s.pack", hash_to_hex(hash)); - - if (rename(pack_tmp_name, name_buffer->buf)) - die_errno("unable to rename temporary pack file"); - - strbuf_setlen(name_buffer, basename_len); - - strbuf_addf(name_buffer, "%s.idx", hash_to_hex(hash)); - if (rename(idx_tmp_name, name_buffer->buf)) - die_errno("unable to rename temporary index file"); - - strbuf_setlen(name_buffer, basename_len); - - if (rev_tmp_name) { - strbuf_addf(name_buffer, "%s.rev", hash_to_hex(hash)); - if (rename(rev_tmp_name, name_buffer->buf)) - die_errno("unable to rename temporary reverse-index file"); - } - - strbuf_setlen(name_buffer, basename_len); + rename_tmp_packfile(name_buffer, pack_tmp_name, "pack"); + rename_tmp_packfile(name_buffer, idx_tmp_name, "idx"); + if (rev_tmp_name) + rename_tmp_packfile(name_buffer, rev_tmp_name, "rev"); free((void *)idx_tmp_name); } From patchwork Thu Sep 9 23:24:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 12484157 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 48DBBC433F5 for ; Thu, 9 Sep 2021 23:24:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3231E610C9 for ; Thu, 9 Sep 2021 23:24:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349612AbhIIXZ4 (ORCPT ); Thu, 9 Sep 2021 19:25:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349759AbhIIXZx (ORCPT ); Thu, 9 Sep 2021 19:25:53 -0400 Received: from mail-il1-x133.google.com (mail-il1-x133.google.com [IPv6:2607:f8b0:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3CFEDC061575 for ; Thu, 9 Sep 2021 16:24:43 -0700 (PDT) Received: by mail-il1-x133.google.com with SMTP id h29so112996ila.2 for ; Thu, 09 Sep 2021 16:24:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=wLMUPGNiWOFGKyR1RJpDMuyvM/DALCGBKEAxDmj/rwA=; b=lM9IBDwcWbNBdcqdJh8bOZEWH4v4GTigHAPZOsqayCN2HVcE/ghff+XpA815mXA9KW 1NV65qz/ds/hBnnub58cZo06w/6/8yuB2+MAcl3kYYbSVBGhhLlpik0yzdXbZOktYpOv hhclUCidYdoIhnAaWEIA1jb7uaSeqMJjk7cqGiIrus7gXRI9RUWlzh0gG6RMm6aK/ar9 b5kv7okbzfxk521USS/aSuz9I/vOo80nNNCDD7+7SyZV33CbXfPM0EKCBbBOoVXnc/17 aqm98PbDq7c80HgrVJa+uE/DU3TGaqH+Lgg/mLbh4f8RAFVj3OJF8Nf7w6hJKCfgem2/ oH6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=wLMUPGNiWOFGKyR1RJpDMuyvM/DALCGBKEAxDmj/rwA=; b=U1k6Y4B0/tNQ8Dm4RXV9mmNV4XAFjcnfJNs31R++F00HPoH9jO2WXMtBNH3tJYG0Pb 8PpMunmBdZ3irJ2xlG83aoTZ15sXy5LmVOX4bQZ1t2WwRk3wMVB757z6tuUOh42297qK STjqwG8v2Udn8FsOgJWa7pCo3jNlLtXuvw2zgI96LAbEbBdluxzWMnowt9vEWj3ORDuk g8/hzbtFmn/EbbPe1FBhwHrR5iQ+tO8kQ5I0kHlVg5Lkayz/H1UvWZKvEtyOpMlalMR5 y09697tPBgPQDNhCk7+EnJL96zKj2ifAHre74Q8EfTd1YkAoeJelsplncIVpICvyYbel TDtw== X-Gm-Message-State: AOAM530+hQnOxPGuRb8ve23QDeu/ZF9vL4oIuSIeXM9uN/NyYRRpuWKM 8owHNxFu1fhnV0aVpAgAV+jXuvjeUO4oVlwx X-Google-Smtp-Source: ABdhPJz3RHJXLlHjFtxNyK/qRJ7Yz3OS2q7/lavpMktEzDNbmk1GtEm3Vj8FegmS3spq8g29TGijkQ== X-Received: by 2002:a92:6a02:: with SMTP id f2mr4314615ilc.19.1631229882531; Thu, 09 Sep 2021 16:24:42 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id m26sm1572734ioj.54.2021.09.09.16.24.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Sep 2021 16:24:42 -0700 (PDT) Date: Thu, 9 Sep 2021 19:24:41 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: avarab@gmail.com, gitster@pobox.com Subject: [PATCH v2 4/9] pack-write.c: rename `.idx` files after `*.rev` Message-ID: <41d34b1f180350c466243ed5aa7f6a48a2ff2aeb.1631228928.git.me@ttaylorr.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org We treat the presence of an `.idx` file as the indicator of whether or not it's safe to use a packfile. But `finish_tmp_packfile()` (which is responsible for writing the pack and moving the temporary versions of all of its auxiliary files into place) is inconsistent about the write order. Specifically, it moves the `.rev` file into place after the `.idx`, leaving open the possibility to open a pack which looks "ready" (because the `.idx` file exists and is readable) but appears momentarily to not have a `.rev` file. This causes Git to fall back to generating the pack's reverse index in memory. Though racy, this amounts to an unnecessary slow-down at worst, and doesn't affect the correctness of the resulting reverse index. Close this race by moving the .rev file into place before moving the .idx file into place. This still leaves the issue of `.idx` files being renamed into place before the auxiliary `.bitmap` file is renamed when in pack-object.c's write_pack_file() "write_bitmap_index" is true. That race will be addressed in subsequent commits. Signed-off-by: Taylor Blau Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Taylor Blau --- pack-write.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pack-write.c b/pack-write.c index 58bc5fbcdf..b9f9cd5c14 100644 --- a/pack-write.c +++ b/pack-write.c @@ -491,9 +491,9 @@ void finish_tmp_packfile(struct strbuf *name_buffer, pack_idx_opts->flags); rename_tmp_packfile(name_buffer, pack_tmp_name, "pack"); - rename_tmp_packfile(name_buffer, idx_tmp_name, "idx"); if (rev_tmp_name) rename_tmp_packfile(name_buffer, rev_tmp_name, "rev"); + rename_tmp_packfile(name_buffer, idx_tmp_name, "idx"); free((void *)idx_tmp_name); } From patchwork Thu Sep 9 23:24:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 12484159 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71C57C433EF for ; Thu, 9 Sep 2021 23:24:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 559046108B for ; Thu, 9 Sep 2021 23:24:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347294AbhIIXZ6 (ORCPT ); Thu, 9 Sep 2021 19:25:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349193AbhIIXZ4 (ORCPT ); Thu, 9 Sep 2021 19:25:56 -0400 Received: from mail-io1-xd2d.google.com (mail-io1-xd2d.google.com [IPv6:2607:f8b0:4864:20::d2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44D69C061574 for ; Thu, 9 Sep 2021 16:24:46 -0700 (PDT) Received: by mail-io1-xd2d.google.com with SMTP id f6so79066iox.0 for ; Thu, 09 Sep 2021 16:24:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=7nqV9WfFtPETODmBhucsE1hvbSzAfz7L/410X/EGp9c=; b=UxD5Nju+oP0k4ObG/EVlDN0p+CI/tb/TfMr4JvRRTkM1Qxm6J+uKNXf0WKlHcet9gW weq8zsELwA2LtaYIzfyA2RsL+q+EvCCv6KAr2oeXbc0vBFNQcZ2v82h769zG2ZgcpXsB MRpGalzX5HC2v/lry8d8G9WQJoHtZ5CDPkYEbRVd/2/OrMKRHFgHQGubF1lD0c69v5hT xpsfOHTLLHuE6O1CRO6ijqFSEPGyUTt03kB4wXsAgJmWqh51QkJJCTkyOTX6gY7FY4ZP Go8lvM54gFQeAdnrdX2LPKhuXG6XGC5evPfStQE59BQDCKmHSXLQDpdzUvjoXCAmH9K1 fdww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=7nqV9WfFtPETODmBhucsE1hvbSzAfz7L/410X/EGp9c=; b=JTRJhy38d4Oj0FV3XI5chEtc+j7kkhQHeNviL640eJcCswBzGeHKBr7OwBVZRqdVBq NGbCm0RB/gdi609prYmGx/tQSwuKkc2CHcKxKRROCWvONtMgADYK+lZwj0wAx4JV5uIE KugdkiMdctZzo+K5yZQw8jDGWjnQ7MQWlx+gKzV1iqUptqpfZrPwFzmXQPWP547oRF6I HMlIcolmtHgfU6LBfG3hHEaAuGbus/yuzBDCdZt9jtx+0od4BEWPn0J+7ueNUMO7anKX w4AvHXB12disKFkZI5FaOZzNyTDejH4QNQET0FcJT7IfGG4OzmroCb/kO3395KD+3Cq7 +ILw== X-Gm-Message-State: AOAM531pJF9xA4eEGrb8hhnu1z5tq707qW0MX0ZX1A3W9E1LFSYijsyp rdqs57ix75CBckNU8HXd0MQBwuAJkBBZfQAB X-Google-Smtp-Source: ABdhPJw2ZZ4SRIwYCLBWeTKO5FOD1XHaIjKKZx7KtUHqqF2IwgitleJ5cL1hnuSGWhFc9wu/a9jnkQ== X-Received: by 2002:a5e:a81a:: with SMTP id c26mr4668245ioa.15.1631229885645; Thu, 09 Sep 2021 16:24:45 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id a16sm1662614ili.64.2021.09.09.16.24.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Sep 2021 16:24:45 -0700 (PDT) Date: Thu, 9 Sep 2021 19:24:44 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: avarab@gmail.com, gitster@pobox.com Subject: [PATCH v2 5/9] builtin/repack.c: move `.idx` files into place last Message-ID: <6b340b7eba1509ac12291d2d1a20c146a2800f80.1631228928.git.me@ttaylorr.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In a similar spirit as the previous patch, fix the identical problem from `git repack` (which invokes `pack-objects` with a temporary location for output, and then moves the files into their final locations itself). Signed-off-by: Taylor Blau Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Taylor Blau --- builtin/repack.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/repack.c b/builtin/repack.c index 5f9bc74adc..c3e4771609 100644 --- a/builtin/repack.c +++ b/builtin/repack.c @@ -208,10 +208,10 @@ static struct { unsigned optional:1; } exts[] = { {".pack"}, - {".idx"}, {".rev", 1}, {".bitmap", 1}, {".promisor", 1}, + {".idx"}, }; static unsigned populate_pack_exts(char *name) From patchwork Thu Sep 9 23:24:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 12484161 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 33E68C433EF for ; Thu, 9 Sep 2021 23:25:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 14F6F6108B for ; Thu, 9 Sep 2021 23:25:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231819AbhIIX0L (ORCPT ); Thu, 9 Sep 2021 19:26:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349824AbhIIX0I (ORCPT ); Thu, 9 Sep 2021 19:26:08 -0400 Received: from mail-il1-x12e.google.com (mail-il1-x12e.google.com [IPv6:2607:f8b0:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE4A1C061768 for ; Thu, 9 Sep 2021 16:24:51 -0700 (PDT) Received: by mail-il1-x12e.google.com with SMTP id l10so90107ilh.8 for ; Thu, 09 Sep 2021 16:24:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=YuS+c34GpEkv6uyewZNPiRjnuUT1cG2SH2pGnbUWU6A=; b=GViBO+8jRyO99UDOpzLT39MARq/aHEKHLXhxt+gSaiRwq9Yqfl+U3d38lVn3IDLV1j LRd7XErHneu0pFu6pk2eOYjDva/K8iUsNKXHNjvufW2Fi47A5tiAxNGhmEAw5IMFtnJn KJkmQIZx5vLO4o+itUl8gP8WFsjn8vP4KUkdum6b8s+9rEn3DCaCfNo5FdsHJ4E6g12r SmFzvoCIdLv/v6U9SLcV5ryuxXSLouT2r3GnSkdpGH76L9r158+1rQI9jcYat8W9Ly0R bewOh+zj6G+CqA8iAfsimIyHChWQqygv5gAZRz2LPVbHg3zAYW56uBYcgvqEWEZP/BkI tqxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=YuS+c34GpEkv6uyewZNPiRjnuUT1cG2SH2pGnbUWU6A=; b=eEp3rL30RvZ5uTSYuqgYn9hjVPdtNVLS/cQbQCLBWD2e/iwDptFAUP9gzKUw51s8tq uN2YwfigkVOGvzEVAmYqCUXzHrvu1+374mZ3djIFZzFhtDuCdrVWtwn1yOBtc0bL3n3C mJv1vsq5ok7bb2IldgdqqLUaV5s1IkdeMi5tW+5aTwfkAeGPRO1Ap8Xv1t4vILky2A96 xgtgLXTQd1AwnxYqw7HSvdTsdMCDs8NVeGojzYvswCZliSqd7xAoDKSXdptHtNXcn8Y1 FYlEbU/2FQMIMLh9RQEeXlZ6BP9ZVYWb1S+faEl5iHZDiH6vMx2s00ZR6HqW5HthdL1D jw3g== X-Gm-Message-State: AOAM533K2TkENmeJ+wGEBUjmQyXwCGQYw+UMGKqb3r9C9ieUgdX3mxfr gTvtXyKJkzcXeK0Yd9HLTM2F3MFcGI7Pdxx7 X-Google-Smtp-Source: ABdhPJwjdfH18h42Dl2wrbfzLVthQiZZkkkCg2zcjoig2X0WXmiMhz16X2iL1ZHX66sz0YW134ub7A== X-Received: by 2002:a05:6e02:1a87:: with SMTP id k7mr4334034ilv.122.1631229891140; Thu, 09 Sep 2021 16:24:51 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id e12sm1612748ile.14.2021.09.09.16.24.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Sep 2021 16:24:50 -0700 (PDT) Date: Thu, 9 Sep 2021 19:24:49 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: avarab@gmail.com, gitster@pobox.com Subject: [PATCH v2 6/9] index-pack: refactor renaming in final() Message-ID: <1e4d0ea0f398ba48cf1b1f87122ab343bdb296e2.1631228928.git.me@ttaylorr.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Ævar Arnfjörð Bjarmason Refactor the renaming in final() into a helper function, this is similar in spirit to a preceding refactoring of finish_tmp_packfile() in pack-write.c. Before e37d0b8730b (builtin/index-pack.c: write reverse indexes, 2021-01-25) it probably wasn't worth it to have this sort of helper, due to the differing "else if" case for "pack" files v.s. "idx" files. But since we've got "rev" as well now, let's do the renaming via a helper, this is both a net decrease in lines, and improves the readability, since we can easily see at a glance that the logic for writing these three types of files is exactly the same, aside from the obviously differing cases of "*final_name" being NULL, and "make_read_only_if_same" being different. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Taylor Blau --- builtin/index-pack.c | 48 +++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 6cc4890217..3e3736cd95 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -1477,6 +1477,22 @@ static void write_special_file(const char *suffix, const char *msg, strbuf_release(&name_buf); } +static void rename_tmp_packfile(const char **final_name, + const char *curr_name, + struct strbuf *name, unsigned char *hash, + const char *ext, int make_read_only_if_same) +{ + if (*final_name != curr_name) { + if (!*final_name) + *final_name = odb_pack_name(name, hash, ext); + if (finalize_object_file(curr_name, *final_name)) + die(_("unable to rename temporary '*.%s' file to '%s"), + ext, *final_name); + } else if (make_read_only_if_same) { + chmod(*final_name, 0444); + } +} + static void final(const char *final_pack_name, const char *curr_pack_name, const char *final_index_name, const char *curr_index_name, const char *final_rev_index_name, const char *curr_rev_index_name, @@ -1505,31 +1521,13 @@ static void final(const char *final_pack_name, const char *curr_pack_name, write_special_file("promisor", promisor_msg, final_pack_name, hash, NULL); - if (final_pack_name != curr_pack_name) { - if (!final_pack_name) - final_pack_name = odb_pack_name(&pack_name, hash, "pack"); - if (finalize_object_file(curr_pack_name, final_pack_name)) - die(_("cannot store pack file")); - } else if (from_stdin) - chmod(final_pack_name, 0444); - - if (final_index_name != curr_index_name) { - if (!final_index_name) - final_index_name = odb_pack_name(&index_name, hash, "idx"); - if (finalize_object_file(curr_index_name, final_index_name)) - die(_("cannot store index file")); - } else - chmod(final_index_name, 0444); - - if (curr_rev_index_name) { - if (final_rev_index_name != curr_rev_index_name) { - if (!final_rev_index_name) - final_rev_index_name = odb_pack_name(&rev_index_name, hash, "rev"); - if (finalize_object_file(curr_rev_index_name, final_rev_index_name)) - die(_("cannot store reverse index file")); - } else - chmod(final_rev_index_name, 0444); - } + rename_tmp_packfile(&final_pack_name, curr_pack_name, &pack_name, + hash, "pack", from_stdin); + rename_tmp_packfile(&final_index_name, curr_index_name, &index_name, + hash, "idx", 1); + if (curr_rev_index_name) + rename_tmp_packfile(&final_rev_index_name, curr_rev_index_name, + &rev_index_name, hash, "rev", 1); if (do_fsck_object) { struct packed_git *p; From patchwork Thu Sep 9 23:24:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 12484165 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 625E9C433F5 for ; Thu, 9 Sep 2021 23:25:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 46FE76108B for ; Thu, 9 Sep 2021 23:25:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349805AbhIIX0P (ORCPT ); Thu, 9 Sep 2021 19:26:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349787AbhIIX0K (ORCPT ); Thu, 9 Sep 2021 19:26:10 -0400 Received: from mail-io1-xd2c.google.com (mail-io1-xd2c.google.com [IPv6:2607:f8b0:4864:20::d2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10E5FC0613E4 for ; Thu, 9 Sep 2021 16:24:55 -0700 (PDT) Received: by mail-io1-xd2c.google.com with SMTP id z1so21419ioh.7 for ; Thu, 09 Sep 2021 16:24:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=/TcU8niDUXEaxWVVkAyw16gXK1x9H/0z7dfA7bm7DdY=; b=p1sDMR+RnEhSf78PkucFgw8n5KpzT0TH1iT7Y2OkCvBamkOpes9m+lmAm727bPVAyA 70iRyQI0o44CdINvmsJ/4SXI82tqY8lXzJ6FcKtoOifdruUM8y1kYoSiptVl9gKbEOXW xcjOW5zneQnkUFKlQxzb1teQUILViGBoYW3fWa2Hpy4NlUnJngFedRWx5/GrtDBALxmT j96tylC6GETB3GCYg9BgfB/mg0+N51wf0T7U72d3LZIL5Rs0OvzflihseWuV8ty1HNfF anD+MWQ0XLZ3pbG4+Fsd1bTMozN9kwA5pwCHzgETB1GU7U/M9F5AoQ4dB7/p9I269LJq ThFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=/TcU8niDUXEaxWVVkAyw16gXK1x9H/0z7dfA7bm7DdY=; b=Gj6UgkrEaVpxEss7qfyc2hV7O+0n3SuSya3Pnjz8zJe97zSlTo0tRglXasKP6XiEW/ F61w2kQP9Cv2G5KA9VdXAaWGaeFqYay1nt9b3Crswv1UIqcUXfL0QpD2V0+3ojNGt1bK kuZs4ECmjgO/sd3uqv++fRgJDi7b6RCivTtzRfgWAuOf+Vil12KRaufK4pHfKjCtmUwB oiJB1I4mVv+r1/aRSeuN1O/hFkJNafr5DJDApRabIk/3ffaA+JHIASKgAECXE6c69Zvc nYAO+6o4IlhH9yclsDTXubRcjGDY1HRgDM/ODJ66zy0nN69oujkiSduB0eFuBRSVQCKG P4pQ== X-Gm-Message-State: AOAM530ziaTD9alQqMruwodCNkh0Fu/037r8DiLGftXB7yHVtad6EEWD 4AGA1spqo5++GZNO3SDiMgWBh/Pa3dKmbPoC X-Google-Smtp-Source: ABdhPJwmD/XJt05bBfhK+gI06LfZCo/aKhvpO2div8p1no1GQnHTpwbX8e69dPfjxfvmHjku19bfkg== X-Received: by 2002:a6b:28b:: with SMTP id 133mr4695533ioc.107.1631229894372; Thu, 09 Sep 2021 16:24:54 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id k5sm1561343iob.45.2021.09.09.16.24.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Sep 2021 16:24:54 -0700 (PDT) Date: Thu, 9 Sep 2021 19:24:53 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: avarab@gmail.com, gitster@pobox.com Subject: [PATCH v2 7/9] builtin/index-pack.c: move `.idx` files into place last Message-ID: <906e75d7076e547fe2947dc701054e554f29dedb.1631228928.git.me@ttaylorr.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In a similar spirit as preceding patches to `git repack` and `git pack-objects`, fix the identical problem in `git index-pack`. Signed-off-by: Taylor Blau Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Taylor Blau --- builtin/index-pack.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 3e3736cd95..f267dce49e 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -1523,11 +1523,11 @@ static void final(const char *final_pack_name, const char *curr_pack_name, rename_tmp_packfile(&final_pack_name, curr_pack_name, &pack_name, hash, "pack", from_stdin); - rename_tmp_packfile(&final_index_name, curr_index_name, &index_name, - hash, "idx", 1); if (curr_rev_index_name) rename_tmp_packfile(&final_rev_index_name, curr_rev_index_name, &rev_index_name, hash, "rev", 1); + rename_tmp_packfile(&final_index_name, curr_index_name, &index_name, + hash, "idx", 1); if (do_fsck_object) { struct packed_git *p; From patchwork Thu Sep 9 23:24:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 12484163 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2DE8AC433FE for ; Thu, 9 Sep 2021 23:25:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0AA36610C9 for ; Thu, 9 Sep 2021 23:25:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349593AbhIIX0M (ORCPT ); Thu, 9 Sep 2021 19:26:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349786AbhIIX0K (ORCPT ); Thu, 9 Sep 2021 19:26:10 -0400 Received: from mail-io1-xd31.google.com (mail-io1-xd31.google.com [IPv6:2607:f8b0:4864:20::d31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C90AEC061574 for ; Thu, 9 Sep 2021 16:24:57 -0700 (PDT) Received: by mail-io1-xd31.google.com with SMTP id a15so40527iot.2 for ; Thu, 09 Sep 2021 16:24:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=1uinzz2bN2Y1Ub0Dz+81s2OdRoZ4GU5uPFUToyOrrOI=; b=oChU+nk4T/T3vh7WISZ8BRtKLvdOAD+p/GuMaMHM01Q2Jcalt2/ydgjdxvpeKKwXFP 1jC6na4I7LIAZ94QM5xnT+9Eo5t2OQg3pkxOHmMtkgcjbvXUoD4sqxj15B6gclFB3+t2 319edK+B3qnhqhEJLY4hQuwCSw3qNbKgT3hsv8AcOnnyEJruj0acFbqNUuTypLFzLBm/ TzP0NybBDN38f9G8x29o9lYPuaNT9MtDyfkWnGuZ26gR6tLPC0Zlr2HskC+SykbQOQAq aNJm7kJ4UleyDJZW27ZEQb1yahgxmhEzlWkhphOe+bj93SC7CNYO0YQ0+44GIt7+wrrM AgWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=1uinzz2bN2Y1Ub0Dz+81s2OdRoZ4GU5uPFUToyOrrOI=; b=of4ipRyRfR6Kws+6z9L3oYmBZ+GHTQvGayNTZAbfSSe3BMha93iFjMPzcKhy4dvC/n Qzf9ohQ7n/cSmwHjQz0Pp4fctbA8HIibSj1sO/pjcJ7nnV3rco5XaVu0yz1VHT8YvokE dHZNbT9zuHqv2N+okMDsr6pizBlmUw++tpffHPyAZ+VCZU8YuxilLVmoN3PRXhKMDhFY bsAAtwnEqxmKaQKvkPqqLH+8nP5d1ePjRde/yHK/tRC9d0PkZCYJMN2OdflSz1zCJWyY mAWAjfrVIfrmU34gB2xrYqQQMrKa91QwZykqP+pqV+eWRBI0t4Kn/qkXzcOg1f1iqasl 1YwA== X-Gm-Message-State: AOAM5311w+oFu2kR3mPWmBDvb6/CLhdgVIjS+7NcfKKqhLIaYSFHmhcW cxO10Ksrn1ktKwYSYUHaX4y3qYENZEucTf1Z X-Google-Smtp-Source: ABdhPJykz3CwOzakMjSCUXdumz76L+nM7Zob8J2wRm89959jwey8w1u3X+FRQbXJBgh8sH2hsDkARw== X-Received: by 2002:a5e:c30c:: with SMTP id a12mr4617524iok.52.1631229897107; Thu, 09 Sep 2021 16:24:57 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id v1sm1561115ile.83.2021.09.09.16.24.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Sep 2021 16:24:56 -0700 (PDT) Date: Thu, 9 Sep 2021 19:24:56 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: avarab@gmail.com, gitster@pobox.com Subject: [PATCH v2 8/9] pack-write: split up finish_tmp_packfile() function Message-ID: <90bebe4e51c3bc84d156912db84e0d2774f56354.1631228928.git.me@ttaylorr.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Ævar Arnfjörð Bjarmason Split up the finish_tmp_packfile() function and use the split-up version in pack-objects.c in preparation for moving the step of renaming the *.idx file later as part of a function change. Since the only other caller of finish_tmp_packfile() was in bulk-checkin.c, and it won't be needing a change to its *.idx renaming, provide a thin wrapper for the old function as a static function in that file. If other callers end up needing the simpler version it could be moved back to "pack-write.c" and "pack.h". Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Taylor Blau --- builtin/pack-objects.c | 7 +++++-- bulk-checkin.c | 16 ++++++++++++++++ pack-write.c | 22 +++++++++++++--------- pack.h | 7 +++++-- 4 files changed, 39 insertions(+), 13 deletions(-) diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 2a105c8d6e..944134b6f2 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -1217,6 +1217,7 @@ static void write_pack_file(void) if (!pack_to_stdout) { struct stat st; struct strbuf tmpname = STRBUF_INIT; + char *idx_tmp_name = NULL; /* * Packs are runtime accessed in their mtime @@ -1246,9 +1247,10 @@ static void write_pack_file(void) &to_pack, written_list, nr_written); } - finish_tmp_packfile(&tmpname, pack_tmp_name, + stage_tmp_packfiles(&tmpname, pack_tmp_name, written_list, nr_written, - &pack_idx_opts, hash); + &pack_idx_opts, hash, &idx_tmp_name); + rename_tmp_packfile_idx(&tmpname, &idx_tmp_name); if (write_bitmap_index) { size_t tmpname_len = tmpname.len; @@ -1265,6 +1267,7 @@ static void write_pack_file(void) strbuf_setlen(&tmpname, tmpname_len); } + free(idx_tmp_name); strbuf_release(&tmpname); free(pack_tmp_name); puts(hash_to_hex(hash)); diff --git a/bulk-checkin.c b/bulk-checkin.c index c19d471f0b..8785b2ac80 100644 --- a/bulk-checkin.c +++ b/bulk-checkin.c @@ -23,6 +23,22 @@ static struct bulk_checkin_state { uint32_t nr_written; } state; +static void finish_tmp_packfile(struct strbuf *basename, + const char *pack_tmp_name, + struct pack_idx_entry **written_list, + uint32_t nr_written, + struct pack_idx_option *pack_idx_opts, + unsigned char hash[]) +{ + char *idx_tmp_name = NULL; + + stage_tmp_packfiles(basename, pack_tmp_name, written_list, nr_written, + pack_idx_opts, hash, &idx_tmp_name); + rename_tmp_packfile_idx(basename, &idx_tmp_name); + + free(idx_tmp_name); +} + static void finish_bulk_checkin(struct bulk_checkin_state *state) { unsigned char hash[GIT_MAX_RAWSZ]; diff --git a/pack-write.c b/pack-write.c index b9f9cd5c14..c21aed64b3 100644 --- a/pack-write.c +++ b/pack-write.c @@ -470,21 +470,28 @@ static void rename_tmp_packfile(struct strbuf *name_prefix, const char *source, strbuf_setlen(name_prefix, name_prefix_len); } -void finish_tmp_packfile(struct strbuf *name_buffer, +void rename_tmp_packfile_idx(struct strbuf *name_buffer, + char **idx_tmp_name) +{ + rename_tmp_packfile(name_buffer, *idx_tmp_name, "idx"); +} + +void stage_tmp_packfiles(struct strbuf *name_buffer, const char *pack_tmp_name, struct pack_idx_entry **written_list, uint32_t nr_written, struct pack_idx_option *pack_idx_opts, - unsigned char hash[]) + unsigned char hash[], + char **idx_tmp_name) { - const char *idx_tmp_name, *rev_tmp_name = NULL; + const char *rev_tmp_name = NULL; if (adjust_shared_perm(pack_tmp_name)) die_errno("unable to make temporary pack file readable"); - idx_tmp_name = write_idx_file(NULL, written_list, nr_written, - pack_idx_opts, hash); - if (adjust_shared_perm(idx_tmp_name)) + *idx_tmp_name = (char *)write_idx_file(NULL, written_list, nr_written, + pack_idx_opts, hash); + if (adjust_shared_perm(*idx_tmp_name)) die_errno("unable to make temporary index file readable"); rev_tmp_name = write_rev_file(NULL, written_list, nr_written, hash, @@ -493,9 +500,6 @@ void finish_tmp_packfile(struct strbuf *name_buffer, rename_tmp_packfile(name_buffer, pack_tmp_name, "pack"); if (rev_tmp_name) rename_tmp_packfile(name_buffer, rev_tmp_name, "rev"); - rename_tmp_packfile(name_buffer, idx_tmp_name, "idx"); - - free((void *)idx_tmp_name); } void write_promisor_file(const char *promisor_name, struct ref **sought, int nr_sought) diff --git a/pack.h b/pack.h index 1c17254c0a..b22bfc4a18 100644 --- a/pack.h +++ b/pack.h @@ -110,11 +110,14 @@ int encode_in_pack_object_header(unsigned char *hdr, int hdr_len, int read_pack_header(int fd, struct pack_header *); struct hashfile *create_tmp_packfile(char **pack_tmp_name); -void finish_tmp_packfile(struct strbuf *name_buffer, +void stage_tmp_packfiles(struct strbuf *name_buffer, const char *pack_tmp_name, struct pack_idx_entry **written_list, uint32_t nr_written, struct pack_idx_option *pack_idx_opts, - unsigned char sha1[]); + unsigned char hash[], + char **idx_tmp_name); +void rename_tmp_packfile_idx(struct strbuf *basename, + char **idx_tmp_name); #endif From patchwork Thu Sep 9 23:25:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 12484167 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BDD09C433F5 for ; Thu, 9 Sep 2021 23:25:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 98F26610C9 for ; Thu, 9 Sep 2021 23:25:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349320AbhIIX0T (ORCPT ); Thu, 9 Sep 2021 19:26:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349533AbhIIX0M (ORCPT ); Thu, 9 Sep 2021 19:26:12 -0400 Received: from mail-il1-x12b.google.com (mail-il1-x12b.google.com [IPv6:2607:f8b0:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 438B6C061574 for ; Thu, 9 Sep 2021 16:25:02 -0700 (PDT) Received: by mail-il1-x12b.google.com with SMTP id l10so90546ilh.8 for ; Thu, 09 Sep 2021 16:25:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=lw6WWh7oWv2wBEXcCqVbIGz0GPy9m3PgbNMhaMoaMzI=; b=iL6BPrcDBxqQaYaG0rnh3PfhKiqQ98JK060A8CjlMTbMq0+B/UWh/DLfCd0SFuBocb mRjEgPfs8oC1miznF1sgy6QSCjCKaLWRxd3XSupjSSKHQ+a6u9LwZX5KNeNo+JoZ5v+a FN25wLOaoSh6aR+TSR5jFHldaY0bc98u4pBZocpoyPW9jcNq9fz/vfU3CIkivrJbD4BA 1RQlrbBhOhDyATl50wmX7gEr/K3jgmU7y33vQkoxRZujdKdzfMmFHWURr0pqRiF+4NHv XGsxGa/gDx42ZVqhBaWx+hbzRYGUgXcQkNIgTIXOc2nhKY9D+5VHvvup3bFd+6nVYamr OQFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=lw6WWh7oWv2wBEXcCqVbIGz0GPy9m3PgbNMhaMoaMzI=; b=SOZVUcY3WE7kaQT5Ggt6tPJKwqlYdtPMbNGAZzHu02cVt7BZcwAl11MpofNlaCqJn1 C3Zah1AJJz0E0ZZ4MfkpevcVgkWqeRuAd6oOyevP4I/FEDB3yyttHxX903AOE7LyoC6u RZyXMhTWFzd/iaohp2bnYIKriAy+DAJdi544Rzk1s9j/1QsBtrl4A4a+ItlKbg1L1l6V mQp8gg2urEqnBxg5KOSfM7lj9ByNVTpVnOlBhzRjEkP49VPH8+qorqa2+2vt569VVWwI eKt6XWeU05jUmDMyrz8KkWRAm6i7ku/9jvtv6dRurzvf+K3iL0e460cZz9lAXBH5SH1y j8Eg== X-Gm-Message-State: AOAM531EJnfrA+QSuGQIS+sOWx21Q3XTUngzIjB++wjVCPYoCpkGgx9P 1gRslTH0JOVIOEQuKjeNSny3RzF6NiyrQxKW X-Google-Smtp-Source: ABdhPJw2d0O210lVhap4WFy3ydBASLUPcUCOWJah9tLS0djOf+3qsyU+NbTyU0jpJ9CFZ/nM1fN9hQ== X-Received: by 2002:a92:6605:: with SMTP id a5mr3945668ilc.17.1631229901593; Thu, 09 Sep 2021 16:25:01 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id d17sm1609496ilf.49.2021.09.09.16.25.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Sep 2021 16:25:01 -0700 (PDT) Date: Thu, 9 Sep 2021 19:25:00 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: avarab@gmail.com, gitster@pobox.com Subject: [PATCH v2 9/9] pack-objects: rename .idx files into place after .bitmap files Message-ID: <1409725509fad5708abc2586c5679887561c5ed6.1631228928.git.me@ttaylorr.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Ævar Arnfjörð Bjarmason In preceding commits the race of renaming .idx files in place before .rev files and other auxiliary files was fixed in pack-write.c's finish_tmp_packfile(), builtin/repack.c's "struct exts", and builtin/index-pack.c's final(). As noted in the change to pack-write.c we left in place the issue of writing *.bitmap files after the *.idx, let's fix that issue. See 7cc8f971085 (pack-objects: implement bitmap writing, 2013-12-21) for commentary at the time when *.bitmap was implemented about how those files are written out, nothing in that commit contradicts what's being done here. Note that this commit and preceding ones only close any race condition with *.idx files being written before their auxiliary files if we're optimistic about our lack of fsync()-ing in this are not tripping us over. See the thread at [1] for a rabbit hole of various discussions about filesystem races in the face of doing and not doing fsync() (and if doing fsync(), not doing it properly). We may want to fsync the containing directory once after renaming the *.idx file into place, but that is outside the scope of this series. 1. https://lore.kernel.org/git/8735qgkvv1.fsf@evledraar.gmail.com/ Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Taylor Blau --- builtin/pack-objects.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 944134b6f2..a01767a384 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -1250,7 +1250,6 @@ static void write_pack_file(void) stage_tmp_packfiles(&tmpname, pack_tmp_name, written_list, nr_written, &pack_idx_opts, hash, &idx_tmp_name); - rename_tmp_packfile_idx(&tmpname, &idx_tmp_name); if (write_bitmap_index) { size_t tmpname_len = tmpname.len; @@ -1267,6 +1266,8 @@ static void write_pack_file(void) strbuf_setlen(&tmpname, tmpname_len); } + rename_tmp_packfile_idx(&tmpname, &idx_tmp_name); + free(idx_tmp_name); strbuf_release(&tmpname); free(pack_tmp_name);