Skip to content

Commit 4fee6ff

Browse files
committed
Merge branch 'ps/reftable-portability'
Update reftable library part with what is used in libgit2 to improve portability to different target codebases and platforms. * ps/reftable-portability: reftable/system: add abstraction to mmap files reftable/system: add abstraction to retrieve time in milliseconds reftable/fsck: use REFTABLE_UNUSED instead of UNUSED reftable/stack: provide fsync(3p) via system header reftable: introduce "reftable-system.h" header
2 parents 0c0cbd8 + 87e4eee commit 4fee6ff

18 files changed

Lines changed: 105 additions & 70 deletions

refs/reftable-backend.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -366,11 +366,6 @@ static int reftable_be_config(const char *var, const char *value,
366366
return 0;
367367
}
368368

369-
static int reftable_be_fsync(int fd)
370-
{
371-
return fsync_component(FSYNC_COMPONENT_REFERENCE, fd);
372-
}
373-
374369
static struct ref_store *reftable_be_init(struct repository *repo,
375370
const char *payload,
376371
const char *gitdir,
@@ -408,7 +403,6 @@ static struct ref_store *reftable_be_init(struct repository *repo,
408403
refs->write_options.disable_auto_compact =
409404
!git_env_bool("GIT_TEST_REFTABLE_AUTOCOMPACTION", 1);
410405
refs->write_options.lock_timeout_ms = 100;
411-
refs->write_options.fsync = reftable_be_fsync;
412406

413407
repo_config(the_repository, reftable_be_config, &refs->write_options);
414408

reftable/blocksource.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,12 @@ void block_source_from_buf(struct reftable_block_source *bs,
9393
}
9494

9595
struct file_block_source {
96-
uint64_t size;
97-
unsigned char *data;
96+
struct reftable_mmap mmap;
9897
};
9998

10099
static uint64_t file_size(void *b)
101100
{
102-
return ((struct file_block_source *)b)->size;
101+
return ((struct file_block_source *)b)->mmap.size;
103102
}
104103

105104
static void file_release_data(void *b REFTABLE_UNUSED, struct reftable_block_data *dest REFTABLE_UNUSED)
@@ -109,16 +108,16 @@ static void file_release_data(void *b REFTABLE_UNUSED, struct reftable_block_dat
109108
static void file_close(void *v)
110109
{
111110
struct file_block_source *b = v;
112-
munmap(b->data, b->size);
111+
reftable_munmap(&b->mmap);
113112
reftable_free(b);
114113
}
115114

116115
static ssize_t file_read_data(void *v, struct reftable_block_data *dest, uint64_t off,
117116
uint32_t size)
118117
{
119118
struct file_block_source *b = v;
120-
assert(off + size <= b->size);
121-
dest->data = b->data + off;
119+
assert(off + size <= b->mmap.size);
120+
dest->data = (unsigned char *) b->mmap.data + off;
122121
dest->len = size;
123122
return size;
124123
}
@@ -156,13 +155,9 @@ int reftable_block_source_from_file(struct reftable_block_source *bs,
156155
goto out;
157156
}
158157

159-
p->size = st.st_size;
160-
p->data = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
161-
if (p->data == MAP_FAILED) {
162-
err = REFTABLE_IO_ERROR;
163-
p->data = NULL;
158+
err = reftable_mmap(&p->mmap, fd, st.st_size);
159+
if (err < 0)
164160
goto out;
165-
}
166161

167162
assert(!bs->ops);
168163
bs->ops = &file_vtable;

reftable/fsck.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ static int table_check_name(struct reftable_table *table,
6363

6464
static int table_checks(struct reftable_table *table,
6565
reftable_fsck_report_fn report_fn,
66-
reftable_fsck_verbose_fn verbose_fn UNUSED,
66+
reftable_fsck_verbose_fn verbose_fn REFTABLE_UNUSED,
6767
void *cb_data)
6868
{
6969
table_check_fn table_check_fns[] = {

reftable/reftable-basics.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#ifndef REFTABLE_BASICS_H
1010
#define REFTABLE_BASICS_H
1111

12-
#include <stddef.h>
12+
#include "reftable-system.h"
1313

1414
/* A buffer that contains arbitrary byte slices. */
1515
struct reftable_buf {

reftable/reftable-block.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
#ifndef REFTABLE_BLOCK_H
1010
#define REFTABLE_BLOCK_H
1111

12-
#include <stdint.h>
13-
12+
#include "reftable-system.h"
1413
#include "reftable-basics.h"
1514
#include "reftable-blocksource.h"
1615
#include "reftable-iterator.h"

reftable/reftable-blocksource.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#ifndef REFTABLE_BLOCKSOURCE_H
1010
#define REFTABLE_BLOCKSOURCE_H
1111

12-
#include <stdint.h>
12+
#include "reftable-system.h"
1313

1414
/*
1515
* Generic wrapper for a seekable readable file.

reftable/reftable-error.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#ifndef REFTABLE_ERROR_H
1010
#define REFTABLE_ERROR_H
1111

12+
#include "reftable-system.h"
13+
1214
/*
1315
* Errors in reftable calls are signaled with negative integer return values. 0
1416
* means success.

reftable/reftable-fsck.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef REFTABLE_FSCK_H
22
#define REFTABLE_FSCK_H
33

4+
#include "reftable-system.h"
45
#include "reftable-stack.h"
56

67
enum reftable_fsck_error {

reftable/reftable-iterator.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef REFTABLE_ITERATOR_H
1010
#define REFTABLE_ITERATOR_H
1111

12+
#include "reftable-system.h"
1213
#include "reftable-record.h"
1314

1415
struct reftable_iterator_vtable;

reftable/reftable-merged.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef REFTABLE_MERGED_H
1010
#define REFTABLE_MERGED_H
1111

12+
#include "reftable-system.h"
1213
#include "reftable-iterator.h"
1314

1415
/*

0 commit comments

Comments
 (0)