Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Documentation/gitnamespaces.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ gitnamespaces - Git namespaces
SYNOPSIS
--------
[verse]
GIT_NAMESPACE=<namespace> git <command>
GIT_NAMESPACE=<namespace> 'git upload-pack'
GIT_NAMESPACE=<namespace> 'git receive-pack'

Expand Down Expand Up @@ -45,11 +46,19 @@ also avoids ambiguity with strange namespace paths such as `foo/refs/heads/`,
which could otherwise generate directory/file conflicts within the `refs`
directory.

For ordinary Git commands, `GIT_NAMESPACE` selects the local ref view.
A ref such as `refs/heads/main` resolves to the corresponding ref inside
the selected namespace. Branch, tag, tracking, fetch, and push commands
use these logical ref names.

linkgit:git-upload-pack[1] and linkgit:git-receive-pack[1] rewrite the
names of refs as specified by `GIT_NAMESPACE`. git-upload-pack and
git-receive-pack will ignore all references outside the specified
namespace.

Reference maintenance commands such as linkgit:git-gc[1] protect refs from
all namespaces because every namespace shares the object store.

The smart HTTP server, linkgit:git-http-backend[1], will pass
GIT_NAMESPACE through to the backend programs; see
linkgit:git-http-backend[1] for sample configuration to expose
Expand Down
2 changes: 1 addition & 1 deletion builtin/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ static int should_write_commit_graph(struct gc_config *cfg UNUSED)
if (data.limit < 0)
return 1;

result = refs_for_each_ref(get_main_ref_store(the_repository),
result = refs_for_each_ref_all(get_main_ref_store(the_repository),
dfs_on_ref, &data);

repo_clear_commit_marks(the_repository, SEEN);
Expand Down
2 changes: 2 additions & 0 deletions builtin/pack-objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -5324,6 +5324,8 @@ int cmd_pack_objects(int argc,
strvec_push(&rp, "--objects");

if (rev_list_all) {
/* --all must protect every namespace in the shared object store. */
set_git_namespace_is_local(0);
use_internal_rev_list = 1;
strvec_push(&rp, "--all");
}
Expand Down
1 change: 1 addition & 0 deletions builtin/receive-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -2632,6 +2632,7 @@ int cmd_receive_pack(int argc,
OPT_END()
};

set_git_namespace_is_local(0);
packet_trace_identity("receive-pack");

argc = parse_options(argc, argv, prefix, options, receive_pack_usage, 0);
Expand Down
1 change: 1 addition & 0 deletions builtin/upload-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ int cmd_upload_pack(int argc,
};
unsigned enter_repo_flags = ENTER_REPO_ANY_OWNER_OK;

set_git_namespace_is_local(0);
packet_trace_identity("upload-pack");
disable_replace_refs();
save_commit_buffer = 0;
Expand Down
12 changes: 12 additions & 0 deletions environment.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,18 @@ int have_git_dir(void)
|| the_repository->gitdir;
}

static int git_namespace_local = 1;

int git_namespace_is_local(void)
{
return git_namespace_local;
}

void set_git_namespace_is_local(int is_local)
{
git_namespace_local = is_local;
}

const char *get_git_namespace(void)
{
static const char *namespace;
Expand Down
2 changes: 2 additions & 0 deletions environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ int use_optional_locks(void);

const char *get_git_namespace(void);
const char *strip_namespace(const char *namespaced_ref);
int git_namespace_is_local(void);
void set_git_namespace_is_local(int is_local);

int git_default_config(const char *, const char *,
const struct config_context *, void *);
Expand Down
1 change: 1 addition & 0 deletions http-backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,7 @@ int cmd_main(int argc UNUSED, const char **argv UNUSED)
int i;
struct strbuf hdr = STRBUF_INIT;

set_git_namespace_is_local(0);
set_die_routine(die_webcgi);
set_die_is_recursing_routine(die_webcgi_recursing);

Expand Down
2 changes: 1 addition & 1 deletion reachable.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ void mark_reachable_objects(struct rev_info *revs, int mark_reflog,
add_index_objects_to_pending(revs, 0);

/* Add all external refs */
refs_for_each_ref(get_main_ref_store(the_repository), add_one_ref,
refs_for_each_ref_all(get_main_ref_store(the_repository), add_one_ref,
revs);

/* detached HEAD is not included in the list above */
Expand Down
Loading
Loading