Skip to content

Commit a4bbd13

Browse files
committed
Merge branch 'hn/reftable'
The "reftable" backend for the refs API, without integrating into the refs subsystem, has been added. * hn/reftable: Add "test-tool dump-reftable" command. reftable: add dump utility reftable: implement stack, a mutable database of reftable files. reftable: implement refname validation reftable: add merged table view reftable: add a heap-based priority queue for reftable records reftable: reftable file level tests reftable: read reftable files reftable: generic interface to tables reftable: write reftable files reftable: a generic binary tree implementation reftable: reading/writing blocks Provide zlib's uncompress2 from compat/zlib-compat.c reftable: (de)serialization for the polymorphic record type. reftable: add blocksource, an abstraction for random access reads reftable: utility functions reftable: add error related functionality reftable: add LICENSE hash.h: provide constants for the hash IDs
2 parents e773545 + d860c86 commit a4bbd13

Some content is hidden

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

69 files changed

+11125
-12
lines changed

Makefile

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@ all::
256256
#
257257
# Define NO_DEFLATE_BOUND if your zlib does not have deflateBound.
258258
#
259+
# Define NO_UNCOMPRESS2 if your zlib does not have uncompress2.
260+
#
259261
# Define NO_NORETURN if using buggy versions of gcc 4.6+ and profile feedback,
260262
# as the compiler can crash (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49299)
261263
#
@@ -732,6 +734,7 @@ TEST_BUILTINS_OBJS += test-read-cache.o
732734
TEST_BUILTINS_OBJS += test-read-graph.o
733735
TEST_BUILTINS_OBJS += test-read-midx.o
734736
TEST_BUILTINS_OBJS += test-ref-store.o
737+
TEST_BUILTINS_OBJS += test-reftable.o
735738
TEST_BUILTINS_OBJS += test-regex.o
736739
TEST_BUILTINS_OBJS += test-repository.o
737740
TEST_BUILTINS_OBJS += test-revision-walking.o
@@ -810,6 +813,8 @@ TEST_SHELL_PATH = $(SHELL_PATH)
810813

811814
LIB_FILE = libgit.a
812815
XDIFF_LIB = xdiff/lib.a
816+
REFTABLE_LIB = reftable/libreftable.a
817+
REFTABLE_TEST_LIB = reftable/libreftable_test.a
813818

814819
GENERATED_H += command-list.h
815820
GENERATED_H += config-list.h
@@ -1189,7 +1194,7 @@ THIRD_PARTY_SOURCES += compat/regex/%
11891194
THIRD_PARTY_SOURCES += sha1collisiondetection/%
11901195
THIRD_PARTY_SOURCES += sha1dc/%
11911196

1192-
GITLIBS = common-main.o $(LIB_FILE) $(XDIFF_LIB)
1197+
GITLIBS = common-main.o $(LIB_FILE) $(XDIFF_LIB) $(REFTABLE_LIB)
11931198
EXTLIBS =
11941199

11951200
GIT_USER_AGENT = git/$(GIT_VERSION)
@@ -1720,6 +1725,11 @@ ifdef NO_DEFLATE_BOUND
17201725
BASIC_CFLAGS += -DNO_DEFLATE_BOUND
17211726
endif
17221727

1728+
ifdef NO_UNCOMPRESS2
1729+
BASIC_CFLAGS += -DNO_UNCOMPRESS2
1730+
REFTABLE_OBJS += compat/zlib-uncompress2.o
1731+
endif
1732+
17231733
ifdef NO_POSIX_GOODIES
17241734
BASIC_CFLAGS += -DNO_POSIX_GOODIES
17251735
endif
@@ -2431,7 +2441,36 @@ XDIFF_OBJS += xdiff/xutils.o
24312441
.PHONY: xdiff-objs
24322442
xdiff-objs: $(XDIFF_OBJS)
24332443

2444+
REFTABLE_OBJS += reftable/basics.o
2445+
REFTABLE_OBJS += reftable/error.o
2446+
REFTABLE_OBJS += reftable/block.o
2447+
REFTABLE_OBJS += reftable/blocksource.o
2448+
REFTABLE_OBJS += reftable/iter.o
2449+
REFTABLE_OBJS += reftable/publicbasics.o
2450+
REFTABLE_OBJS += reftable/merged.o
2451+
REFTABLE_OBJS += reftable/pq.o
2452+
REFTABLE_OBJS += reftable/reader.o
2453+
REFTABLE_OBJS += reftable/record.o
2454+
REFTABLE_OBJS += reftable/refname.o
2455+
REFTABLE_OBJS += reftable/generic.o
2456+
REFTABLE_OBJS += reftable/stack.o
2457+
REFTABLE_OBJS += reftable/tree.o
2458+
REFTABLE_OBJS += reftable/writer.o
2459+
2460+
REFTABLE_TEST_OBJS += reftable/basics_test.o
2461+
REFTABLE_TEST_OBJS += reftable/block_test.o
2462+
REFTABLE_TEST_OBJS += reftable/dump.o
2463+
REFTABLE_TEST_OBJS += reftable/merged_test.o
2464+
REFTABLE_TEST_OBJS += reftable/pq_test.o
2465+
REFTABLE_TEST_OBJS += reftable/record_test.o
2466+
REFTABLE_TEST_OBJS += reftable/readwrite_test.o
2467+
REFTABLE_TEST_OBJS += reftable/refname_test.o
2468+
REFTABLE_TEST_OBJS += reftable/stack_test.o
2469+
REFTABLE_TEST_OBJS += reftable/test_framework.o
2470+
REFTABLE_TEST_OBJS += reftable/tree_test.o
2471+
24342472
TEST_OBJS := $(patsubst %$X,%.o,$(TEST_PROGRAMS)) $(patsubst %,t/helper/%,$(TEST_BUILTINS_OBJS))
2473+
24352474
.PHONY: test-objs
24362475
test-objs: $(TEST_OBJS)
24372476

@@ -2447,6 +2486,8 @@ OBJECTS += $(PROGRAM_OBJS)
24472486
OBJECTS += $(TEST_OBJS)
24482487
OBJECTS += $(XDIFF_OBJS)
24492488
OBJECTS += $(FUZZ_OBJS)
2489+
OBJECTS += $(REFTABLE_OBJS) $(REFTABLE_TEST_OBJS)
2490+
24502491
ifndef NO_CURL
24512492
OBJECTS += http.o http-walker.o remote-curl.o
24522493
endif
@@ -2589,6 +2630,12 @@ $(LIB_FILE): $(LIB_OBJS)
25892630
$(XDIFF_LIB): $(XDIFF_OBJS)
25902631
$(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^
25912632

2633+
$(REFTABLE_LIB): $(REFTABLE_OBJS)
2634+
$(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^
2635+
2636+
$(REFTABLE_TEST_LIB): $(REFTABLE_TEST_OBJS)
2637+
$(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^
2638+
25922639
export DEFAULT_EDITOR DEFAULT_PAGER
25932640

25942641
Documentation/GIT-EXCLUDED-PROGRAMS: FORCE
@@ -2887,7 +2934,7 @@ perf: all
28872934

28882935
t/helper/test-tool$X: $(patsubst %,t/helper/%,$(TEST_BUILTINS_OBJS))
28892936

2890-
t/helper/test-%$X: t/helper/test-%.o GIT-LDFLAGS $(GITLIBS)
2937+
t/helper/test-%$X: t/helper/test-%.o GIT-LDFLAGS $(GITLIBS) $(REFTABLE_TEST_LIB)
28912938
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(filter %.a,$^) $(LIBS)
28922939

28932940
check-sha1:: t/helper/test-tool$X
@@ -3225,7 +3272,7 @@ cocciclean:
32253272
clean: profile-clean coverage-clean cocciclean
32263273
$(RM) *.res
32273274
$(RM) $(OBJECTS)
3228-
$(RM) $(LIB_FILE) $(XDIFF_LIB)
3275+
$(RM) $(LIB_FILE) $(XDIFF_LIB) $(REFTABLE_LIB) $(REFTABLE_TEST_LIB)
32293276
$(RM) $(ALL_PROGRAMS) $(SCRIPT_LIB) $(BUILT_INS) git$X
32303277
$(RM) $(TEST_PROGRAMS)
32313278
$(RM) $(FUZZ_PROGRAMS)

ci/lib.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ linux-gcc-default)
224224
;;
225225
Linux32)
226226
CC=gcc
227+
MAKEFLAGS="$MAKEFLAGS NO_UNCOMPRESS2=1"
227228
;;
228229
linux-musl)
229230
CC=gcc

compat/.gitattributes

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

compat/zlib-uncompress2.c

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/* taken from zlib's uncompr.c
2+
3+
commit cacf7f1d4e3d44d871b605da3b647f07d718623f
4+
Author: Mark Adler <[email protected]>
5+
Date: Sun Jan 15 09:18:46 2017 -0800
6+
7+
zlib 1.2.11
8+
9+
*/
10+
11+
#include "../reftable/system.h"
12+
#define z_const
13+
14+
/*
15+
* Copyright (C) 1995-2003, 2010, 2014, 2016 Jean-loup Gailly, Mark Adler
16+
* For conditions of distribution and use, see copyright notice in zlib.h
17+
*/
18+
19+
#include <zlib.h>
20+
21+
/* clang-format off */
22+
23+
/* ===========================================================================
24+
Decompresses the source buffer into the destination buffer. *sourceLen is
25+
the byte length of the source buffer. Upon entry, *destLen is the total size
26+
of the destination buffer, which must be large enough to hold the entire
27+
uncompressed data. (The size of the uncompressed data must have been saved
28+
previously by the compressor and transmitted to the decompressor by some
29+
mechanism outside the scope of this compression library.) Upon exit,
30+
*destLen is the size of the decompressed data and *sourceLen is the number
31+
of source bytes consumed. Upon return, source + *sourceLen points to the
32+
first unused input byte.
33+
34+
uncompress returns Z_OK if success, Z_MEM_ERROR if there was not enough
35+
memory, Z_BUF_ERROR if there was not enough room in the output buffer, or
36+
Z_DATA_ERROR if the input data was corrupted, including if the input data is
37+
an incomplete zlib stream.
38+
*/
39+
int ZEXPORT uncompress2 (
40+
Bytef *dest,
41+
uLongf *destLen,
42+
const Bytef *source,
43+
uLong *sourceLen) {
44+
z_stream stream;
45+
int err;
46+
const uInt max = (uInt)-1;
47+
uLong len, left;
48+
Byte buf[1]; /* for detection of incomplete stream when *destLen == 0 */
49+
50+
len = *sourceLen;
51+
if (*destLen) {
52+
left = *destLen;
53+
*destLen = 0;
54+
}
55+
else {
56+
left = 1;
57+
dest = buf;
58+
}
59+
60+
stream.next_in = (z_const Bytef *)source;
61+
stream.avail_in = 0;
62+
stream.zalloc = (alloc_func)0;
63+
stream.zfree = (free_func)0;
64+
stream.opaque = (voidpf)0;
65+
66+
err = inflateInit(&stream);
67+
if (err != Z_OK) return err;
68+
69+
stream.next_out = dest;
70+
stream.avail_out = 0;
71+
72+
do {
73+
if (stream.avail_out == 0) {
74+
stream.avail_out = left > (uLong)max ? max : (uInt)left;
75+
left -= stream.avail_out;
76+
}
77+
if (stream.avail_in == 0) {
78+
stream.avail_in = len > (uLong)max ? max : (uInt)len;
79+
len -= stream.avail_in;
80+
}
81+
err = inflate(&stream, Z_NO_FLUSH);
82+
} while (err == Z_OK);
83+
84+
*sourceLen -= len + stream.avail_in;
85+
if (dest != buf)
86+
*destLen = stream.total_out;
87+
else if (stream.total_out && err == Z_BUF_ERROR)
88+
left = 1;
89+
90+
inflateEnd(&stream);
91+
return err == Z_STREAM_END ? Z_OK :
92+
err == Z_NEED_DICT ? Z_DATA_ERROR :
93+
err == Z_BUF_ERROR && left + stream.avail_out ? Z_DATA_ERROR :
94+
err;
95+
}

config.mak.uname

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,10 @@ ifeq ($(uname_S),FreeBSD)
261261
FILENO_IS_A_MACRO = UnfortunatelyYes
262262
endif
263263
ifeq ($(uname_S),OpenBSD)
264+
# Versions < 7.0 need compatibility layer
265+
ifeq ($(shell expr "$(uname_R)" : "[1-6]\."),2)
266+
NO_UNCOMPRESS2 = UnfortunatelyYes
267+
endif
264268
NO_STRCASESTR = YesPlease
265269
NO_MEMMEM = YesPlease
266270
USE_ST_TIMESPEC = YesPlease
@@ -516,6 +520,7 @@ ifeq ($(uname_S),Interix)
516520
endif
517521
endif
518522
ifeq ($(uname_S),Minix)
523+
NO_UNCOMPRESS2 = YesPlease
519524
NO_IPV6 = YesPlease
520525
NO_ST_BLOCKS_IN_STRUCT_STAT = YesPlease
521526
NO_NSEC = YesPlease

configure.ac

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,9 +664,22 @@ AC_LINK_IFELSE([ZLIBTEST_SRC],
664664
NO_DEFLATE_BOUND=yes])
665665
LIBS="$old_LIBS"
666666

667+
AC_DEFUN([ZLIBTEST_UNCOMPRESS2_SRC], [
668+
AC_LANG_PROGRAM([#include <zlib.h>],
669+
[uncompress2(NULL,NULL,NULL,NULL);])])
670+
AC_MSG_CHECKING([for uncompress2 in -lz])
671+
old_LIBS="$LIBS"
672+
LIBS="$LIBS -lz"
673+
AC_LINK_IFELSE([ZLIBTEST_UNCOMPRESS2_SRC],
674+
[AC_MSG_RESULT([yes])],
675+
[AC_MSG_RESULT([no])
676+
NO_UNCOMPRESS2=yes])
677+
LIBS="$old_LIBS"
678+
667679
GIT_UNSTASH_FLAGS($ZLIB_PATH)
668680

669681
GIT_CONF_SUBST([NO_DEFLATE_BOUND])
682+
GIT_CONF_SUBST([NO_UNCOMPRESS2])
670683

671684
#
672685
# Define NEEDS_SOCKET if linking with libc is not enough (SunOS,

contrib/buildsystems/CMakeLists.txt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,12 @@ parse_makefile_for_sources(libxdiff_SOURCES "XDIFF_OBJS")
647647
list(TRANSFORM libxdiff_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/")
648648
add_library(xdiff STATIC ${libxdiff_SOURCES})
649649

650+
#reftable
651+
parse_makefile_for_sources(reftable_SOURCES "REFTABLE_OBJS")
652+
653+
list(TRANSFORM reftable_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/")
654+
add_library(reftable STATIC ${reftable_SOURCES})
655+
650656
if(WIN32)
651657
if(NOT MSVC)#use windres when compiling with gcc and clang
652658
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/git.res
@@ -669,7 +675,7 @@ endif()
669675
#link all required libraries to common-main
670676
add_library(common-main OBJECT ${CMAKE_SOURCE_DIR}/common-main.c)
671677

672-
target_link_libraries(common-main libgit xdiff ${ZLIB_LIBRARIES})
678+
target_link_libraries(common-main libgit xdiff reftable ${ZLIB_LIBRARIES})
673679
if(Intl_FOUND)
674680
target_link_libraries(common-main ${Intl_LIBRARIES})
675681
endif()
@@ -908,11 +914,15 @@ if(BUILD_TESTING)
908914
add_executable(test-fake-ssh ${CMAKE_SOURCE_DIR}/t/helper/test-fake-ssh.c)
909915
target_link_libraries(test-fake-ssh common-main)
910916

917+
#reftable-tests
918+
parse_makefile_for_sources(test-reftable_SOURCES "REFTABLE_TEST_OBJS")
919+
list(TRANSFORM test-reftable_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/")
920+
911921
#test-tool
912922
parse_makefile_for_sources(test-tool_SOURCES "TEST_BUILTINS_OBJS")
913923

914924
list(TRANSFORM test-tool_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/t/helper/")
915-
add_executable(test-tool ${CMAKE_SOURCE_DIR}/t/helper/test-tool.c ${test-tool_SOURCES})
925+
add_executable(test-tool ${CMAKE_SOURCE_DIR}/t/helper/test-tool.c ${test-tool_SOURCES} ${test-reftable_SOURCES})
916926
target_link_libraries(test-tool common-main)
917927

918928
set_target_properties(test-fake-ssh test-tool

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">

hash.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,18 @@ static inline void git_SHA256_Clone(git_SHA256_CTX *dst, const git_SHA256_CTX *s
9595
/* Number of algorithms supported (including unknown). */
9696
#define GIT_HASH_NALGOS (GIT_HASH_SHA256 + 1)
9797

98+
/* "sha1", big-endian */
99+
#define GIT_SHA1_FORMAT_ID 0x73686131
100+
98101
/* The length in bytes and in hex digits of an object name (SHA-1 value). */
99102
#define GIT_SHA1_RAWSZ 20
100103
#define GIT_SHA1_HEXSZ (2 * GIT_SHA1_RAWSZ)
101104
/* The block size of SHA-1. */
102105
#define GIT_SHA1_BLKSZ 64
103106

107+
/* "s256", big-endian */
108+
#define GIT_SHA256_FORMAT_ID 0x73323536
109+
104110
/* The length in bytes and in hex digits of an object name (SHA-256 value). */
105111
#define GIT_SHA256_RAWSZ 32
106112
#define GIT_SHA256_HEXSZ (2 * GIT_SHA256_RAWSZ)

object-file.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ static void git_hash_unknown_final_oid(struct object_id *oid, git_hash_ctx *ctx)
165165
BUG("trying to finalize unknown hash");
166166
}
167167

168-
169168
const struct git_hash_algo hash_algos[GIT_HASH_NALGOS] = {
170169
{
171170
NULL,
@@ -184,8 +183,7 @@ const struct git_hash_algo hash_algos[GIT_HASH_NALGOS] = {
184183
},
185184
{
186185
"sha1",
187-
/* "sha1", big-endian */
188-
0x73686131,
186+
GIT_SHA1_FORMAT_ID,
189187
GIT_SHA1_RAWSZ,
190188
GIT_SHA1_HEXSZ,
191189
GIT_SHA1_BLKSZ,
@@ -200,8 +198,7 @@ const struct git_hash_algo hash_algos[GIT_HASH_NALGOS] = {
200198
},
201199
{
202200
"sha256",
203-
/* "s256", big-endian */
204-
0x73323536,
201+
GIT_SHA256_FORMAT_ID,
205202
GIT_SHA256_RAWSZ,
206203
GIT_SHA256_HEXSZ,
207204
GIT_SHA256_BLKSZ,

0 commit comments

Comments
 (0)