Skip to content

Commit

Permalink
refs: alternate reftable ref backend implementation
Browse files Browse the repository at this point in the history
This introduces the reftable backend as an alternative to the packed
backend. This simplifies the code, because we now longer have to worry
about:

- pseudorefs and the HEAD ref
- worktrees
- commands that blur together files and references (cherry-pick, rebase)

This deviates from the spec that in
Documentation/technical/reftable.txt. It might be possible to update
the code such that all writes by default go to reftable directly. Then
the result would be compatible with an implementation that writes only
reftable (the reftable lock would still prevent races) relative to an
implementation that disregards loose refs. Or,  JGit could be adapted
to follow this implementation.

For this incremental path, the reftable format is arguably more
complex than necessary, as

- packed-refs doesn't support symrefs
- reflogs aren't moved into reftable/

on the other hand, the code is already there, and it's well-structured
and well-tested.

This implementation is a prototype. To test, you need to do `export
GIT_TEST_REFTABLE=1`. Doing so creates a handful of errors in the
test-suite, most seemingly related to the new behavior of pack-refs
(which creates a reftable/ dir and not a packed-refs file.), but it
seems overseeable.

Signed-off-by: Han-Wen Nienhuys <[email protected]>
  • Loading branch information
hanwen committed Sep 18, 2023
1 parent a5cb3ad commit 559c04c
Show file tree
Hide file tree
Showing 8 changed files with 1,766 additions and 15 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,7 @@ LIB_OBJS += reflog.o
LIB_OBJS += refs.o
LIB_OBJS += refs/debug.o
LIB_OBJS += refs/files-backend.o
LIB_OBJS += refs/reftable-backend.o
LIB_OBJS += refs/iterator.o
LIB_OBJS += refs/packed-backend.o
LIB_OBJS += refs/ref-cache.o
Expand Down
2 changes: 1 addition & 1 deletion config.mak.uname
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ vcxproj:

# Make .vcxproj files and add them
perl contrib/buildsystems/generate -g Vcxproj
git add -f git.sln {*,*/lib,t/helper/*}/*.vcxproj
git add -f git.sln {*,*/lib,*/libreftable,t/helper/*}/*.vcxproj

# Generate the LinkOrCopyBuiltins.targets and LinkOrCopyRemoteHttp.targets file
(echo '<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">' && \
Expand Down
2 changes: 1 addition & 1 deletion contrib/workdir/git-new-workdir
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ trap cleanup $siglist
# create the links to the original repo. explicitly exclude index, HEAD and
# logs/HEAD from the list since they are purely related to the current working
# directory, and should not be shared.
for x in config refs logs/refs objects info hooks packed-refs remotes rr-cache svn
for x in config refs logs/refs objects info hooks packed-refs remotes rr-cache svn reftable
do
# create a containing directory if needed
case $x in
Expand Down
8 changes: 7 additions & 1 deletion refs/files-backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "refs-internal.h"
#include "ref-cache.h"
#include "packed-backend.h"
#include "reftable-backend.h"
#include "../ident.h"
#include "../iterator.h"
#include "../dir-iterator.h"
Expand Down Expand Up @@ -103,8 +104,13 @@ static struct ref_store *files_ref_store_create(struct repository *repo,
refs->store_flags = flags;
get_common_dir_noenv(&sb, gitdir);
refs->gitcommondir = strbuf_detach(&sb, NULL);

/* TODO: should look at the repo to decide whether to use packed-refs or
* reftable. */
refs->packed_ref_store =
packed_ref_store_create(repo, refs->gitcommondir, flags);
git_env_bool("GIT_TEST_REFTABLE", 0)
? git_reftable_ref_store_create(repo, refs->gitcommondir, flags)
: packed_ref_store_create(repo, refs->gitcommondir, flags);

chdir_notify_reparent("files-backend $GIT_DIR", &refs->base.gitdir);
chdir_notify_reparent("files-backend $GIT_COMMONDIR",
Expand Down
14 changes: 2 additions & 12 deletions refs/packed-backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,7 @@ static int write_packed_entry(FILE *fh, const char *refname,
return 0;
}

int packed_refs_lock(struct ref_store *ref_store, int flags, struct strbuf *err)
static int packed_refs_lock(struct ref_store *ref_store, int flags, struct strbuf *err)
{
struct packed_ref_store *refs =
packed_downcast(ref_store, REF_STORE_WRITE | REF_STORE_MAIN,
Expand Down Expand Up @@ -1212,7 +1212,7 @@ int packed_refs_lock(struct ref_store *ref_store, int flags, struct strbuf *err)
return 0;
}

void packed_refs_unlock(struct ref_store *ref_store)
static void packed_refs_unlock(struct ref_store *ref_store)
{
struct packed_ref_store *refs = packed_downcast(
ref_store,
Expand All @@ -1224,16 +1224,6 @@ void packed_refs_unlock(struct ref_store *ref_store)
rollback_lock_file(&refs->lock);
}

int packed_refs_is_locked(struct ref_store *ref_store)
{
struct packed_ref_store *refs = packed_downcast(
ref_store,
REF_STORE_READ | REF_STORE_WRITE,
"packed_refs_is_locked");

return is_lock_file_locked(&refs->lock);
}

/*
* The packed-refs header line that we write out. Perhaps other traits
* will be added later.
Expand Down
1 change: 1 addition & 0 deletions refs/refs-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ struct ref_storage_be {
};

extern struct ref_storage_be refs_be_files;
extern struct ref_storage_be refs_be_reftable;
extern struct ref_storage_be refs_be_packed;

/*
Expand Down
Loading

0 comments on commit 559c04c

Please sign in to comment.