Skip to content

Commit f011ab3

Browse files
committed
Merge branch 'hn/reftable' into seen
The reftable backend for the refs API. * hn/reftable: reftable: "test-tool dump-reftable" command. reftable: rest of library reftable: file level tests reftable: read reftable files reftable: write reftable files reftable: a generic binary tree implementation reftable: reading/writing blocks reftable: (de)serialization for the polymorphic record type. reftable: utility functions reftable: add a barebones unittest framework vcxproj: adjust for the reftable changes reftable: define the public API reftable: add LICENSE
2 parents 8bf0681 + 0186e65 commit f011ab3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+10474
-5
lines changed

Makefile

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,7 @@ TEST_BUILTINS_OBJS += test-read-cache.o
731731
TEST_BUILTINS_OBJS += test-read-graph.o
732732
TEST_BUILTINS_OBJS += test-read-midx.o
733733
TEST_BUILTINS_OBJS += test-ref-store.o
734+
TEST_BUILTINS_OBJS += test-reftable.o
734735
TEST_BUILTINS_OBJS += test-regex.o
735736
TEST_BUILTINS_OBJS += test-repository.o
736737
TEST_BUILTINS_OBJS += test-revision-walking.o
@@ -820,6 +821,8 @@ TEST_SHELL_PATH = $(SHELL_PATH)
820821

821822
LIB_FILE = libgit.a
822823
XDIFF_LIB = xdiff/lib.a
824+
REFTABLE_LIB = reftable/libreftable.a
825+
REFTABLE_TEST_LIB = reftable/libreftable_test.a
823826

824827
GENERATED_H += config-list.h
825828
GENERATED_H += command-list.h
@@ -1187,7 +1190,7 @@ THIRD_PARTY_SOURCES += compat/regex/%
11871190
THIRD_PARTY_SOURCES += sha1collisiondetection/%
11881191
THIRD_PARTY_SOURCES += sha1dc/%
11891192

1190-
GITLIBS = common-main.o $(LIB_FILE) $(XDIFF_LIB)
1193+
GITLIBS = common-main.o $(LIB_FILE) $(XDIFF_LIB) $(REFTABLE_LIB)
11911194
EXTLIBS =
11921195

11931196
GIT_USER_AGENT = git/$(GIT_VERSION)
@@ -2388,10 +2391,41 @@ XDIFF_OBJS += xdiff/xpatience.o
23882391
XDIFF_OBJS += xdiff/xprepare.o
23892392
XDIFF_OBJS += xdiff/xutils.o
23902393

2394+
REFTABLE_OBJS += reftable/basics.o
2395+
REFTABLE_OBJS += reftable/block.o
2396+
REFTABLE_OBJS += reftable/blocksource.o
2397+
REFTABLE_OBJS += reftable/compat.o
2398+
REFTABLE_OBJS += reftable/iter.o
2399+
REFTABLE_OBJS += reftable/merged.o
2400+
REFTABLE_OBJS += reftable/pq.o
2401+
REFTABLE_OBJS += reftable/publicbasics.o
2402+
REFTABLE_OBJS += reftable/reader.o
2403+
REFTABLE_OBJS += reftable/record.o
2404+
REFTABLE_OBJS += reftable/refname.o
2405+
REFTABLE_OBJS += reftable/reftable.o
2406+
REFTABLE_OBJS += reftable/stack.o
2407+
REFTABLE_OBJS += reftable/strbuf.o
2408+
REFTABLE_OBJS += reftable/tree.o
2409+
REFTABLE_OBJS += reftable/writer.o
2410+
REFTABLE_OBJS += reftable/zlib-compat.o
2411+
2412+
REFTABLE_TEST_OBJS += reftable/block_test.o
2413+
REFTABLE_TEST_OBJS += reftable/dump.o
2414+
REFTABLE_TEST_OBJS += reftable/merged_test.o
2415+
REFTABLE_TEST_OBJS += reftable/record_test.o
2416+
REFTABLE_TEST_OBJS += reftable/refname_test.o
2417+
REFTABLE_TEST_OBJS += reftable/reftable_test.o
2418+
REFTABLE_TEST_OBJS += reftable/stack_test.o
2419+
REFTABLE_TEST_OBJS += reftable/strbuf_test.o
2420+
REFTABLE_TEST_OBJS += reftable/test_framework.o
2421+
REFTABLE_TEST_OBJS += reftable/tree_test.o
2422+
23912423
TEST_OBJS := $(patsubst %$X,%.o,$(TEST_PROGRAMS)) $(patsubst %,t/helper/%,$(TEST_BUILTINS_OBJS))
23922424
OBJECTS := $(LIB_OBJS) $(BUILTIN_OBJS) $(PROGRAM_OBJS) $(TEST_OBJS) \
23932425
$(XDIFF_OBJS) \
23942426
$(FUZZ_OBJS) \
2427+
$(REFTABLE_OBJS) \
2428+
$(REFTABLE_TEST_OBJS) \
23952429
common-main.o \
23962430
git.o
23972431
ifndef NO_CURL
@@ -2543,6 +2577,12 @@ $(LIB_FILE): $(LIB_OBJS)
25432577
$(XDIFF_LIB): $(XDIFF_OBJS)
25442578
$(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^
25452579

2580+
$(REFTABLE_LIB): $(REFTABLE_OBJS)
2581+
$(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^
2582+
2583+
$(REFTABLE_TEST_LIB): $(REFTABLE_TEST_OBJS)
2584+
$(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^
2585+
25462586
export DEFAULT_EDITOR DEFAULT_PAGER
25472587

25482588
Documentation/GIT-EXCLUDED-PROGRAMS: FORCE
@@ -2821,7 +2861,7 @@ perf: all
28212861

28222862
t/helper/test-tool$X: $(patsubst %,t/helper/%,$(TEST_BUILTINS_OBJS))
28232863

2824-
t/helper/test-%$X: t/helper/test-%.o GIT-LDFLAGS $(GITLIBS)
2864+
t/helper/test-%$X: t/helper/test-%.o GIT-LDFLAGS $(GITLIBS) $(REFTABLE_TEST_LIB)
28252865
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(filter %.a,$^) $(LIBS)
28262866

28272867
check-sha1:: t/helper/test-tool$X
@@ -3148,7 +3188,7 @@ cocciclean:
31483188
clean: profile-clean coverage-clean cocciclean
31493189
$(RM) *.res
31503190
$(RM) $(OBJECTS)
3151-
$(RM) $(LIB_FILE) $(XDIFF_LIB)
3191+
$(RM) $(LIB_FILE) $(XDIFF_LIB) $(REFTABLE_LIB) $(REFTABLE_TEST_LIB)
31523192
$(RM) $(ALL_PROGRAMS) $(SCRIPT_LIB) $(BUILT_INS) git$X
31533193
$(RM) $(TEST_PROGRAMS)
31543194
$(RM) $(FUZZ_PROGRAMS)

config.mak.uname

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ vcxproj:
709709
# Make .vcxproj files and add them
710710
unset QUIET_GEN QUIET_BUILT_IN; \
711711
perl contrib/buildsystems/generate -g Vcxproj
712-
git add -f git.sln {*,*/lib,t/helper/*}/*.vcxproj
712+
git add -f git.sln {*,*/lib,*/libreftable,t/helper/*}/*.vcxproj
713713

714714
# Generate the LinkOrCopyBuiltins.targets and LinkOrCopyRemoteHttp.targets file
715715
(echo '<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">' && \

contrib/buildsystems/Generators/Vcxproj.pm

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ sub createProject {
7777
my $libs_release = "\n ";
7878
my $libs_debug = "\n ";
7979
if (!$static_library) {
80-
$libs_release = join(";", sort(grep /^(?!libgit\.lib|xdiff\/lib\.lib|vcs-svn\/lib\.lib)/, @{$$build_structure{"$prefix${name}_LIBS"}}));
80+
$libs_release = join(";", sort(grep /^(?!libgit\.lib|xdiff\/lib\.lib|vcs-svn\/lib\.lib|reftable\/libreftable\.lib)/, @{$$build_structure{"$prefix${name}_LIBS"}}));
8181
$libs_debug = $libs_release;
8282
$libs_debug =~ s/zlib\.lib/zlibd\.lib/g;
8383
$libs_debug =~ s/libexpat\.lib/libexpatd\.lib/g;
@@ -232,6 +232,7 @@ EOM
232232
EOM
233233
if (!$static_library || $target =~ 'vcs-svn' || $target =~ 'xdiff') {
234234
my $uuid_libgit = $$build_structure{"LIBS_libgit_GUID"};
235+
my $uuid_libreftable = $$build_structure{"LIBS_reftable/libreftable_GUID"};
235236
my $uuid_xdiff_lib = $$build_structure{"LIBS_xdiff/lib_GUID"};
236237

237238
print F << "EOM";
@@ -241,6 +242,14 @@ EOM
241242
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
242243
</ProjectReference>
243244
EOM
245+
if (!($name =~ /xdiff|libreftable/)) {
246+
print F << "EOM";
247+
<ProjectReference Include="$cdup\\reftable\\libreftable\\libreftable.vcxproj">
248+
<Project>$uuid_libreftable</Project>
249+
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
250+
</ProjectReference>
251+
EOM
252+
}
244253
if (!($name =~ 'xdiff')) {
245254
print F << "EOM";
246255
<ProjectReference Include="$cdup\\xdiff\\lib\\xdiff_lib.vcxproj">

reftable/.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/zlib-compat.c whitespace=-indent-with-non-tab,-trailing-space

reftable/LICENSE

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
BSD License
2+
3+
Copyright (c) 2020, Google LLC
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are
8+
met:
9+
10+
* Redistributions of source code must retain the above copyright notice,
11+
this list of conditions and the following disclaimer.
12+
13+
* Redistributions in binary form must reproduce the above copyright
14+
notice, this list of conditions and the following disclaimer in the
15+
documentation and/or other materials provided with the distribution.
16+
17+
* Neither the name of Google LLC nor the names of its contributors may
18+
be used to endorse or promote products derived from this software
19+
without specific prior written permission.
20+
21+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

reftable/VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7134eb9f8171a9759800f4187f9e6dde997335e7 C: NULL iso 0 for init

reftable/basics.c

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/*
2+
Copyright 2020 Google LLC
3+
4+
Use of this source code is governed by a BSD-style
5+
license that can be found in the LICENSE file or at
6+
https://developers.google.com/open-source/licenses/bsd
7+
*/
8+
9+
#include "basics.h"
10+
11+
void put_be24(uint8_t *out, uint32_t i)
12+
{
13+
out[0] = (uint8_t)((i >> 16) & 0xff);
14+
out[1] = (uint8_t)((i >> 8) & 0xff);
15+
out[2] = (uint8_t)(i & 0xff);
16+
}
17+
18+
uint32_t get_be24(uint8_t *in)
19+
{
20+
return (uint32_t)(in[0]) << 16 | (uint32_t)(in[1]) << 8 |
21+
(uint32_t)(in[2]);
22+
}
23+
24+
void put_be16(uint8_t *out, uint16_t i)
25+
{
26+
out[0] = (uint8_t)((i >> 8) & 0xff);
27+
out[1] = (uint8_t)(i & 0xff);
28+
}
29+
30+
int binsearch(size_t sz, int (*f)(size_t k, void *args), void *args)
31+
{
32+
size_t lo = 0;
33+
size_t hi = sz;
34+
35+
/* invariant: (hi == sz) || f(hi) == true
36+
(lo == 0 && f(0) == true) || fi(lo) == false
37+
*/
38+
while (hi - lo > 1) {
39+
size_t mid = lo + (hi - lo) / 2;
40+
41+
int val = f(mid, args);
42+
if (val) {
43+
hi = mid;
44+
} else {
45+
lo = mid;
46+
}
47+
}
48+
49+
if (lo == 0) {
50+
if (f(0, args)) {
51+
return 0;
52+
} else {
53+
return 1;
54+
}
55+
}
56+
57+
return hi;
58+
}
59+
60+
void free_names(char **a)
61+
{
62+
char **p = a;
63+
if (p == NULL) {
64+
return;
65+
}
66+
while (*p) {
67+
reftable_free(*p);
68+
p++;
69+
}
70+
reftable_free(a);
71+
}
72+
73+
int names_length(char **names)
74+
{
75+
int len = 0;
76+
char **p = names;
77+
while (*p) {
78+
p++;
79+
len++;
80+
}
81+
return len;
82+
}
83+
84+
void parse_names(char *buf, int size, char ***namesp)
85+
{
86+
char **names = NULL;
87+
size_t names_cap = 0;
88+
size_t names_len = 0;
89+
90+
char *p = buf;
91+
char *end = buf + size;
92+
while (p < end) {
93+
char *next = strchr(p, '\n');
94+
if (next != NULL) {
95+
*next = 0;
96+
} else {
97+
next = end;
98+
}
99+
if (p < next) {
100+
if (names_len == names_cap) {
101+
names_cap = 2 * names_cap + 1;
102+
names = reftable_realloc(
103+
names, names_cap * sizeof(char *));
104+
}
105+
names[names_len++] = xstrdup(p);
106+
}
107+
p = next + 1;
108+
}
109+
110+
if (names_len == names_cap) {
111+
names_cap = 2 * names_cap + 1;
112+
names = reftable_realloc(names, names_cap * sizeof(char *));
113+
}
114+
115+
names[names_len] = NULL;
116+
*namesp = names;
117+
}
118+
119+
int names_equal(char **a, char **b)
120+
{
121+
while (*a && *b) {
122+
if (strcmp(*a, *b)) {
123+
return 0;
124+
}
125+
126+
a++;
127+
b++;
128+
}
129+
130+
return *a == *b;
131+
}

reftable/basics.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
Copyright 2020 Google LLC
3+
4+
Use of this source code is governed by a BSD-style
5+
license that can be found in the LICENSE file or at
6+
https://developers.google.com/open-source/licenses/bsd
7+
*/
8+
9+
#ifndef BASICS_H
10+
#define BASICS_H
11+
12+
#include "system.h"
13+
14+
/* Bigendian en/decoding of integers */
15+
16+
void put_be24(uint8_t *out, uint32_t i);
17+
uint32_t get_be24(uint8_t *in);
18+
void put_be16(uint8_t *out, uint16_t i);
19+
20+
/*
21+
find smallest index i in [0, sz) at which f(i) is true, assuming
22+
that f is ascending. Return sz if f(i) is false for all indices.
23+
*/
24+
int binsearch(size_t sz, int (*f)(size_t k, void *args), void *args);
25+
26+
/*
27+
Frees a NULL terminated array of malloced strings. The array itself is also
28+
freed.
29+
*/
30+
void free_names(char **a);
31+
32+
/* parse a newline separated list of names. Empty names are discarded. */
33+
void parse_names(char *buf, int size, char ***namesp);
34+
35+
/* compares two NULL-terminated arrays of strings. */
36+
int names_equal(char **a, char **b);
37+
38+
/* returns the array size of a NULL-terminated array of strings. */
39+
int names_length(char **names);
40+
41+
/* Allocation routines; they invoke the functions set through
42+
* reftable_set_alloc() */
43+
void *reftable_malloc(size_t sz);
44+
void *reftable_realloc(void *p, size_t sz);
45+
void reftable_free(void *p);
46+
void *reftable_calloc(size_t sz);
47+
48+
#endif

0 commit comments

Comments
 (0)