From: "Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Han-Wen Nienhuys <hanwenn@gmail.com>,
Han-Wen Nienhuys <hanwen@google.com>, Jeff King <peff@peff.net>,
Johannes Schindelin <johannes.schindelin@gmx.de>,
Johannes Schindelin <johannes.schindelin@gmx.de>
Subject: [PATCH 6/6] fixup! reftable: rest of library
Date: Sat, 28 Nov 2020 06:44:38 +0000 [thread overview]
Message-ID: <ded8d502d97d3d48dc0e4397b6153f4b06fa319b.1606545878.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.801.git.1606545878.gitgitgadget@gmail.com>
From: Johannes Schindelin <johannes.schindelin@gmx.de>
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 <johannes.schindelin@gmx.de>
---
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));
--
gitgitgadget
next prev parent reply other threads:[~2020-11-28 22:55 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-28 6:44 [PATCH 0/6] Minimal patches to let reftable pass the CI builds Johannes Schindelin via GitGitGadget
2020-11-28 6:44 ` [PATCH 1/6] fixup! reftable: rest of library Johannes Schindelin via GitGitGadget
2020-12-01 14:32 ` Han-Wen Nienhuys
2020-12-02 10:57 ` Johannes Schindelin
2020-12-02 18:31 ` Reftable locking on Windows (Re: [PATCH 1/6] fixup! reftable: rest of library) Han-Wen Nienhuys
2020-12-03 12:24 ` Ævar Arnfjörð Bjarmason
2020-12-03 13:56 ` Han-Wen Nienhuys
2020-11-28 6:44 ` [PATCH 2/6] fixup! reftable: utility functions Johannes Schindelin via GitGitGadget
2020-11-28 6:44 ` [PATCH 3/6] fixup! reftable: rest of library Johannes Schindelin via GitGitGadget
2020-12-01 10:26 ` Jeff King
2020-12-01 11:10 ` Han-Wen Nienhuys
2020-12-01 11:57 ` Jeff King
2020-11-28 6:44 ` [PATCH 4/6] " Johannes Schindelin via GitGitGadget
2020-11-28 6:44 ` [PATCH 5/6] " Johannes Schindelin via GitGitGadget
2020-11-28 6:44 ` Johannes Schindelin via GitGitGadget [this message]
2020-12-01 10:28 ` [PATCH 6/6] " Jeff King
2020-12-01 14:24 ` Johannes Schindelin
2020-12-02 1:50 ` Jeff King
2020-12-02 11:01 ` Han-Wen Nienhuys
2020-12-02 12:43 ` Jeff King
2020-11-30 14:26 ` [PATCH 0/6] Minimal patches to let reftable pass the CI builds Han-Wen Nienhuys
2020-12-01 14:18 ` Johannes Schindelin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ded8d502d97d3d48dc0e4397b6153f4b06fa319b.1606545878.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=git@vger.kernel.org \
--cc=hanwen@google.com \
--cc=hanwenn@gmail.com \
--cc=johannes.schindelin@gmx.de \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).