git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
6e9a15da38a37232e933b1f18ce7b71c39ab6ebe blob 2231 bytes (raw)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
 
/*
Copyright 2020 Google LLC

Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file or at
https://developers.google.com/open-source/licenses/bsd
*/

#include "reftable.h"

#include "basics.h"
#include "block.h"
#include "blocksource.h"
#include "constants.h"
#include "reader.h"
#include "record.h"
#include "refname.h"
#include "system.h"

#include "test_framework.h"
#include "reftable-tests.h"

struct testcase {
	char *add;
	char *del;
	int error_code;
};

static void test_conflict(void)
{
	struct reftable_write_options opts = { 0 };
	struct strbuf buf = STRBUF_INIT;
	struct reftable_writer *w =
		reftable_new_writer(&strbuf_add_void, &buf, &opts);
	struct reftable_ref_record rec = {
		.refname = "a/b",
		.target = "destination", /* make sure it's not a symref. */
		.update_index = 1,
	};
	int err;
	int i;
	struct reftable_block_source source = { NULL };
	struct reftable_reader *rd = NULL;
	struct reftable_table tab = { NULL };
	struct testcase cases[] = {
		{ "a/b/c", NULL, REFTABLE_NAME_CONFLICT },
		{ "b", NULL, 0 },
		{ "a", NULL, REFTABLE_NAME_CONFLICT },
		{ "a", "a/b", 0 },

		{ "p/", NULL, REFTABLE_REFNAME_ERROR },
		{ "p//q", NULL, REFTABLE_REFNAME_ERROR },
		{ "p/./q", NULL, REFTABLE_REFNAME_ERROR },
		{ "p/../q", NULL, REFTABLE_REFNAME_ERROR },

		{ "a/b/c", "a/b", 0 },
		{ NULL, "a//b", 0 },
	};
	reftable_writer_set_limits(w, 1, 1);

	err = reftable_writer_add_ref(w, &rec);
	assert_err(err);

	err = reftable_writer_close(w);
	assert_err(err);
	reftable_writer_free(w);

	block_source_from_strbuf(&source, &buf);
	err = reftable_new_reader(&rd, &source, "filename");
	assert_err(err);

	reftable_table_from_reader(&tab, rd);

	for (i = 0; i < ARRAY_SIZE(cases); i++) {
		struct modification mod = {
			.tab = tab,
		};

		if (cases[i].add != NULL) {
			mod.add = &cases[i].add;
			mod.add_len = 1;
		}
		if (cases[i].del != NULL) {
			mod.del = &cases[i].del;
			mod.del_len = 1;
		}

		err = modification_validate(&mod);
		assert(err == cases[i].error_code);
	}

	reftable_reader_free(rd);
	strbuf_release(&buf);
}

int refname_test_main(int argc, const char *argv[])
{
	add_test_case("test_conflict", &test_conflict);
	return test_main(argc, argv);
}
debug log:

solving 6e9a15da38 ...
found 6e9a15da38 in https://public-inbox.org/git/4e38db7f48295c4e6d729880f5f1a63b0f90274e.1601568664.git.gitgitgadget@gmail.com/

applying [1/1] https://public-inbox.org/git/4e38db7f48295c4e6d729880f5f1a63b0f90274e.1601568664.git.gitgitgadget@gmail.com/
diff --git a/reftable/refname_test.c b/reftable/refname_test.c
new file mode 100644
index 0000000000..6e9a15da38

Checking patch reftable/refname_test.c...
Applied patch reftable/refname_test.c cleanly.

index at:
100644 6e9a15da38a37232e933b1f18ce7b71c39ab6ebe	reftable/refname_test.c

git@vger.kernel.org list mirror (unofficial, one of many)

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 git git/ https://public-inbox.org/git \
		git@vger.kernel.org
	public-inbox-index git

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/inbox.comp.version-control.git
	nntp://ie5yzdi7fg72h7s4sdcztq5evakq23rdt33mfyfcddc5u3ndnw24ogqd.onion/inbox.comp.version-control.git
	nntp://4uok3hntl7oi7b4uf4rtfwefqeexfzil2w6kgk2jn5z2f764irre7byd.onion/inbox.comp.version-control.git
	nntp://news.gmane.io/gmane.comp.version-control.git
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git