From patchwork Sat Nov 28 06:44:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 11938279 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=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 2EE4CC63777 for ; Sat, 28 Nov 2020 22:16:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E2ED721D40 for ; Sat, 28 Nov 2020 22:16:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="qjD0307V" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388994AbgK1Vts (ORCPT ); Sat, 28 Nov 2020 16:49:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732380AbgK1TAJ (ORCPT ); Sat, 28 Nov 2020 14:00:09 -0500 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BA10C094241 for ; Fri, 27 Nov 2020 22:44:42 -0800 (PST) Received: by mail-wm1-x344.google.com with SMTP id v14so1146049wml.1 for ; Fri, 27 Nov 2020 22:44:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=/20RZ4uByElgRc3kL6zaVvAcxNYFd//xwDFEk6VI2E8=; b=qjD0307VOnz2x1s5GV4OKSYJ7c5sjug8d6pWsJ3wd6vzsbAWCawHz4nStq9Ad5p9h0 BNPkeAqkyVMskxJwHnBx4rhC7cu4RXASq0HIoYR5vZFmWPn/NDNCTQicKlEX1urRiNqk 2U9mT1zblRtN82R0L75G2ypnSXMC8bB5KbucZQhQZIyjYGs3csjTpyS9xNrxFBnkL7nw bsal2M80iRuv4cDPy3MDIjXaxtZjXBJiEMpZ5gFD68ReJGOKaIQaMJkOfJwQ1rQThqao ay5NYhqYEyl9fQRC/nFqPMTPW/stJuokyOiJ6LsUmkfxhBIgwmcfuoZh1DhsHywh5BZ1 nVEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=/20RZ4uByElgRc3kL6zaVvAcxNYFd//xwDFEk6VI2E8=; b=XCLd0KKs1xIZfuyTvPhnet0DnaCspVtqOUeUCpo3qdo1aqYBc9cIOz5Ymtiy8VYSMb cPlBhnLR9VxpoZVag+E1oWDi9GY0UblmIJ9yPc07oCAMyW6/TkeIz5lFW5cTYBpDapzR SujsF0LWv+H4yzhe4Ty/v2EvXLCJVZPNbSicv5THHBZc/fQnRjy7ASVA5IIVPMZGcz2i txqPtkH+PrhnsGfsgjLkvdlqYexH2YPsC6cmQVfPSCTb34TFEJ1xKEPcEtGQmAlBjMzp vZwTior7kNaVkk1M1WfIn3FkhUxKfWlyIai1H0zGAuI+UN4z6B95AgVHm5iFVLTvHj6q mHWQ== X-Gm-Message-State: AOAM530VoA4kouzfAreTGuiXZ16xZdBjuxSAQoyyYj9C40KRNDbfmaDC xgFX0dZ/ztsuuhr1JG2CxT8nBM0rnUQ= X-Google-Smtp-Source: ABdhPJzNnKanwYLtSupLrSRbJ9eyNzOtDngQuaWBFMezE+UCvpm/CU8da/BC5hsRnS1rDnL2aQUzvQ== X-Received: by 2002:a7b:c1ce:: with SMTP id a14mr13030055wmj.169.1606545880749; Fri, 27 Nov 2020 22:44:40 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id w186sm16864486wmb.26.2020.11.27.22.44.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Nov 2020 22:44:40 -0800 (PST) Message-Id: <878bffcdfe5ca7657f839de8f7993d9098726636.1606545878.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sat, 28 Nov 2020 06:44:33 +0000 Subject: [PATCH 1/6] fixup! reftable: rest of library Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Han-Wen Nienhuys , Han-Wen Nienhuys , Jeff King , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin Close the file descriptors to obsolete files before trying to delete or rename them. This is actually required on Windows. Note: this patch is just a band-aid to get the tests pass on Windows. The fact that it is needed raises concerns about the overall resource handling: are file descriptors closed properly whenever appropriate, or are they closed much later (which can lead to rename() problems on Windows, and risks running into ulimits)? Also, a `reftable_stack_destroy()` call had to be moved in `test_reftable_stack_uptodate()` to avoid the prompt complaining that a `.ref` file could not be deleted on Windows. This raises the question whether the code does the right thing when two concurrent processes want to access the reftable, and one wants to compact it. At the moment, it does not appear to fail gracefully. Signed-off-by: Johannes Schindelin --- reftable/stack.c | 37 ++++++++++++++++++++++++++++--------- reftable/stack_test.c | 2 +- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/reftable/stack.c b/reftable/stack.c index 1d632937d7..02c6a370ba 100644 --- a/reftable/stack.c +++ b/reftable/stack.c @@ -212,7 +212,6 @@ static int reftable_stack_reload_once(struct reftable_stack *st, char **names, goto done; new_tables = NULL; - st->readers_len = new_readers_len; if (st->merged != NULL) { merged_table_release(st->merged); reftable_merged_table_free(st->merged); @@ -220,6 +219,7 @@ static int reftable_stack_reload_once(struct reftable_stack *st, char **names, if (st->readers != NULL) { reftable_free(st->readers); } + st->readers_len = new_readers_len; st->readers = new_readers; new_readers = NULL; new_readers_len = 0; @@ -939,14 +939,6 @@ static int stack_compact_range(struct reftable_stack *st, int first, int last, strbuf_addstr(&new_table_path, "/"); strbuf_addbuf(&new_table_path, &new_table_name); - if (!is_empty_table) { - err = rename(temp_tab_file_name.buf, new_table_path.buf); - if (err < 0) { - err = REFTABLE_IO_ERROR; - goto done; - } - } - for (i = 0; i < first; i++) { strbuf_addstr(&ref_list_contents, st->readers[i]->name); strbuf_addstr(&ref_list_contents, "\n"); @@ -960,6 +952,32 @@ static int stack_compact_range(struct reftable_stack *st, int first, int last, strbuf_addstr(&ref_list_contents, "\n"); } + /* + * Now release the merged tables and readers + */ + if (st->merged != NULL) { + reftable_merged_table_free(st->merged); + st->merged = NULL; + } + + if (st->readers != NULL) { + int i = 0; + for (i = 0; i < st->readers_len; i++) { + reader_close(st->readers[i]); + reftable_reader_free(st->readers[i]); + } + st->readers_len = 0; + FREE_AND_NULL(st->readers); + } + + if (!is_empty_table) { + err = rename(temp_tab_file_name.buf, new_table_path.buf); + if (err < 0) { + err = REFTABLE_IO_ERROR; + goto done; + } + } + err = write(lock_file_fd, ref_list_contents.buf, ref_list_contents.len); if (err < 0) { err = REFTABLE_IO_ERROR; @@ -1242,6 +1260,7 @@ static int stack_check_addition(struct reftable_stack *st, free(refs); reftable_iterator_destroy(&it); + reader_close(rd); reftable_reader_free(rd); return err; } diff --git a/reftable/stack_test.c b/reftable/stack_test.c index 11d3d30799..c35abd7301 100644 --- a/reftable/stack_test.c +++ b/reftable/stack_test.c @@ -159,12 +159,12 @@ static void test_reftable_stack_uptodate(void) err = reftable_stack_add(st2, &write_test_ref, &ref2); EXPECT(err == REFTABLE_LOCK_ERROR); + reftable_stack_destroy(st1); err = reftable_stack_reload(st2); EXPECT_ERR(err); err = reftable_stack_add(st2, &write_test_ref, &ref2); EXPECT_ERR(err); - reftable_stack_destroy(st1); reftable_stack_destroy(st2); clear_dir(dir); } From patchwork Sat Nov 28 06:44:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 11938287 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=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 799F1C83019 for ; Sat, 28 Nov 2020 22:16:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4BE3421D40 for ; Sat, 28 Nov 2020 22:16:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GpcgRBTK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389093AbgK1Vtu (ORCPT ); Sat, 28 Nov 2020 16:49:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733039AbgK1TFJ (ORCPT ); Sat, 28 Nov 2020 14:05:09 -0500 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10C78C094242 for ; Fri, 27 Nov 2020 22:44:43 -0800 (PST) Received: by mail-wr1-x442.google.com with SMTP id i2so7734063wrs.4 for ; Fri, 27 Nov 2020 22:44:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=eeBNxfU5jIL7EMpNWaf1fxb4+qyUPE6QFDCAw+D28eM=; b=GpcgRBTKJlCqr3sT7TwkMXCyY0eOfn+fH3rUAEdbd+nTGEPmOh4OjHA3Y7ukfwoI+2 HnI9rAPlzzvV4rdtYUMknQ+8h2NjdoK3H+qMJGdVmWU2R8/PDL8GJLSV5dF9Ue4CV/qY p5eMr1cGhhobhetDym+WSGtGWn95okCs8oEUKQchqiX9U+9jM5D21qMR7swuXr/fpdu/ YW4aDiSVYpIIswZCZ61f1pW7LYzAe729h8xup+D06MGzMwOuCdfsEEEDyMQ59CCYfhkv neb9MqRidzy6nABUcnGcCG+UM0ddCgxxNfpgxZwrerXo/hywjIHHkPmvk68E9lEstU8r Q4Gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=eeBNxfU5jIL7EMpNWaf1fxb4+qyUPE6QFDCAw+D28eM=; b=ISqYVHXUscm0m+lOz8T4h8EVwqVGBfl8hvKUh/91kg4GePR6YiXwMqYkY5hkMu6kaq FLbhVUnC8ahWZMKobvuyo3sFx6z6duN1ufwpH87yVTR83YOMnHAWsyhWY0F+qP0B8Eld PbWyQcQzdC6VsiRyv0/iXMshf8zyOfAEbOxKBcjQSdaRcZFCB/G0KjC7CNKEOC1zavHB iZUZMuP48e68Y1ZIHmihOiT9dpbUIUQj7puDXbB+9giKbCOXrX3tSuN7jCheIo6TKhux bPOU1GfiatoBjjVwK84w3ThagrWRPtvi5wXumI+ZrEJ3eSXwiYA+cKbk0833cQpO4PP/ LDWQ== X-Gm-Message-State: AOAM530Ld2HtfbbzcQga1E5JrfgmA9EbYxwpVNKKe9keUY25DWRHL0bw sPAvQVwb7J31UgTh+H3nfZr42zrziZQ= X-Google-Smtp-Source: ABdhPJx0Bz0USgWsvIgwbES94MUV6ilNhuZCZZe1j1cPG2CysitUfG1JfNfeuRRhNyvPCq0aZppc7w== X-Received: by 2002:adf:a39e:: with SMTP id l30mr15176128wrb.195.1606545881685; Fri, 27 Nov 2020 22:44:41 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id e3sm18891348wro.90.2020.11.27.22.44.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Nov 2020 22:44:41 -0800 (PST) Message-Id: <94719a3462ce77e490188b5b96211aec7d67dada.1606545878.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sat, 28 Nov 2020 06:44:34 +0000 Subject: [PATCH 2/6] fixup! reftable: utility functions Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Han-Wen Nienhuys , Han-Wen Nienhuys , Jeff King , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin Let's not forget our CMake configuration. Signed-off-by: Johannes Schindelin --- contrib/buildsystems/CMakeLists.txt | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt index df539a44fa..f3a2fd3561 100644 --- a/contrib/buildsystems/CMakeLists.txt +++ b/contrib/buildsystems/CMakeLists.txt @@ -591,6 +591,12 @@ parse_makefile_for_sources(libxdiff_SOURCES "XDIFF_OBJS") list(TRANSFORM libxdiff_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/") add_library(xdiff STATIC ${libxdiff_SOURCES}) +#reftable +parse_makefile_for_sources(reftable_SOURCES "REFTABLE_OBJS") + +list(TRANSFORM reftable_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/") +add_library(reftable STATIC ${reftable_SOURCES}) + if(WIN32) if(NOT MSVC)#use windres when compiling with gcc and clang add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/git.res @@ -613,7 +619,7 @@ endif() #link all required libraries to common-main add_library(common-main OBJECT ${CMAKE_SOURCE_DIR}/common-main.c) -target_link_libraries(common-main libgit xdiff ${ZLIB_LIBRARIES}) +target_link_libraries(common-main libgit xdiff reftable ${ZLIB_LIBRARIES}) if(Intl_FOUND) target_link_libraries(common-main ${Intl_LIBRARIES}) endif() @@ -848,11 +854,15 @@ if(BUILD_TESTING) add_executable(test-fake-ssh ${CMAKE_SOURCE_DIR}/t/helper/test-fake-ssh.c) target_link_libraries(test-fake-ssh common-main) +#reftable-tests +parse_makefile_for_sources(test-reftable_SOURCES "REFTABLE_TEST_OBJS") +list(TRANSFORM test-reftable_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/") + #test-tool parse_makefile_for_sources(test-tool_SOURCES "TEST_BUILTINS_OBJS") list(TRANSFORM test-tool_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/t/helper/") -add_executable(test-tool ${CMAKE_SOURCE_DIR}/t/helper/test-tool.c ${test-tool_SOURCES}) +add_executable(test-tool ${CMAKE_SOURCE_DIR}/t/helper/test-tool.c ${test-tool_SOURCES} ${test-reftable_SOURCES}) target_link_libraries(test-tool common-main) set_target_properties(test-fake-ssh test-tool From patchwork Sat Nov 28 06:44:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 11938289 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=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 1D672C83022 for ; Sat, 28 Nov 2020 22:17:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DE25F22242 for ; Sat, 28 Nov 2020 22:16:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kZ9nQe9R" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388975AbgK1Vts (ORCPT ); Sat, 28 Nov 2020 16:49:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732093AbgK1S6F (ORCPT ); Sat, 28 Nov 2020 13:58:05 -0500 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6DCAC094243 for ; Fri, 27 Nov 2020 22:44:43 -0800 (PST) Received: by mail-wr1-x444.google.com with SMTP id g14so7696884wrm.13 for ; Fri, 27 Nov 2020 22:44:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=u0bX5HR+EKP51B3h0YCynBVuSHPIBVV8xuMlehD5dQ4=; b=kZ9nQe9RJOXGjYWmfW5GfGFdSeU6t1XW9dm9SV1S97aUixy9o+0kQQwnY+xE0bzXFH Vg+WePI2occ52CPsosaByZ6SllNAv0KePxmTjqIUoEO/1n0da2ntQuli0MZqzRvB595h AY9IMNlU6rO7IDg+M348OzBdeobVGUFg6E1kDbMYvtqy8SOp00HrmGsHolxO1YLnEHjU h4h7bXS9/tLfdQ8NeZyOaZITJb1HxnZqoQvj6+RCuCCCBZwm665G/swoUAL++va4VvP+ ZXa1JizWC30Db/ECJXuy/Ks+hMdbyqTIiWeO+gBr9/lDYu/DCuHAsznKdhfhEac/0OZ/ dPTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=u0bX5HR+EKP51B3h0YCynBVuSHPIBVV8xuMlehD5dQ4=; b=BLj0ORyga6DWkC3Pxjt3ziG73B7gVKB3xZMV4wWGgG54v9mC4AvRnifub9rZBQidCI Sxxif4QkohBvdBuTf15beIniQMkCOo0sD5S6KFKbnYQ4xZjJM7XdMcZZr8BHedizQjDv B0R/FrVDaYDXHeMuw4u+rhxNM/q9g8g9nMMJEn18dkolLTOwBoLhMLvgvgp7TT+/9+0p wqPVd4BVO5Df9iCZcWm+GB4W0CzWiTAxqo4komGk4t/wS9se/5+KiyP5IgOKJfb76Ayt W/Pb3d4ZG/1/qAgkCSxtJ4X91KhpY3cJkLRfZ7+5qy4TnvuNd9DrBtih/+/1OlRKXEh2 meIw== X-Gm-Message-State: AOAM531YY82jiDYlUiPzb2YzOmwPH21BQkTCRUrHrlCz1//ucAWuu9ef zYhi/sJXUdOISyruGZATj5xkCF4f+fA= X-Google-Smtp-Source: ABdhPJwqKKf6QQomHKOFtRfN6RZNJntxgfLeTKFiT2mfHtSKsQq8I+iz5wyBDE7PKY/0IBIdwzEzpw== X-Received: by 2002:a5d:6503:: with SMTP id x3mr15897707wru.151.1606545882516; Fri, 27 Nov 2020 22:44:42 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id l3sm18168656wrr.89.2020.11.27.22.44.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Nov 2020 22:44:42 -0800 (PST) Message-Id: <58f2b0394546e8da2922adcbc38bdb6b53f2b313.1606545878.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sat, 28 Nov 2020 06:44:35 +0000 Subject: [PATCH 3/6] fixup! reftable: rest of library Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Han-Wen Nienhuys , Han-Wen Nienhuys , Jeff King , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin 0-sized arrays are actually not portable. Signed-off-by: Johannes Schindelin --- reftable/stack_test.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/reftable/stack_test.c b/reftable/stack_test.c index c35abd7301..cf2e32a25c 100644 --- a/reftable/stack_test.c +++ b/reftable/stack_test.c @@ -579,11 +579,11 @@ static void test_sizes_to_segments(void) static void test_sizes_to_segments_empty(void) { - uint64_t sizes[0]; + uint64_t sizes[1]; int seglen = 0; struct segment *segs = - sizes_to_segments(&seglen, sizes, ARRAY_SIZE(sizes)); + sizes_to_segments(&seglen, sizes, 0); EXPECT(seglen == 0); reftable_free(segs); } From patchwork Sat Nov 28 06:44:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 11938285 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=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 C6C19C63777 for ; Sat, 28 Nov 2020 22:16:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9752222256 for ; Sat, 28 Nov 2020 22:16:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="F7ZgcA5f" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727558AbgK1Vtu (ORCPT ); Sat, 28 Nov 2020 16:49:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733032AbgK1TFA (ORCPT ); Sat, 28 Nov 2020 14:05:00 -0500 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD4CDC09424A for ; Fri, 27 Nov 2020 22:44:44 -0800 (PST) Received: by mail-wm1-x341.google.com with SMTP id a3so8272424wmb.5 for ; Fri, 27 Nov 2020 22:44:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=7WetoMbnRellC+XuUdQeCzscRpJJO2DEGkFC7ize0EY=; b=F7ZgcA5fnxm/55VFeB30OWxh4nBEI9Smg22+RhL9LfEalDBzix+dG7+4kMCPYnVm8e uBj4b6mExmP+MozVbxNCsqLxySpSAc1UUHLwFr69XO+p6YmO7H1saxILm549wkkOBNxK ClHo9FN1zO6Ssyoqe4Rdfb9UExb14flVJnvW4TF7vibxKq0rx+epQPzXbN7xy20IICFz yuNk477WDzAD3XwWRIPDdaI1yaTBEeFJEwP01H2uzEWASPPimB0QUl3p6K4W865+akNK xSs1uVlLAbDtbd6k8rnImTQNY3D0J8Woa600LTuqEywUNhy/FCiWCKglMd0msVHUz496 ws1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=7WetoMbnRellC+XuUdQeCzscRpJJO2DEGkFC7ize0EY=; b=O9XNJnqNIHasKkuRmhxGTWOlxVomTIOyVK4q+WOQ3hnOLC8CoYe4DbbbgcJm93+Nt3 0yFuC1HIMpNMKhiuPP8W1i8FpXQ8x5hZcxNcuCM+5Hdv8AbMpU0Pn2e7qakzgPrKraAN TRugEbqU2vXuYy5GDCAGtXJH0k7nGug2Dh0LfMc8x5a78RmraX4zXuGAd7IskZU38jYg 8BA3AN/opf6cNcaEXYXzq5zH2smYWB0DZNpTnZAyEmWEJMNV4og+Ov5YXQ1jcTxIubD4 mokejZVsC9aPmN28QUijRl8WwDj5mnNhY7fd+BwDXlFC8jWmsAEncXV+xf3gbL5qDdwE sJWQ== X-Gm-Message-State: AOAM531KIrqHNtfbjYPJoBsIc6385NpUaRhC2h4jMwPps2ecLxzEMn2D 0gLMYNkYTMWDJeo+HafzcoPYHaN7Afo= X-Google-Smtp-Source: ABdhPJy6Ti1v1QAOdDAdnq0teyffWAVwWHFIXIb6mX0GWg+kPUAxWFbW+KhZoTMb6OLLIQ9XhN+DlA== X-Received: by 2002:a1c:28c4:: with SMTP id o187mr13118829wmo.40.1606545883369; Fri, 27 Nov 2020 22:44:43 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id s4sm18408046wro.10.2020.11.27.22.44.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Nov 2020 22:44:42 -0800 (PST) Message-Id: <5c3bdc212962a24f8f23207c6b1b3504c53903ad.1606545878.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sat, 28 Nov 2020 06:44:36 +0000 Subject: [PATCH 4/6] fixup! reftable: rest of library Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Han-Wen Nienhuys , Han-Wen Nienhuys , Jeff King , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin Avoid using `getopt()`: it might be POSIX, but Git's audience is much larger than POSIX. MSVC, for example, does not support `getopt()`. Without this patch, the `vs-build` job of our CI/PR builds would simply fail completely. Signed-off-by: Johannes Schindelin --- reftable/dump.c | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/reftable/dump.c b/reftable/dump.c index 0bd7a1cfa6..e990bffe0c 100644 --- a/reftable/dump.c +++ b/reftable/dump.c @@ -167,40 +167,34 @@ static void print_help(void) int reftable_dump_main(int argc, char *const *argv) { int err = 0; - int opt; int opt_dump_table = 0; int opt_dump_stack = 0; int opt_compact = 0; - const char *arg = NULL; - while ((opt = getopt(argc, argv, "2chts")) != -1) { - switch (opt) { - case '2': - hash_id = 0x73323536; + const char *arg = NULL, *argv0 = argv[0]; + + for (; argc > 1; argv++, argc--) + if (*argv[1] != '-') break; - case 't': + else if (!strcmp("-2", argv[1])) + hash_id = 0x73323536; + else if (!strcmp("-t", argv[1])) opt_dump_table = 1; - break; - case 's': + else if (!strcmp("-s", argv[1])) opt_dump_stack = 1; - break; - case 'c': + else if (!strcmp("-c", argv[1])) opt_compact = 1; - break; - case '?': - case 'h': + else if (!strcmp("-?", argv[1]) || !strcmp("-h", argv[1])) { print_help(); return 2; - break; } - } - if (argv[optind] == NULL) { + if (argc != 2) { fprintf(stderr, "need argument\n"); print_help(); return 2; } - arg = argv[optind]; + arg = argv[1]; if (opt_dump_table) { err = dump_table(arg); @@ -211,7 +205,7 @@ int reftable_dump_main(int argc, char *const *argv) } if (err < 0) { - fprintf(stderr, "%s: %s: %s\n", argv[0], arg, + fprintf(stderr, "%s: %s: %s\n", argv0, arg, reftable_error_str(err)); return 1; } From patchwork Sat Nov 28 06:44:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 11938291 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=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 1D25EC8302C for ; Sat, 28 Nov 2020 22:17:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E4FC12224B for ; Sat, 28 Nov 2020 22:17:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="d/B1UBLm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388931AbgK1Vtr (ORCPT ); Sat, 28 Nov 2020 16:49:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731707AbgK1SzN (ORCPT ); Sat, 28 Nov 2020 13:55:13 -0500 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91D5AC09424B for ; Fri, 27 Nov 2020 22:44:45 -0800 (PST) Received: by mail-wm1-x344.google.com with SMTP id g185so228259wmf.3 for ; Fri, 27 Nov 2020 22:44:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=GjRDj2Bo70S22H0AIBtEElGxzT1vN/EQIzALHBausfA=; b=d/B1UBLm/qMJRBnGBzrLv5DFMed/TBNdQ/O3G7cLSIETUV7cIA+r09aIIQ9SE3a8t0 Ezz+PizJ+KZlZJ3fqykN1tfAB7eLh5PWKjYb1p8UyjpRl+DXjz3hgd6c7jveOZoR7Bju NjawOgCikGWDAtPAZfDpXnSysv7zKKvEmXOcFtwnjR1V/2038TNIIdUJtHqh46JfqgXb zmr2H5vcbXrbvOn/suflhULcf5zZDESyPiiQno2j48oCDo0jbOKWSA5Y6PH7q7rePdTa c+ikiPOq3dcc9wOxnYz+jveS/BiOyleU6Enio96z2FqkmQW5erqNq5YHolpatDCPJM7F /aCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=GjRDj2Bo70S22H0AIBtEElGxzT1vN/EQIzALHBausfA=; b=P2pT8KbKr/i2wHoeBy83acKYaVqEeCDxHKPYc5raycgMTgqH2c3Dr6217qZFPz5Yxy 6nVHXXZC6FC7W01/NTCVNlISe4mp0NStjxL7llQ1LCIRDdp4/n3ntoRnbhEgfP1QwPei 3Zmu2rq5nt28LB3+czTWvzCo8ozF/b/SD6R7+m2Ewp4tMsdJnKzJoL2nT7r8uWlhFOmJ 6PRC7qbLvGmdmL3DL0vFlLH6HhGPOZkzNCYKe/n34HeV8rwmEUy0jI02ql4U29t2hhoL Pvvky1cwU4yzuHND/p+dUAd2YgRQtgfWfzYeWmscEEfbyP+CrVG4KQqWxw+eXIJ77lct P/zw== X-Gm-Message-State: AOAM530uaHX+Nh7kdY8pOfq+PSrnoEzDC/QAGJ8iTj+WIqLmEXwe8KX+ rK31M+6JemWZorMr3ecc2HyyWy4X35o= X-Google-Smtp-Source: ABdhPJwE78H/HEBZ/N3U1qSkof0JHkg8pYAYKESIkV09ZTFOiHd2mwQz1qbwFM9sEb4aj2is+qqJ0Q== X-Received: by 2002:a7b:cd11:: with SMTP id f17mr12804661wmj.127.1606545884226; Fri, 27 Nov 2020 22:44:44 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id v20sm15410454wmh.44.2020.11.27.22.44.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Nov 2020 22:44:43 -0800 (PST) Message-Id: <8d2ae6771b6584965920f5d21829b42b7fdba80f.1606545878.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sat, 28 Nov 2020 06:44:37 +0000 Subject: [PATCH 5/6] fixup! reftable: rest of library Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Han-Wen Nienhuys , Han-Wen Nienhuys , Jeff King , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin Yet another instance of `= {}` initialization. Signed-off-by: Johannes Schindelin --- reftable/dump.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/reftable/dump.c b/reftable/dump.c index e990bffe0c..7d620a3cf0 100644 --- a/reftable/dump.c +++ b/reftable/dump.c @@ -82,7 +82,7 @@ static int dump_table(const char *tablename) static int compact_stack(const char *stackdir) { struct reftable_stack *stack = NULL; - struct reftable_write_options cfg = {}; + struct reftable_write_options cfg = { 0 }; int err = reftable_new_stack(&stack, stackdir, cfg); if (err < 0) @@ -101,7 +101,7 @@ static int compact_stack(const char *stackdir) static int dump_stack(const char *stackdir) { struct reftable_stack *stack = NULL; - struct reftable_write_options cfg = {}; + struct reftable_write_options cfg = { 0 }; struct reftable_iterator it = { NULL }; struct reftable_ref_record ref = { NULL }; struct reftable_log_record log = { NULL }; From patchwork Sat Nov 28 06:44:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 11938281 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=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 53343C63798 for ; Sat, 28 Nov 2020 22:16:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 17777221FD for ; Sat, 28 Nov 2020 22:16:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ieskAgH1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389053AbgK1Vtt (ORCPT ); Sat, 28 Nov 2020 16:49:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732770AbgK1TDG (ORCPT ); Sat, 28 Nov 2020 14:03:06 -0500 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A189AC09424C for ; Fri, 27 Nov 2020 22:44:46 -0800 (PST) Received: by mail-wm1-x341.google.com with SMTP id f190so5277513wme.1 for ; Fri, 27 Nov 2020 22:44:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=b+pnXY7dabSgWLV5TuoCsS06Yfyzz5HKpiLYfb18E88=; b=ieskAgH1hiNS5uLmYb+hEyy2iFXLnSTM+a70hpfnlNO/r63uB+RiLVI/O3g17IMpCs vgZ8DN5TBp7YtkQ6bWlFzigRNclG8Xt7Kvtyfks9dBU8/Ml4eSV2zVUZ4R9Nn3JlmL+D gHIqWKfFcjhBssriMgBAz3euqYfxMhBXSOy2XJLnt6/9O9NwfoAX+nv4C51Bb3jQRPyI jEaK2P1W7WB+2Ae7lJSEqTi8Sn3EwJi/AFLMTHNzMeII0vcF1eWRfFGgn6KOrfonbln3 7ot4lUuN8j+B8e/xbfYCH3qOW2Qy9lt/er4T8Tc9rvl3r3hfdIRvdT4NJ4goOcY4CxIK jc0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=b+pnXY7dabSgWLV5TuoCsS06Yfyzz5HKpiLYfb18E88=; b=T9OdTH5RciKc6VgL7YRhVfPQ5ssX8LaN7Gs2pf8JksWSdfLycHR0vrlWRkl6aG9Dvr vbK5W/3Up4YlIxQeLBJ3djQRqkSkrS947JS7NoBBlk84zqNRSEu/R2JM6rfBKwlo6m7/ yNMk9E+o3CG7dEdzZwzcM/cSoQLJAoCqvIX76xLr8n3Rj8NM976R+RX3Qi9Z6O8zLIfT bc31VQ7WIfC3KNG572vEuGkXZisdN5ATbJRC6nnYrD+70rmLGYCEQcZTDxZo8w5n9if2 x8kijcW+EXrGrSknjm3FXjYz0joIVVig7Wv/KGI1xYFQAC569OQj/XnDyPa3pdxx9J/j zDmQ== X-Gm-Message-State: AOAM530GGZksL/XZ7+LC6IqoRoGa61KG0hEWOf3FvKSB+cV6OJsBu2ha tGUVzgS3P8YTHWGQPL2v95tadLkHM9g= X-Google-Smtp-Source: ABdhPJy22vhJPHQ8UWo561zZLLmby8Z9Rsnb5wj+aykVXrzzE+iqOF4NG9TKdE3oqxv/XKK7UqPI2g== X-Received: by 2002:a1c:309:: with SMTP id 9mr12514306wmd.80.1606545885107; Fri, 27 Nov 2020 22:44:45 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id d2sm18283197wrn.43.2020.11.27.22.44.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Nov 2020 22:44:44 -0800 (PST) Message-Id: In-Reply-To: References: Date: Sat, 28 Nov 2020 06:44:38 +0000 Subject: [PATCH 6/6] fixup! reftable: rest of library Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Han-Wen Nienhuys , Han-Wen Nienhuys , Jeff King , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin The stack_test hard-codes `/tmp/`. That is a particular problem on Windows where the temp directory is never at that location. Let's not do that, but instead use `TMPDIR` as we do in similar scenarios in the rest of Git's source code. Signed-off-by: Johannes Schindelin --- reftable/stack_test.c | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/reftable/stack_test.c b/reftable/stack_test.c index cf2e32a25c..c9beaf4dbf 100644 --- a/reftable/stack_test.c +++ b/reftable/stack_test.c @@ -28,9 +28,19 @@ static void clear_dir(const char *dirname) strbuf_release(&path); } +static char *get_tmp_template(const char *prefix) +{ + static struct strbuf path = STRBUF_INIT; + const char *tmp = getenv("TMPDIR"); + + strbuf_reset(&path); + strbuf_addf(&path, "%s/%s.XXXXXX", tmp ? tmp : "/tmp", prefix); + return path.buf; +} + static void test_read_file(void) { - char fn[256] = "/tmp/stack.test_read_file.XXXXXX"; + char *fn = get_tmp_template("stack.test_read_file"); int fd = mkstemp(fn); char out[1024] = "line1\n\nline2\nline3"; int n, err; @@ -99,7 +109,7 @@ static int write_test_log(struct reftable_writer *wr, void *arg) static void test_reftable_stack_add_one(void) { - char dir[256] = "/tmp/stack_test.XXXXXX"; + char *dir = get_tmp_template("stack_test"); struct reftable_write_options cfg = { 0 }; struct reftable_stack *st = NULL; int err; @@ -132,7 +142,7 @@ static void test_reftable_stack_uptodate(void) struct reftable_write_options cfg = { 0 }; struct reftable_stack *st1 = NULL; struct reftable_stack *st2 = NULL; - char dir[256] = "/tmp/stack_test.XXXXXX"; + char *dir = get_tmp_template("stack_test"); int err; struct reftable_ref_record ref1 = { .refname = "HEAD", @@ -171,7 +181,7 @@ static void test_reftable_stack_uptodate(void) static void test_reftable_stack_transaction_api(void) { - char dir[256] = "/tmp/stack_test.XXXXXX"; + char *dir = get_tmp_template("stack_test"); struct reftable_write_options cfg = { 0 }; struct reftable_stack *st = NULL; int err; @@ -216,7 +226,7 @@ static void test_reftable_stack_validate_refname(void) struct reftable_write_options cfg = { 0 }; struct reftable_stack *st = NULL; int err; - char dir[256] = "/tmp/stack_test.XXXXXX"; + char *dir = get_tmp_template("stack_test"); int i; struct reftable_ref_record ref = { .refname = "a/b", @@ -254,7 +264,7 @@ static int write_error(struct reftable_writer *wr, void *arg) static void test_reftable_stack_update_index_check(void) { - char dir[256] = "/tmp/stack_test.XXXXXX"; + char *dir = get_tmp_template("stack_test"); struct reftable_write_options cfg = { 0 }; struct reftable_stack *st = NULL; int err; @@ -284,7 +294,7 @@ static void test_reftable_stack_update_index_check(void) static void test_reftable_stack_lock_failure(void) { - char dir[256] = "/tmp/stack_test.XXXXXX"; + char *dir = get_tmp_template("stack_test"); struct reftable_write_options cfg = { 0 }; struct reftable_stack *st = NULL; int err, i; @@ -309,7 +319,7 @@ static void test_reftable_stack_add(void) .exact_log_message = 1, }; struct reftable_stack *st = NULL; - char dir[256] = "/tmp/stack_test.XXXXXX"; + char *dir = get_tmp_template("stack_test"); struct reftable_ref_record refs[2] = { { NULL } }; struct reftable_log_record logs[2] = { { NULL } }; int N = ARRAY_SIZE(refs); @@ -385,7 +395,7 @@ static void test_reftable_stack_log_normalize(void) 0, }; struct reftable_stack *st = NULL; - char dir[256] = "/tmp/stack_test.XXXXXX"; + char *dir = get_tmp_template("stack_test"); uint8_t h1[SHA1_SIZE] = { 0x01 }, h2[SHA1_SIZE] = { 0x02 }; @@ -436,7 +446,7 @@ static void test_reftable_stack_log_normalize(void) static void test_reftable_stack_tombstone(void) { int i = 0; - char dir[256] = "/tmp/stack_test.XXXXXX"; + char *dir = get_tmp_template("stack_test"); struct reftable_write_options cfg = { 0 }; struct reftable_stack *st = NULL; int err; @@ -511,7 +521,7 @@ static void test_reftable_stack_tombstone(void) static void test_reftable_stack_hash_id(void) { - char dir[256] = "/tmp/stack_test.XXXXXX"; + char *dir = get_tmp_template("stack_test"); struct reftable_write_options cfg = { 0 }; struct reftable_stack *st = NULL; int err; @@ -621,7 +631,7 @@ static void test_suggest_compaction_segment_nothing(void) static void test_reflog_expire(void) { - char dir[256] = "/tmp/stack.test_reflog_expire.XXXXXX"; + char *dir = get_tmp_template("stack.test_reflog_expire"); struct reftable_write_options cfg = { 0 }; struct reftable_stack *st = NULL; struct reftable_log_record logs[20] = { { NULL } }; @@ -701,7 +711,7 @@ static void test_empty_add(void) struct reftable_write_options cfg = { 0 }; struct reftable_stack *st = NULL; int err; - char dir[256] = "/tmp/stack_test.XXXXXX"; + char *dir = get_tmp_template("stack_test"); struct reftable_stack *st2 = NULL; EXPECT(mkdtemp(dir)); @@ -723,7 +733,7 @@ static void test_reftable_stack_auto_compaction(void) { struct reftable_write_options cfg = { 0 }; struct reftable_stack *st = NULL; - char dir[256] = "/tmp/stack_test.XXXXXX"; + char *dir = get_tmp_template("stack_test"); int err, i; int N = 100; EXPECT(mkdtemp(dir));