* [PATCH v5 17/24] refs: rename get_ref_store() to get_submodule_ref_store() and make it public
From: Nguyễn Thái Ngọc Duy @ 2017-02-22 14:04 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Michael Haggerty, Johannes Schindelin,
Ramsay Jones, Stefan Beller, novalis,
Nguyễn Thái Ngọc Duy
In-Reply-To: <20170222140450.30886-1-pclouds@gmail.com>
This function is intended to replace *_submodule() refs API. It provides
a ref store for a specific submodule, which can be operated on by a new
set of refs API.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
refs.c | 12 ++++++++----
refs.h | 11 +++++++++++
refs/refs-internal.h | 12 ------------
3 files changed, 19 insertions(+), 16 deletions(-)
diff --git a/refs.c b/refs.c
index 2dc97891a..7843d3085 100644
--- a/refs.c
+++ b/refs.c
@@ -1171,7 +1171,7 @@ int head_ref(each_ref_fn fn, void *cb_data)
static int do_for_each_ref(const char *submodule, const char *prefix,
each_ref_fn fn, int trim, int flags, void *cb_data)
{
- struct ref_store *refs = get_ref_store(submodule);
+ struct ref_store *refs = get_submodule_ref_store(submodule);
struct ref_iterator *iter;
if (!refs)
@@ -1344,10 +1344,10 @@ int resolve_gitlink_ref(const char *submodule, const char *refname,
/* We need to strip off one or more trailing slashes */
char *stripped = xmemdupz(submodule, len);
- refs = get_ref_store(stripped);
+ refs = get_submodule_ref_store(stripped);
free(stripped);
} else {
- refs = get_ref_store(submodule);
+ refs = get_submodule_ref_store(submodule);
}
if (!refs)
@@ -1468,13 +1468,17 @@ static void register_submodule_ref_store(struct ref_store *refs,
submodule);
}
-struct ref_store *get_ref_store(const char *submodule)
+struct ref_store *get_submodule_ref_store(const char *submodule)
{
struct strbuf submodule_sb = STRBUF_INIT;
struct ref_store *refs;
int ret;
if (!submodule || !*submodule) {
+ /*
+ * FIXME: This case is ideally not allowed. But that
+ * can't happen until we clean up all the callers.
+ */
return get_main_ref_store();
}
diff --git a/refs.h b/refs.h
index 29013cb7e..2efba6ba9 100644
--- a/refs.h
+++ b/refs.h
@@ -561,5 +561,16 @@ int reflog_expire(const char *refname, const unsigned char *sha1,
int ref_storage_backend_exists(const char *name);
struct ref_store *get_main_ref_store(void);
+/*
+ * Return the ref_store instance for the specified submodule. For the
+ * main repository, use submodule==NULL; such a call cannot fail. For
+ * a submodule, the submodule must exist and be a nonbare repository,
+ * otherwise return NULL. If the requested reference store has not yet
+ * been initialized, initialize it first.
+ *
+ * For backwards compatibility, submodule=="" is treated the same as
+ * submodule==NULL.
+ */
+struct ref_store *get_submodule_ref_store(const char *submodule);
#endif /* REFS_H */
diff --git a/refs/refs-internal.h b/refs/refs-internal.h
index 0cca280b5..f20dde39e 100644
--- a/refs/refs-internal.h
+++ b/refs/refs-internal.h
@@ -646,18 +646,6 @@ struct ref_store {
void base_ref_store_init(struct ref_store *refs,
const struct ref_storage_be *be);
-/*
- * Return the ref_store instance for the specified submodule. For the
- * main repository, use submodule==NULL; such a call cannot fail. For
- * a submodule, the submodule must exist and be a nonbare repository,
- * otherwise return NULL. If the requested reference store has not yet
- * been initialized, initialize it first.
- *
- * For backwards compatibility, submodule=="" is treated the same as
- * submodule==NULL.
- */
-struct ref_store *get_ref_store(const char *submodule);
-
const char *resolve_ref_recursively(struct ref_store *refs,
const char *refname,
int resolve_flags,
--
2.11.0.157.gd943d85
^ permalink raw reply related
* [PATCH v5 15/24] refs: move submodule code out of files-backend.c
From: Nguyễn Thái Ngọc Duy @ 2017-02-22 14:04 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Michael Haggerty, Johannes Schindelin,
Ramsay Jones, Stefan Beller, novalis,
Nguyễn Thái Ngọc Duy
In-Reply-To: <20170222140450.30886-1-pclouds@gmail.com>
files-backend is now initialized with a $GIT_DIR. Converting a submodule
path to where real submodule gitdir is located is done in get_ref_store().
This gives a slight performance improvement for submodules since we
don't convert submodule path to gitdir at every backend call like
before. We pay that once at ref-store creation.
More cleanup in files_downcast() and files_assert_main_repository()
follows shortly. It's separate to keep noises from this patch.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
refs.c | 20 ++++++++++++++------
refs/files-backend.c | 24 ++----------------------
refs/refs-internal.h | 9 ++++-----
3 files changed, 20 insertions(+), 33 deletions(-)
diff --git a/refs.c b/refs.c
index 562834fc0..67acae60c 100644
--- a/refs.c
+++ b/refs.c
@@ -9,6 +9,7 @@
#include "refs/refs-internal.h"
#include "object.h"
#include "tag.h"
+#include "submodule.h"
/*
* List of all available backends
@@ -1413,9 +1414,9 @@ static struct ref_store *lookup_submodule_ref_store(const char *submodule)
/*
* Create, record, and return a ref_store instance for the specified
- * submodule (or the main repository if submodule is NULL).
+ * gitdir.
*/
-static struct ref_store *ref_store_init(const char *submodule)
+static struct ref_store *ref_store_init(const char *gitdir)
{
const char *be_name = "files";
struct ref_storage_be *be = find_ref_storage_backend(be_name);
@@ -1424,7 +1425,7 @@ static struct ref_store *ref_store_init(const char *submodule)
if (!be)
die("BUG: reference backend %s is unknown", be_name);
- refs = be->init(submodule);
+ refs = be->init(gitdir);
return refs;
}
@@ -1435,7 +1436,7 @@ struct ref_store *get_main_ref_store(void)
if (main_ref_store)
return main_ref_store;
- refs = ref_store_init(NULL);
+ refs = ref_store_init(get_git_dir());
if (refs) {
if (main_ref_store)
die("BUG: main_ref_store initialized twice");
@@ -1466,6 +1467,7 @@ struct ref_store *get_ref_store(const char *submodule)
{
struct strbuf submodule_sb = STRBUF_INIT;
struct ref_store *refs;
+ int ret;
if (!submodule || !*submodule) {
return get_main_ref_store();
@@ -1476,8 +1478,14 @@ struct ref_store *get_ref_store(const char *submodule)
return refs;
strbuf_addstr(&submodule_sb, submodule);
- if (is_nonbare_repository_dir(&submodule_sb))
- refs = ref_store_init(submodule);
+ ret = is_nonbare_repository_dir(&submodule_sb);
+ strbuf_release(&submodule_sb);
+ if (!ret)
+ return refs;
+
+ ret = submodule_to_gitdir(&submodule_sb, submodule);
+ if (!ret)
+ refs = ref_store_init(submodule_sb.buf);
strbuf_release(&submodule_sb);
if (refs)
diff --git a/refs/files-backend.c b/refs/files-backend.c
index d80c27837..37443369b 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -917,12 +917,6 @@ struct packed_ref_cache {
struct files_ref_store {
struct ref_store base;
- /*
- * The name of the submodule represented by this object, or
- * NULL if it represents the main repository's reference
- * store:
- */
- const char *submodule;
char *gitdir;
char *gitcommondir;
char *packed_refs_path;
@@ -982,22 +976,14 @@ static void clear_loose_ref_cache(struct files_ref_store *refs)
* Create a new submodule ref cache and add it to the internal
* set of caches.
*/
-static struct ref_store *files_ref_store_create(const char *submodule)
+static struct ref_store *files_ref_store_create(const char *gitdir)
{
struct files_ref_store *refs = xcalloc(1, sizeof(*refs));
struct ref_store *ref_store = (struct ref_store *)refs;
struct strbuf sb = STRBUF_INIT;
- const char *gitdir = get_git_dir();
base_ref_store_init(ref_store, &refs_be_files);
- if (submodule) {
- refs->submodule = xstrdup(submodule);
- refs->packed_refs_path = git_pathdup_submodule(
- refs->submodule, "packed-refs");
- return ref_store;
- }
-
refs->gitdir = xstrdup(gitdir);
get_common_dir_noenv(&sb, gitdir);
refs->gitcommondir = strbuf_detach(&sb, NULL);
@@ -1014,8 +1000,7 @@ static struct ref_store *files_ref_store_create(const char *submodule)
static void files_assert_main_repository(struct files_ref_store *refs,
const char *caller)
{
- if (refs->submodule)
- die("BUG: %s called for a submodule", caller);
+ /* This function is to be deleted in the next patch */
}
/*
@@ -1206,11 +1191,6 @@ static void files_refname_path(struct files_ref_store *refs,
struct strbuf *sb,
const char *refname)
{
- if (refs->submodule) {
- strbuf_git_path_submodule(sb, refs->submodule, "%s", refname);
- return;
- }
-
switch (ref_type(refname)) {
case REF_TYPE_PER_WORKTREE:
case REF_TYPE_PSEUDOREF:
diff --git a/refs/refs-internal.h b/refs/refs-internal.h
index f732473e1..dfa181792 100644
--- a/refs/refs-internal.h
+++ b/refs/refs-internal.h
@@ -482,12 +482,11 @@ struct ref_store;
/* refs backends */
/*
- * Initialize the ref_store for the specified submodule, or for the
- * main repository if submodule == NULL. These functions should call
- * base_ref_store_init() to initialize the shared part of the
- * ref_store and to record the ref_store for later lookup.
+ * Initialize the ref_store for the specified gitdir. These functions
+ * should call base_ref_store_init() to initialize the shared part of
+ * the ref_store and to record the ref_store for later lookup.
*/
-typedef struct ref_store *ref_store_init_fn(const char *submodule);
+typedef struct ref_store *ref_store_init_fn(const char *gitdir);
typedef int ref_init_db_fn(struct ref_store *refs, struct strbuf *err);
--
2.11.0.157.gd943d85
^ permalink raw reply related
* [PATCH v5 16/24] files-backend: replace submodule_allowed check in files_downcast()
From: Nguyễn Thái Ngọc Duy @ 2017-02-22 14:04 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Michael Haggerty, Johannes Schindelin,
Ramsay Jones, Stefan Beller, novalis,
Nguyễn Thái Ngọc Duy
In-Reply-To: <20170222140450.30886-1-pclouds@gmail.com>
files-backend.c is unlearning submodules. Instead of having a specific
check for submodules to see what operation is allowed, files backend
now takes a set of flags at init. Each operation will check if the
required flags is present before performing.
For now we have four flags: read, write and odb access. Main ref store
has all flags, obviously, while submodule stores are read-only and have
access to odb (*).
The "main" flag stays because many functions in the backend calls
frontend ones without a ref store, so these functions always target the
main ref store. Ideally the flag should be gone after ref-store-aware
api is in place and used by backends.
(*) Submodule code needs for_each_ref. Try take REF_STORE_ODB flag
out. At least t3404 would fail. The "have access to odb" in submodule is
a bit hacky since we don't know from he whether add_submodule_odb() has
been called.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
refs.c | 15 ++++++---
refs/files-backend.c | 86 +++++++++++++++++++++++++++++++++-------------------
refs/refs-internal.h | 9 +++++-
3 files changed, 73 insertions(+), 37 deletions(-)
diff --git a/refs.c b/refs.c
index 67acae60c..2dc97891a 100644
--- a/refs.c
+++ b/refs.c
@@ -1416,7 +1416,8 @@ static struct ref_store *lookup_submodule_ref_store(const char *submodule)
* Create, record, and return a ref_store instance for the specified
* gitdir.
*/
-static struct ref_store *ref_store_init(const char *gitdir)
+static struct ref_store *ref_store_init(const char *gitdir,
+ unsigned int flags)
{
const char *be_name = "files";
struct ref_storage_be *be = find_ref_storage_backend(be_name);
@@ -1425,7 +1426,7 @@ static struct ref_store *ref_store_init(const char *gitdir)
if (!be)
die("BUG: reference backend %s is unknown", be_name);
- refs = be->init(gitdir);
+ refs = be->init(gitdir, flags);
return refs;
}
@@ -1436,7 +1437,11 @@ struct ref_store *get_main_ref_store(void)
if (main_ref_store)
return main_ref_store;
- refs = ref_store_init(get_git_dir());
+ refs = ref_store_init(get_git_dir(),
+ (REF_STORE_READ |
+ REF_STORE_WRITE |
+ REF_STORE_ODB |
+ REF_STORE_MAIN));
if (refs) {
if (main_ref_store)
die("BUG: main_ref_store initialized twice");
@@ -1485,7 +1490,9 @@ struct ref_store *get_ref_store(const char *submodule)
ret = submodule_to_gitdir(&submodule_sb, submodule);
if (!ret)
- refs = ref_store_init(submodule_sb.buf);
+ /* pretend that add_submodule_odb() has been called */
+ refs = ref_store_init(submodule_sb.buf,
+ REF_STORE_READ | REF_STORE_ODB);
strbuf_release(&submodule_sb);
if (refs)
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 37443369b..474d1027c 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -916,6 +916,7 @@ struct packed_ref_cache {
*/
struct files_ref_store {
struct ref_store base;
+ unsigned int store_flags;
char *gitdir;
char *gitcommondir;
@@ -976,13 +977,15 @@ static void clear_loose_ref_cache(struct files_ref_store *refs)
* Create a new submodule ref cache and add it to the internal
* set of caches.
*/
-static struct ref_store *files_ref_store_create(const char *gitdir)
+static struct ref_store *files_ref_store_create(const char *gitdir,
+ unsigned int flags)
{
struct files_ref_store *refs = xcalloc(1, sizeof(*refs));
struct ref_store *ref_store = (struct ref_store *)refs;
struct strbuf sb = STRBUF_INIT;
base_ref_store_init(ref_store, &refs_be_files);
+ refs->store_flags = flags;
refs->gitdir = xstrdup(gitdir);
get_common_dir_noenv(&sb, gitdir);
@@ -994,13 +997,17 @@ static struct ref_store *files_ref_store_create(const char *gitdir)
}
/*
- * Die if refs is for a submodule (i.e., not for the main repository).
- * caller is used in any necessary error messages.
+ * Die if refs is not the main ref store. caller is used in any
+ * necessary error messages.
*/
static void files_assert_main_repository(struct files_ref_store *refs,
const char *caller)
{
- /* This function is to be deleted in the next patch */
+ if (refs->store_flags & REF_STORE_MAIN)
+ return;
+
+ die("BUG: unallowed operation (%s), only works "
+ "on main ref store\n", caller);
}
/*
@@ -1009,9 +1016,9 @@ static void files_assert_main_repository(struct files_ref_store *refs,
* files_ref_store is for a submodule (i.e., not for the main
* repository). caller is used in any necessary error messages.
*/
-static struct files_ref_store *files_downcast(
- struct ref_store *ref_store, int submodule_allowed,
- const char *caller)
+static struct files_ref_store *files_downcast(struct ref_store *ref_store,
+ unsigned int required_flags,
+ const char *caller)
{
struct files_ref_store *refs;
@@ -1021,8 +1028,9 @@ static struct files_ref_store *files_downcast(
refs = (struct files_ref_store *)ref_store;
- if (!submodule_allowed)
- files_assert_main_repository(refs, caller);
+ if ((refs->store_flags & required_flags) != required_flags)
+ die("BUG: unallowed operation (%s), requires %x, has %x\n",
+ caller, required_flags, refs->store_flags);
return refs;
}
@@ -1404,7 +1412,7 @@ static int files_read_raw_ref(struct ref_store *ref_store,
struct strbuf *referent, unsigned int *type)
{
struct files_ref_store *refs =
- files_downcast(ref_store, 1, "read_raw_ref");
+ files_downcast(ref_store, REF_STORE_READ, "read_raw_ref");
struct strbuf sb_contents = STRBUF_INIT;
struct strbuf sb_path = STRBUF_INIT;
const char *path;
@@ -1821,10 +1829,14 @@ static enum peel_status peel_entry(struct ref_entry *entry, int repeel)
static int files_peel_ref(struct ref_store *ref_store,
const char *refname, unsigned char *sha1)
{
- struct files_ref_store *refs = files_downcast(ref_store, 0, "peel_ref");
+ struct files_ref_store *refs =
+ files_downcast(ref_store, REF_STORE_READ | REF_STORE_ODB,
+ "peel_ref");
int flag;
unsigned char base[20];
+ files_assert_main_repository(refs, "peel_ref");
+
if (current_ref_iter && current_ref_iter->refname == refname) {
struct object_id peeled;
@@ -1929,21 +1941,23 @@ static struct ref_iterator *files_ref_iterator_begin(
struct ref_store *ref_store,
const char *prefix, unsigned int flags)
{
- struct files_ref_store *refs =
- files_downcast(ref_store, 1, "ref_iterator_begin");
+ struct files_ref_store *refs;
struct ref_dir *loose_dir, *packed_dir;
struct ref_iterator *loose_iter, *packed_iter;
struct files_ref_iterator *iter;
struct ref_iterator *ref_iterator;
- if (!refs)
- return empty_ref_iterator_begin();
-
if (ref_paranoia < 0)
ref_paranoia = git_env_bool("GIT_REF_PARANOIA", 0);
if (ref_paranoia)
flags |= DO_FOR_EACH_INCLUDE_BROKEN;
+ refs = files_downcast(ref_store,
+ REF_STORE_READ | (ref_paranoia ? 0 : REF_STORE_ODB),
+ "ref_iterator_begin");
+ if (!refs)
+ return empty_ref_iterator_begin();
+
iter = xcalloc(1, sizeof(*iter));
ref_iterator = &iter->base;
base_ref_iterator_init(ref_iterator, &files_ref_iterator_vtable);
@@ -2424,7 +2438,8 @@ static void prune_refs(struct ref_to_prune *r)
static int files_pack_refs(struct ref_store *ref_store, unsigned int flags)
{
struct files_ref_store *refs =
- files_downcast(ref_store, 0, "pack_refs");
+ files_downcast(ref_store, REF_STORE_WRITE | REF_STORE_ODB,
+ "pack_refs");
struct pack_refs_cb_data cbdata;
memset(&cbdata, 0, sizeof(cbdata));
@@ -2503,7 +2518,7 @@ static int files_delete_refs(struct ref_store *ref_store,
struct string_list *refnames, unsigned int flags)
{
struct files_ref_store *refs =
- files_downcast(ref_store, 0, "delete_refs");
+ files_downcast(ref_store, REF_STORE_WRITE, "delete_refs");
struct strbuf err = STRBUF_INIT;
int i, result = 0;
@@ -2607,7 +2622,7 @@ static int files_verify_refname_available(struct ref_store *ref_store,
struct strbuf *err)
{
struct files_ref_store *refs =
- files_downcast(ref_store, 1, "verify_refname_available");
+ files_downcast(ref_store, REF_STORE_READ, "verify_refname_available");
struct ref_dir *packed_refs = get_packed_refs(refs);
struct ref_dir *loose_refs = get_loose_refs(refs);
@@ -2632,7 +2647,7 @@ static int files_rename_ref(struct ref_store *ref_store,
const char *logmsg)
{
struct files_ref_store *refs =
- files_downcast(ref_store, 0, "rename_ref");
+ files_downcast(ref_store, REF_STORE_WRITE, "rename_ref");
unsigned char sha1[20], orig_sha1[20];
int flag = 0, logmoved = 0;
struct ref_lock *lock;
@@ -2875,7 +2890,7 @@ static int files_create_reflog(struct ref_store *ref_store,
struct strbuf *err)
{
struct files_ref_store *refs =
- files_downcast(ref_store, 0, "create_reflog");
+ files_downcast(ref_store, REF_STORE_WRITE, "create_reflog");
int fd;
if (log_ref_setup(refs, refname, force_create, &fd, err))
@@ -3119,7 +3134,7 @@ static int files_create_symref(struct ref_store *ref_store,
const char *logmsg)
{
struct files_ref_store *refs =
- files_downcast(ref_store, 0, "create_symref");
+ files_downcast(ref_store, REF_STORE_WRITE, "create_symref");
struct strbuf err = STRBUF_INIT;
struct ref_lock *lock;
int ret;
@@ -3145,7 +3160,9 @@ int set_worktree_head_symref(const char *gitdir, const char *target)
* backends. This function needs to die.
*/
struct files_ref_store *refs =
- files_downcast(get_main_ref_store(), 0, "set_head_symref");
+ files_downcast(get_main_ref_store(),
+ REF_STORE_WRITE,
+ "set_head_symref");
static struct lock_file head_lock;
struct ref_lock *lock;
@@ -3184,7 +3201,7 @@ static int files_reflog_exists(struct ref_store *ref_store,
const char *refname)
{
struct files_ref_store *refs =
- files_downcast(ref_store, 0, "reflog_exists");
+ files_downcast(ref_store, REF_STORE_READ, "reflog_exists");
struct strbuf sb = STRBUF_INIT;
struct stat st;
int ret;
@@ -3199,7 +3216,7 @@ static int files_delete_reflog(struct ref_store *ref_store,
const char *refname)
{
struct files_ref_store *refs =
- files_downcast(ref_store, 0, "delete_reflog");
+ files_downcast(ref_store, REF_STORE_WRITE, "delete_reflog");
struct strbuf sb = STRBUF_INIT;
int ret;
@@ -3254,7 +3271,8 @@ static int files_for_each_reflog_ent_reverse(struct ref_store *ref_store,
void *cb_data)
{
struct files_ref_store *refs =
- files_downcast(ref_store, 0, "for_each_reflog_ent_reverse");
+ files_downcast(ref_store, REF_STORE_READ,
+ "for_each_reflog_ent_reverse");
struct strbuf sb = STRBUF_INIT;
FILE *logfp;
long pos;
@@ -3362,7 +3380,8 @@ static int files_for_each_reflog_ent(struct ref_store *ref_store,
each_reflog_ent_fn fn, void *cb_data)
{
struct files_ref_store *refs =
- files_downcast(ref_store, 0, "for_each_reflog_ent");
+ files_downcast(ref_store, REF_STORE_READ,
+ "for_each_reflog_ent");
FILE *logfp;
struct strbuf sb = STRBUF_INIT;
int ret = 0;
@@ -3450,7 +3469,8 @@ static struct ref_iterator_vtable files_reflog_iterator_vtable = {
static struct ref_iterator *files_reflog_iterator_begin(struct ref_store *ref_store)
{
struct files_ref_store *refs =
- files_downcast(ref_store, 0, "reflog_iterator_begin");
+ files_downcast(ref_store, REF_STORE_READ,
+ "reflog_iterator_begin");
struct files_reflog_iterator *iter = xcalloc(1, sizeof(*iter));
struct ref_iterator *ref_iterator = &iter->base;
struct strbuf sb = STRBUF_INIT;
@@ -3788,7 +3808,8 @@ static int files_transaction_commit(struct ref_store *ref_store,
struct strbuf *err)
{
struct files_ref_store *refs =
- files_downcast(ref_store, 0, "ref_transaction_commit");
+ files_downcast(ref_store, REF_STORE_WRITE,
+ "ref_transaction_commit");
int ret = 0, i;
struct string_list refs_to_delete = STRING_LIST_INIT_NODUP;
struct string_list_item *ref_to_delete;
@@ -3993,7 +4014,8 @@ static int files_initial_transaction_commit(struct ref_store *ref_store,
struct strbuf *err)
{
struct files_ref_store *refs =
- files_downcast(ref_store, 0, "initial_ref_transaction_commit");
+ files_downcast(ref_store, REF_STORE_WRITE,
+ "initial_ref_transaction_commit");
int ret = 0, i;
struct string_list affected_refnames = STRING_LIST_INIT_NODUP;
@@ -4115,7 +4137,7 @@ static int files_reflog_expire(struct ref_store *ref_store,
void *policy_cb_data)
{
struct files_ref_store *refs =
- files_downcast(ref_store, 0, "reflog_expire");
+ files_downcast(ref_store, REF_STORE_WRITE, "reflog_expire");
static struct lock_file reflog_lock;
struct expire_reflog_cb cb;
struct ref_lock *lock;
@@ -4221,7 +4243,7 @@ static int files_reflog_expire(struct ref_store *ref_store,
static int files_init_db(struct ref_store *ref_store, struct strbuf *err)
{
struct files_ref_store *refs =
- files_downcast(ref_store, 0, "init_db");
+ files_downcast(ref_store, REF_STORE_WRITE, "init_db");
struct strbuf sb = STRBUF_INIT;
/*
diff --git a/refs/refs-internal.h b/refs/refs-internal.h
index dfa181792..0cca280b5 100644
--- a/refs/refs-internal.h
+++ b/refs/refs-internal.h
@@ -481,12 +481,19 @@ struct ref_store;
/* refs backends */
+/* ref_store_init flags */
+#define REF_STORE_READ (1 << 0)
+#define REF_STORE_WRITE (1 << 1) /* can perform update operations */
+#define REF_STORE_ODB (1 << 2) /* has access to object database */
+#define REF_STORE_MAIN (1 << 3)
+
/*
* Initialize the ref_store for the specified gitdir. These functions
* should call base_ref_store_init() to initialize the shared part of
* the ref_store and to record the ref_store for later lookup.
*/
-typedef struct ref_store *ref_store_init_fn(const char *gitdir);
+typedef struct ref_store *ref_store_init_fn(const char *gitdir,
+ unsigned int flags);
typedef int ref_init_db_fn(struct ref_store *refs, struct strbuf *err);
--
2.11.0.157.gd943d85
^ permalink raw reply related
* [PATCH v5 13/24] refs.c: make get_main_ref_store() public and use it
From: Nguyễn Thái Ngọc Duy @ 2017-02-22 14:04 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Michael Haggerty, Johannes Schindelin,
Ramsay Jones, Stefan Beller, novalis,
Nguyễn Thái Ngọc Duy
In-Reply-To: <20170222140450.30886-1-pclouds@gmail.com>
get_ref_store() will soon be renamed to get_submodule_ref_store().
Together with future get_worktree_ref_store(), the three functions
provide an appropriate ref store for different operation modes. New APIs
will be added to operate directly on ref stores.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
refs.c | 36 ++++++++++++++++++------------------
refs.h | 3 +++
refs/files-backend.c | 2 +-
3 files changed, 22 insertions(+), 19 deletions(-)
diff --git a/refs.c b/refs.c
index 6adc38e42..562834fc0 100644
--- a/refs.c
+++ b/refs.c
@@ -1314,7 +1314,7 @@ const char *resolve_ref_recursively(struct ref_store *refs,
/* backend functions */
int refs_init_db(struct strbuf *err)
{
- struct ref_store *refs = get_ref_store(NULL);
+ struct ref_store *refs = get_main_ref_store();
return refs->be->init_db(refs, err);
}
@@ -1322,7 +1322,7 @@ int refs_init_db(struct strbuf *err)
const char *resolve_ref_unsafe(const char *refname, int resolve_flags,
unsigned char *sha1, int *flags)
{
- return resolve_ref_recursively(get_ref_store(NULL), refname,
+ return resolve_ref_recursively(get_main_ref_store(), refname,
resolve_flags, sha1, flags);
}
@@ -1428,7 +1428,7 @@ static struct ref_store *ref_store_init(const char *submodule)
return refs;
}
-static struct ref_store *get_main_ref_store(void)
+struct ref_store *get_main_ref_store(void)
{
struct ref_store *refs;
@@ -1494,14 +1494,14 @@ void base_ref_store_init(struct ref_store *refs,
/* backend functions */
int pack_refs(unsigned int flags)
{
- struct ref_store *refs = get_ref_store(NULL);
+ struct ref_store *refs = get_main_ref_store();
return refs->be->pack_refs(refs, flags);
}
int peel_ref(const char *refname, unsigned char *sha1)
{
- struct ref_store *refs = get_ref_store(NULL);
+ struct ref_store *refs = get_main_ref_store();
return refs->be->peel_ref(refs, refname, sha1);
}
@@ -1509,7 +1509,7 @@ int peel_ref(const char *refname, unsigned char *sha1)
int create_symref(const char *ref_target, const char *refs_heads_master,
const char *logmsg)
{
- struct ref_store *refs = get_ref_store(NULL);
+ struct ref_store *refs = get_main_ref_store();
return refs->be->create_symref(refs, ref_target, refs_heads_master,
logmsg);
@@ -1518,7 +1518,7 @@ int create_symref(const char *ref_target, const char *refs_heads_master,
int ref_transaction_commit(struct ref_transaction *transaction,
struct strbuf *err)
{
- struct ref_store *refs = get_ref_store(NULL);
+ struct ref_store *refs = get_main_ref_store();
return refs->be->transaction_commit(refs, transaction, err);
}
@@ -1528,14 +1528,14 @@ int verify_refname_available(const char *refname,
const struct string_list *skip,
struct strbuf *err)
{
- struct ref_store *refs = get_ref_store(NULL);
+ struct ref_store *refs = get_main_ref_store();
return refs->be->verify_refname_available(refs, refname, extra, skip, err);
}
int for_each_reflog(each_ref_fn fn, void *cb_data)
{
- struct ref_store *refs = get_ref_store(NULL);
+ struct ref_store *refs = get_main_ref_store();
struct ref_iterator *iter;
iter = refs->be->reflog_iterator_begin(refs);
@@ -1546,7 +1546,7 @@ int for_each_reflog(each_ref_fn fn, void *cb_data)
int for_each_reflog_ent_reverse(const char *refname, each_reflog_ent_fn fn,
void *cb_data)
{
- struct ref_store *refs = get_ref_store(NULL);
+ struct ref_store *refs = get_main_ref_store();
return refs->be->for_each_reflog_ent_reverse(refs, refname,
fn, cb_data);
@@ -1555,14 +1555,14 @@ int for_each_reflog_ent_reverse(const char *refname, each_reflog_ent_fn fn,
int for_each_reflog_ent(const char *refname, each_reflog_ent_fn fn,
void *cb_data)
{
- struct ref_store *refs = get_ref_store(NULL);
+ struct ref_store *refs = get_main_ref_store();
return refs->be->for_each_reflog_ent(refs, refname, fn, cb_data);
}
int reflog_exists(const char *refname)
{
- struct ref_store *refs = get_ref_store(NULL);
+ struct ref_store *refs = get_main_ref_store();
return refs->be->reflog_exists(refs, refname);
}
@@ -1570,14 +1570,14 @@ int reflog_exists(const char *refname)
int safe_create_reflog(const char *refname, int force_create,
struct strbuf *err)
{
- struct ref_store *refs = get_ref_store(NULL);
+ struct ref_store *refs = get_main_ref_store();
return refs->be->create_reflog(refs, refname, force_create, err);
}
int delete_reflog(const char *refname)
{
- struct ref_store *refs = get_ref_store(NULL);
+ struct ref_store *refs = get_main_ref_store();
return refs->be->delete_reflog(refs, refname);
}
@@ -1589,7 +1589,7 @@ int reflog_expire(const char *refname, const unsigned char *sha1,
reflog_expiry_cleanup_fn cleanup_fn,
void *policy_cb_data)
{
- struct ref_store *refs = get_ref_store(NULL);
+ struct ref_store *refs = get_main_ref_store();
return refs->be->reflog_expire(refs, refname, sha1, flags,
prepare_fn, should_prune_fn,
@@ -1599,21 +1599,21 @@ int reflog_expire(const char *refname, const unsigned char *sha1,
int initial_ref_transaction_commit(struct ref_transaction *transaction,
struct strbuf *err)
{
- struct ref_store *refs = get_ref_store(NULL);
+ struct ref_store *refs = get_main_ref_store();
return refs->be->initial_transaction_commit(refs, transaction, err);
}
int delete_refs(struct string_list *refnames, unsigned int flags)
{
- struct ref_store *refs = get_ref_store(NULL);
+ struct ref_store *refs = get_main_ref_store();
return refs->be->delete_refs(refs, refnames, flags);
}
int rename_ref(const char *oldref, const char *newref, const char *logmsg)
{
- struct ref_store *refs = get_ref_store(NULL);
+ struct ref_store *refs = get_main_ref_store();
return refs->be->rename_ref(refs, oldref, newref, logmsg);
}
diff --git a/refs.h b/refs.h
index c494b641a..29013cb7e 100644
--- a/refs.h
+++ b/refs.h
@@ -2,6 +2,7 @@
#define REFS_H
struct object_id;
+struct ref_store;
struct ref_transaction;
struct strbuf;
struct string_list;
@@ -559,4 +560,6 @@ int reflog_expire(const char *refname, const unsigned char *sha1,
int ref_storage_backend_exists(const char *name);
+struct ref_store *get_main_ref_store(void);
+
#endif /* REFS_H */
diff --git a/refs/files-backend.c b/refs/files-backend.c
index a390eaadf..d80c27837 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -3165,7 +3165,7 @@ int set_worktree_head_symref(const char *gitdir, const char *target)
* backends. This function needs to die.
*/
struct files_ref_store *refs =
- files_downcast(get_ref_store(NULL), 0, "set_head_symref");
+ files_downcast(get_main_ref_store(), 0, "set_head_symref");
static struct lock_file head_lock;
struct ref_lock *lock;
--
2.11.0.157.gd943d85
^ permalink raw reply related
* [PATCH v5 14/24] path.c: move some code out of strbuf_git_path_submodule()
From: Nguyễn Thái Ngọc Duy @ 2017-02-22 14:04 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Michael Haggerty, Johannes Schindelin,
Ramsay Jones, Stefan Beller, novalis,
Nguyễn Thái Ngọc Duy
In-Reply-To: <20170222140450.30886-1-pclouds@gmail.com>
refs is learning to avoid path rewriting that is done by
strbuf_git_path_submodule(). Factor out this code so it could be reused
by refs*
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
path.c | 34 +++++++---------------------------
submodule.c | 31 +++++++++++++++++++++++++++++++
submodule.h | 1 +
3 files changed, 39 insertions(+), 27 deletions(-)
diff --git a/path.c b/path.c
index efcedafba..3451d2916 100644
--- a/path.c
+++ b/path.c
@@ -475,35 +475,16 @@ const char *worktree_git_path(const struct worktree *wt, const char *fmt, ...)
static int do_submodule_path(struct strbuf *buf, const char *path,
const char *fmt, va_list args)
{
- const char *git_dir;
struct strbuf git_submodule_common_dir = STRBUF_INIT;
struct strbuf git_submodule_dir = STRBUF_INIT;
- const struct submodule *sub;
- int err = 0;
+ int ret;
- strbuf_addstr(buf, path);
- strbuf_complete(buf, '/');
- strbuf_addstr(buf, ".git");
-
- git_dir = read_gitfile(buf->buf);
- if (git_dir) {
- strbuf_reset(buf);
- strbuf_addstr(buf, git_dir);
- }
- if (!is_git_directory(buf->buf)) {
- gitmodules_config();
- sub = submodule_from_path(null_sha1, path);
- if (!sub) {
- err = SUBMODULE_PATH_ERR_NOT_CONFIGURED;
- goto cleanup;
- }
- strbuf_reset(buf);
- strbuf_git_path(buf, "%s/%s", "modules", sub->name);
- }
-
- strbuf_addch(buf, '/');
- strbuf_addbuf(&git_submodule_dir, buf);
+ ret = submodule_to_gitdir(&git_submodule_dir, path);
+ if (ret)
+ goto cleanup;
+ strbuf_complete(&git_submodule_dir, '/');
+ strbuf_addbuf(buf, &git_submodule_dir);
strbuf_vaddf(buf, fmt, args);
if (get_common_dir_noenv(&git_submodule_common_dir, git_submodule_dir.buf))
@@ -514,8 +495,7 @@ static int do_submodule_path(struct strbuf *buf, const char *path,
cleanup:
strbuf_release(&git_submodule_dir);
strbuf_release(&git_submodule_common_dir);
-
- return err;
+ return ret;
}
char *git_pathdup_submodule(const char *path, const char *fmt, ...)
diff --git a/submodule.c b/submodule.c
index 3b98766a6..36b8d1d11 100644
--- a/submodule.c
+++ b/submodule.c
@@ -1514,3 +1514,34 @@ void absorb_git_dir_into_superproject(const char *prefix,
strbuf_release(&sb);
}
}
+
+int submodule_to_gitdir(struct strbuf *buf, const char *submodule)
+{
+ const struct submodule *sub;
+ const char *git_dir;
+ int ret = 0;
+
+ strbuf_reset(buf);
+ strbuf_addstr(buf, submodule);
+ strbuf_complete(buf, '/');
+ strbuf_addstr(buf, ".git");
+
+ git_dir = read_gitfile(buf->buf);
+ if (git_dir) {
+ strbuf_reset(buf);
+ strbuf_addstr(buf, git_dir);
+ }
+ if (!is_git_directory(buf->buf)) {
+ gitmodules_config();
+ sub = submodule_from_path(null_sha1, submodule);
+ if (!sub) {
+ ret = -1;
+ goto cleanup;
+ }
+ strbuf_reset(buf);
+ strbuf_git_path(buf, "%s/%s", "modules", sub->name);
+ }
+
+cleanup:
+ return ret;
+}
diff --git a/submodule.h b/submodule.h
index 05ab674f0..fc3d0303e 100644
--- a/submodule.h
+++ b/submodule.h
@@ -81,6 +81,7 @@ extern int push_unpushed_submodules(struct sha1_array *commits,
int dry_run);
extern void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir);
extern int parallel_submodules(void);
+int submodule_to_gitdir(struct strbuf *buf, const char *submodule);
/*
* Prepare the "env_array" parameter of a "struct child_process" for executing
--
2.11.0.157.gd943d85
^ permalink raw reply related
* [PATCH v5 11/24] refs.c: flatten get_ref_store() a bit
From: Nguyễn Thái Ngọc Duy @ 2017-02-22 14:04 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Michael Haggerty, Johannes Schindelin,
Ramsay Jones, Stefan Beller, novalis,
Nguyễn Thái Ngọc Duy
In-Reply-To: <20170222140450.30886-1-pclouds@gmail.com>
This helps the future changes in this code. And because get_ref_store()
is destined to become get_submodule_ref_store(), the "get main store"
code path will be removed eventually. After this the patch to delete
that code will be cleaner.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
refs.c | 19 +++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)
diff --git a/refs.c b/refs.c
index 8b36d97c0..c284cb4f4 100644
--- a/refs.c
+++ b/refs.c
@@ -1465,22 +1465,21 @@ static struct ref_store *get_main_ref_store(void)
struct ref_store *get_ref_store(const char *submodule)
{
+ struct strbuf submodule_sb = STRBUF_INIT;
struct ref_store *refs;
if (!submodule || !*submodule) {
return get_main_ref_store();
- } else {
- refs = lookup_submodule_ref_store(submodule);
+ }
- if (!refs) {
- struct strbuf submodule_sb = STRBUF_INIT;
+ refs = lookup_submodule_ref_store(submodule);
+ if (refs)
+ return refs;
- strbuf_addstr(&submodule_sb, submodule);
- if (is_nonbare_repository_dir(&submodule_sb))
- refs = ref_store_init(submodule);
- strbuf_release(&submodule_sb);
- }
- }
+ strbuf_addstr(&submodule_sb, submodule);
+ if (is_nonbare_repository_dir(&submodule_sb))
+ refs = ref_store_init(submodule);
+ strbuf_release(&submodule_sb);
return refs;
}
--
2.11.0.157.gd943d85
^ permalink raw reply related
* [PATCH v5 12/24] refs.c: kill register_ref_store(), add register_submodule_ref_store()
From: Nguyễn Thái Ngọc Duy @ 2017-02-22 14:04 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Michael Haggerty, Johannes Schindelin,
Ramsay Jones, Stefan Beller, novalis,
Nguyễn Thái Ngọc Duy
In-Reply-To: <20170222140450.30886-1-pclouds@gmail.com>
This is the last function in this code (besides public API) that takes
submodule argument and handles both main/submodule cases. Break it down,
move main store registration in get_main_ref_store() and keep the rest
in register_submodule_ref_store().
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
refs.c | 50 ++++++++++++++++++++++++++------------------------
1 file changed, 26 insertions(+), 24 deletions(-)
diff --git a/refs.c b/refs.c
index c284cb4f4..6adc38e42 100644
--- a/refs.c
+++ b/refs.c
@@ -1412,29 +1412,6 @@ static struct ref_store *lookup_submodule_ref_store(const char *submodule)
}
/*
- * Register the specified ref_store to be the one that should be used
- * for submodule (or the main repository if submodule is NULL). It is
- * a fatal error to call this function twice for the same submodule.
- */
-static void register_ref_store(struct ref_store *refs, const char *submodule)
-{
- if (!submodule) {
- if (main_ref_store)
- die("BUG: main_ref_store initialized twice");
-
- main_ref_store = refs;
- } else {
- if (!submodule_ref_stores.tablesize)
- hashmap_init(&submodule_ref_stores, submodule_hash_cmp, 0);
-
- if (hashmap_put(&submodule_ref_stores,
- alloc_submodule_hash_entry(submodule, refs)))
- die("BUG: ref_store for submodule '%s' initialized twice",
- submodule);
- }
-}
-
-/*
* Create, record, and return a ref_store instance for the specified
* submodule (or the main repository if submodule is NULL).
*/
@@ -1448,7 +1425,6 @@ static struct ref_store *ref_store_init(const char *submodule)
die("BUG: reference backend %s is unknown", be_name);
refs = be->init(submodule);
- register_ref_store(refs, submodule);
return refs;
}
@@ -1460,9 +1436,32 @@ static struct ref_store *get_main_ref_store(void)
return main_ref_store;
refs = ref_store_init(NULL);
+ if (refs) {
+ if (main_ref_store)
+ die("BUG: main_ref_store initialized twice");
+
+ main_ref_store = refs;
+ }
return refs;
}
+/*
+ * Register the specified ref_store to be the one that should be used
+ * for submodule. It is a fatal error to call this function twice for
+ * the same submodule.
+ */
+static void register_submodule_ref_store(struct ref_store *refs,
+ const char *submodule)
+{
+ if (!submodule_ref_stores.tablesize)
+ hashmap_init(&submodule_ref_stores, submodule_hash_cmp, 0);
+
+ if (hashmap_put(&submodule_ref_stores,
+ alloc_submodule_hash_entry(submodule, refs)))
+ die("BUG: ref_store for submodule '%s' initialized twice",
+ submodule);
+}
+
struct ref_store *get_ref_store(const char *submodule)
{
struct strbuf submodule_sb = STRBUF_INIT;
@@ -1480,6 +1479,9 @@ struct ref_store *get_ref_store(const char *submodule)
if (is_nonbare_repository_dir(&submodule_sb))
refs = ref_store_init(submodule);
strbuf_release(&submodule_sb);
+
+ if (refs)
+ register_submodule_ref_store(refs, submodule);
return refs;
}
--
2.11.0.157.gd943d85
^ permalink raw reply related
* [PATCH v5 10/24] refs: rename lookup_ref_store() to lookup_submodule_ref_store()
From: Nguyễn Thái Ngọc Duy @ 2017-02-22 14:04 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Michael Haggerty, Johannes Schindelin,
Ramsay Jones, Stefan Beller, novalis,
Nguyễn Thái Ngọc Duy
In-Reply-To: <20170222140450.30886-1-pclouds@gmail.com>
With get_main_ref_store() being used inside get_ref_store(),
lookup_ref_store() is only used for submodule code path. Rename to
reflect that and delete dead code.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
refs.c | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)
diff --git a/refs.c b/refs.c
index dab1a21ac..8b36d97c0 100644
--- a/refs.c
+++ b/refs.c
@@ -1395,17 +1395,13 @@ static struct ref_store *main_ref_store;
static struct hashmap submodule_ref_stores;
/*
- * Return the ref_store instance for the specified submodule (or the
- * main repository if submodule is NULL). If that ref_store hasn't
- * been initialized yet, return NULL.
+ * Return the ref_store instance for the specified submodule. If that
+ * ref_store hasn't been initialized yet, return NULL.
*/
-static struct ref_store *lookup_ref_store(const char *submodule)
+static struct ref_store *lookup_submodule_ref_store(const char *submodule)
{
struct submodule_hash_entry *entry;
- if (!submodule)
- return main_ref_store;
-
if (!submodule_ref_stores.tablesize)
/* It's initialized on demand in register_ref_store(). */
return NULL;
@@ -1474,7 +1470,7 @@ struct ref_store *get_ref_store(const char *submodule)
if (!submodule || !*submodule) {
return get_main_ref_store();
} else {
- refs = lookup_ref_store(submodule);
+ refs = lookup_submodule_ref_store(submodule);
if (!refs) {
struct strbuf submodule_sb = STRBUF_INIT;
@@ -1485,7 +1481,6 @@ struct ref_store *get_ref_store(const char *submodule)
strbuf_release(&submodule_sb);
}
}
-
return refs;
}
--
2.11.0.157.gd943d85
^ permalink raw reply related
* [PATCH v5 09/24] refs.c: introduce get_main_ref_store()
From: Nguyễn Thái Ngọc Duy @ 2017-02-22 14:04 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Michael Haggerty, Johannes Schindelin,
Ramsay Jones, Stefan Beller, novalis,
Nguyễn Thái Ngọc Duy
In-Reply-To: <20170222140450.30886-1-pclouds@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
refs.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/refs.c b/refs.c
index 81b64b4ed..dab1a21ac 100644
--- a/refs.c
+++ b/refs.c
@@ -1456,15 +1456,23 @@ static struct ref_store *ref_store_init(const char *submodule)
return refs;
}
+static struct ref_store *get_main_ref_store(void)
+{
+ struct ref_store *refs;
+
+ if (main_ref_store)
+ return main_ref_store;
+
+ refs = ref_store_init(NULL);
+ return refs;
+}
+
struct ref_store *get_ref_store(const char *submodule)
{
struct ref_store *refs;
if (!submodule || !*submodule) {
- refs = lookup_ref_store(NULL);
-
- if (!refs)
- refs = ref_store_init(NULL);
+ return get_main_ref_store();
} else {
refs = lookup_ref_store(submodule);
--
2.11.0.157.gd943d85
^ permalink raw reply related
* [PATCH v5 08/24] files-backend: remove the use of git_path()
From: Nguyễn Thái Ngọc Duy @ 2017-02-22 14:04 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Michael Haggerty, Johannes Schindelin,
Ramsay Jones, Stefan Beller, novalis,
Nguyễn Thái Ngọc Duy
In-Reply-To: <20170222140450.30886-1-pclouds@gmail.com>
Given $GIT_DIR and $GIT_COMMON_DIR, files-backend is now in charge of
deciding what goes where (*). The end goal is to pass $GIT_DIR only. A
refs "view" of a linked worktree is a logical ref store that combines
two files backends together.
(*) Not entirely true since strbuf_git_path_submodule() still does path
translation underneath. But that's for another patch.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
refs/files-backend.c | 43 ++++++++++++++++++++++++++++++++++++++-----
1 file changed, 38 insertions(+), 5 deletions(-)
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 72f4e1746..a390eaadf 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -923,7 +923,8 @@ struct files_ref_store {
* store:
*/
const char *submodule;
-
+ char *gitdir;
+ char *gitcommondir;
char *packed_refs_path;
struct ref_entry *loose;
@@ -985,6 +986,8 @@ static struct ref_store *files_ref_store_create(const char *submodule)
{
struct files_ref_store *refs = xcalloc(1, sizeof(*refs));
struct ref_store *ref_store = (struct ref_store *)refs;
+ struct strbuf sb = STRBUF_INIT;
+ const char *gitdir = get_git_dir();
base_ref_store_init(ref_store, &refs_be_files);
@@ -995,7 +998,11 @@ static struct ref_store *files_ref_store_create(const char *submodule)
return ref_store;
}
- refs->packed_refs_path = git_pathdup("packed-refs");
+ refs->gitdir = xstrdup(gitdir);
+ get_common_dir_noenv(&sb, gitdir);
+ refs->gitcommondir = strbuf_detach(&sb, NULL);
+ strbuf_addf(&sb, "%s/packed-refs", refs->gitcommondir);
+ refs->packed_refs_path = strbuf_detach(&sb, NULL);
return ref_store;
}
@@ -1173,11 +1180,26 @@ static void files_reflog_path(struct files_ref_store *refs,
const char *refname)
{
if (!refname) {
- strbuf_git_path(sb, "logs");
+ /*
+ * FIXME: of course this is wrong in multi worktree
+ * setting. To be fixed real soon.
+ */
+ strbuf_addf(sb, "%s/logs", refs->gitcommondir);
return;
}
- strbuf_git_path(sb, "logs/%s", refname);
+ switch (ref_type(refname)) {
+ case REF_TYPE_PER_WORKTREE:
+ case REF_TYPE_PSEUDOREF:
+ strbuf_addf(sb, "%s/logs/%s", refs->gitdir, refname);
+ break;
+ case REF_TYPE_NORMAL:
+ strbuf_addf(sb, "%s/logs/%s", refs->gitcommondir, refname);
+ break;
+ default:
+ die("BUG: unknown ref type %d of ref %s",
+ ref_type(refname), refname);
+ }
}
static void files_refname_path(struct files_ref_store *refs,
@@ -1189,7 +1211,18 @@ static void files_refname_path(struct files_ref_store *refs,
return;
}
- strbuf_git_path(sb, "%s", refname);
+ switch (ref_type(refname)) {
+ case REF_TYPE_PER_WORKTREE:
+ case REF_TYPE_PSEUDOREF:
+ strbuf_addf(sb, "%s/%s", refs->gitdir, refname);
+ break;
+ case REF_TYPE_NORMAL:
+ strbuf_addf(sb, "%s/%s", refs->gitcommondir, refname);
+ break;
+ default:
+ die("BUG: unknown ref type %d of ref %s",
+ ref_type(refname), refname);
+ }
}
/*
--
2.11.0.157.gd943d85
^ permalink raw reply related
* [PATCH v5 06/24] files-backend: add and use files_reflog_path()
From: Nguyễn Thái Ngọc Duy @ 2017-02-22 14:04 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Michael Haggerty, Johannes Schindelin,
Ramsay Jones, Stefan Beller, novalis,
Nguyễn Thái Ngọc Duy
In-Reply-To: <20170222140450.30886-1-pclouds@gmail.com>
Keep repo-related path handling in one place. This will make it easier
to add submodule/multiworktree support later.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
refs/files-backend.c | 148 +++++++++++++++++++++++++++++++--------------------
1 file changed, 89 insertions(+), 59 deletions(-)
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 69946b0de..7b4ea4c56 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -165,7 +165,8 @@ static struct ref_entry *create_dir_entry(struct files_ref_store *ref_store,
const char *dirname, size_t len,
int incomplete);
static void add_entry_to_dir(struct ref_dir *dir, struct ref_entry *entry);
-static int files_log_ref_write(const char *refname, const unsigned char *old_sha1,
+static int files_log_ref_write(struct files_ref_store *refs,
+ const char *refname, const unsigned char *old_sha1,
const unsigned char *new_sha1, const char *msg,
int flags, struct strbuf *err);
@@ -1167,6 +1168,18 @@ static const char *files_packed_refs_path(struct files_ref_store *refs)
return refs->packed_refs_path;
}
+static void files_reflog_path(struct files_ref_store *refs,
+ struct strbuf *sb,
+ const char *refname)
+{
+ if (!refname) {
+ strbuf_git_path(sb, "logs");
+ return;
+ }
+
+ strbuf_git_path(sb, "logs/%s", refname);
+}
+
/*
* Get the packed_ref_cache for the specified files_ref_store,
* creating it if necessary.
@@ -2316,7 +2329,9 @@ enum {
* subdirs. flags is a combination of REMOVE_EMPTY_PARENTS_REF and/or
* REMOVE_EMPTY_PARENTS_REFLOG.
*/
-static void try_remove_empty_parents(const char *refname, unsigned int flags)
+static void try_remove_empty_parents(struct files_ref_store *refs,
+ const char *refname,
+ unsigned int flags)
{
struct strbuf buf = STRBUF_INIT;
struct strbuf sb = STRBUF_INIT;
@@ -2348,7 +2363,7 @@ static void try_remove_empty_parents(const char *refname, unsigned int flags)
flags &= ~REMOVE_EMPTY_PARENTS_REF;
strbuf_reset(&sb);
- strbuf_git_path(&sb, "logs/%s", buf.buf);
+ files_reflog_path(refs, &sb, buf.buf);
if ((flags & REMOVE_EMPTY_PARENTS_REFLOG) && rmdir(sb.buf))
flags &= ~REMOVE_EMPTY_PARENTS_REFLOG;
}
@@ -2541,15 +2556,15 @@ static int rename_tmp_log_callback(const char *path, void *cb_data)
}
}
-static int rename_tmp_log(const char *newrefname)
+static int rename_tmp_log(struct files_ref_store *refs, const char *newrefname)
{
struct strbuf path = STRBUF_INIT;
struct strbuf tmp = STRBUF_INIT;
struct rename_cb cb;
int ret;
- strbuf_git_path(&path, "logs/%s", newrefname);
- strbuf_git_path(&tmp, "logs/%s", TMP_RENAMED_LOG);
+ files_reflog_path(refs, &path, newrefname);
+ files_reflog_path(refs, &tmp, TMP_RENAMED_LOG);
cb.tmp_renamed_log = tmp.buf;
ret = raceproof_create_file(path.buf, rename_tmp_log_callback, &cb);
if (ret) {
@@ -2609,7 +2624,7 @@ static int files_rename_ref(struct ref_store *ref_store,
int log, ret;
struct strbuf err = STRBUF_INIT;
- strbuf_git_path(&sb_oldref, "logs/%s", oldrefname);
+ files_reflog_path(refs, &sb_oldref, oldrefname);
log = !lstat(sb_oldref.buf, &loginfo);
strbuf_release(&sb_oldref);
if (log && S_ISLNK(loginfo.st_mode))
@@ -2625,8 +2640,8 @@ static int files_rename_ref(struct ref_store *ref_store,
if (!rename_ref_available(oldrefname, newrefname))
return 1;
- strbuf_git_path(&sb_oldref, "logs/%s", oldrefname);
- strbuf_git_path(&tmp_renamed_log, "logs/%s", TMP_RENAMED_LOG);
+ files_reflog_path(refs, &sb_oldref, oldrefname);
+ files_reflog_path(refs, &tmp_renamed_log, TMP_RENAMED_LOG);
ret = log && rename(sb_oldref.buf, tmp_renamed_log.buf);
strbuf_release(&sb_oldref);
strbuf_release(&tmp_renamed_log);
@@ -2667,7 +2682,7 @@ static int files_rename_ref(struct ref_store *ref_store,
}
}
- if (log && rename_tmp_log(newrefname))
+ if (log && rename_tmp_log(refs, newrefname))
goto rollback;
logmoved = log;
@@ -2709,12 +2724,12 @@ static int files_rename_ref(struct ref_store *ref_store,
log_all_ref_updates = flag;
rollbacklog:
- strbuf_git_path(&sb_newref, "logs/%s", newrefname);
- strbuf_git_path(&sb_oldref, "logs/%s", oldrefname);
+ files_reflog_path(refs, &sb_newref, newrefname);
+ files_reflog_path(refs, &sb_oldref, oldrefname);
if (logmoved && rename(sb_newref.buf, sb_oldref.buf))
error("unable to restore logfile %s from %s: %s",
oldrefname, newrefname, strerror(errno));
- strbuf_git_path(&tmp_renamed_log, "logs/%s", TMP_RENAMED_LOG);
+ files_reflog_path(refs, &tmp_renamed_log, TMP_RENAMED_LOG);
if (!logmoved && log &&
rename(tmp_renamed_log.buf, sb_oldref.buf))
error("unable to restore logfile %s from logs/"TMP_RENAMED_LOG": %s",
@@ -2782,10 +2797,15 @@ static int open_or_create_logfile(const char *path, void *cb)
* set *logfd to -1. On failure, fill in *err, set *logfd to -1, and
* return -1.
*/
-static int log_ref_setup(const char *refname, int force_create,
+static int log_ref_setup(struct files_ref_store *refs,
+ const char *refname, int force_create,
int *logfd, struct strbuf *err)
{
- char *logfile = git_pathdup("logs/%s", refname);
+ struct strbuf logfile_sb = STRBUF_INIT;
+ char *logfile;
+
+ files_reflog_path(refs, &logfile_sb, refname);
+ logfile = strbuf_detach(&logfile_sb, NULL);
if (force_create || should_autocreate_reflog(refname)) {
if (raceproof_create_file(logfile, open_or_create_logfile, logfd)) {
@@ -2835,12 +2855,11 @@ static int files_create_reflog(struct ref_store *ref_store,
const char *refname, int force_create,
struct strbuf *err)
{
+ struct files_ref_store *refs =
+ files_downcast(ref_store, 0, "create_reflog");
int fd;
- /* Check validity (but we don't need the result): */
- files_downcast(ref_store, 0, "create_reflog");
-
- if (log_ref_setup(refname, force_create, &fd, err))
+ if (log_ref_setup(refs, refname, force_create, &fd, err))
return -1;
if (fd >= 0)
@@ -2875,7 +2894,8 @@ static int log_ref_write_fd(int fd, const unsigned char *old_sha1,
return 0;
}
-int files_log_ref_write(const char *refname, const unsigned char *old_sha1,
+int files_log_ref_write(struct files_ref_store *refs,
+ const char *refname, const unsigned char *old_sha1,
const unsigned char *new_sha1, const char *msg,
int flags, struct strbuf *err)
{
@@ -2884,7 +2904,8 @@ int files_log_ref_write(const char *refname, const unsigned char *old_sha1,
if (log_all_ref_updates == LOG_REFS_UNSET)
log_all_ref_updates = is_bare_repository() ? LOG_REFS_NONE : LOG_REFS_NORMAL;
- result = log_ref_setup(refname, flags & REF_FORCE_CREATE_REFLOG,
+ result = log_ref_setup(refs, refname,
+ flags & REF_FORCE_CREATE_REFLOG,
&logfd, err);
if (result)
@@ -2898,7 +2919,7 @@ int files_log_ref_write(const char *refname, const unsigned char *old_sha1,
struct strbuf sb = STRBUF_INIT;
int save_errno = errno;
- strbuf_git_path(&sb, "logs/%s", refname);
+ files_reflog_path(refs, &sb, refname);
strbuf_addf(err, "unable to append to '%s': %s",
sb.buf, strerror(save_errno));
strbuf_release(&sb);
@@ -2909,7 +2930,7 @@ int files_log_ref_write(const char *refname, const unsigned char *old_sha1,
struct strbuf sb = STRBUF_INIT;
int save_errno = errno;
- strbuf_git_path(&sb, "logs/%s", refname);
+ files_reflog_path(refs, &sb, refname);
strbuf_addf(err, "unable to append to '%s': %s",
sb.buf, strerror(save_errno));
strbuf_release(&sb);
@@ -2970,7 +2991,8 @@ static int commit_ref_update(struct files_ref_store *refs,
files_assert_main_repository(refs, "commit_ref_update");
clear_loose_ref_cache(refs);
- if (files_log_ref_write(lock->ref_name, lock->old_oid.hash, sha1,
+ if (files_log_ref_write(refs, lock->ref_name,
+ lock->old_oid.hash, sha1,
logmsg, 0, err)) {
char *old_msg = strbuf_detach(err, NULL);
strbuf_addf(err, "cannot update the ref '%s': %s",
@@ -3002,8 +3024,9 @@ static int commit_ref_update(struct files_ref_store *refs,
if (head_ref && (head_flag & REF_ISSYMREF) &&
!strcmp(head_ref, lock->ref_name)) {
struct strbuf log_err = STRBUF_INIT;
- if (files_log_ref_write("HEAD", lock->old_oid.hash, sha1,
- logmsg, 0, &log_err)) {
+ if (files_log_ref_write(refs, "HEAD",
+ lock->old_oid.hash, sha1,
+ logmsg, 0, &log_err)) {
error("%s", log_err.buf);
strbuf_release(&log_err);
}
@@ -3035,24 +3058,26 @@ static int create_ref_symlink(struct ref_lock *lock, const char *target)
return ret;
}
-static void update_symref_reflog(struct ref_lock *lock, const char *refname,
+static void update_symref_reflog(struct files_ref_store *refs,
+ struct ref_lock *lock, const char *refname,
const char *target, const char *logmsg)
{
struct strbuf err = STRBUF_INIT;
unsigned char new_sha1[20];
if (logmsg && !read_ref(target, new_sha1) &&
- files_log_ref_write(refname, lock->old_oid.hash, new_sha1,
- logmsg, 0, &err)) {
+ files_log_ref_write(refs, refname, lock->old_oid.hash,
+ new_sha1, logmsg, 0, &err)) {
error("%s", err.buf);
strbuf_release(&err);
}
}
-static int create_symref_locked(struct ref_lock *lock, const char *refname,
+static int create_symref_locked(struct files_ref_store *refs,
+ struct ref_lock *lock, const char *refname,
const char *target, const char *logmsg)
{
if (prefer_symlink_refs && !create_ref_symlink(lock, target)) {
- update_symref_reflog(lock, refname, target, logmsg);
+ update_symref_reflog(refs, lock, refname, target, logmsg);
return 0;
}
@@ -3060,7 +3085,7 @@ static int create_symref_locked(struct ref_lock *lock, const char *refname,
return error("unable to fdopen %s: %s",
lock->lk->tempfile.filename.buf, strerror(errno));
- update_symref_reflog(lock, refname, target, logmsg);
+ update_symref_reflog(refs, lock, refname, target, logmsg);
/* no error check; commit_ref will check ferror */
fprintf(lock->lk->tempfile.fp, "ref: %s\n", target);
@@ -3089,13 +3114,20 @@ static int files_create_symref(struct ref_store *ref_store,
return -1;
}
- ret = create_symref_locked(lock, refname, target, logmsg);
+ ret = create_symref_locked(refs, lock, refname, target, logmsg);
unlock_ref(lock);
return ret;
}
int set_worktree_head_symref(const char *gitdir, const char *target)
{
+ /*
+ * FIXME: this obviously will not work well for future refs
+ * backends. This function needs to die.
+ */
+ struct files_ref_store *refs =
+ files_downcast(get_ref_store(NULL), 0, "set_head_symref");
+
static struct lock_file head_lock;
struct ref_lock *lock;
struct strbuf head_path = STRBUF_INIT;
@@ -3122,7 +3154,7 @@ int set_worktree_head_symref(const char *gitdir, const char *target)
lock->lk = &head_lock;
lock->ref_name = xstrdup(head_rel);
- ret = create_symref_locked(lock, head_rel, target, NULL);
+ ret = create_symref_locked(refs, lock, head_rel, target, NULL);
unlock_ref(lock); /* will free lock */
strbuf_release(&head_path);
@@ -3132,14 +3164,13 @@ int set_worktree_head_symref(const char *gitdir, const char *target)
static int files_reflog_exists(struct ref_store *ref_store,
const char *refname)
{
+ struct files_ref_store *refs =
+ files_downcast(ref_store, 0, "reflog_exists");
struct strbuf sb = STRBUF_INIT;
struct stat st;
int ret;
- /* Check validity (but we don't need the result): */
- files_downcast(ref_store, 0, "reflog_exists");
-
- strbuf_git_path(&sb, "logs/%s", refname);
+ files_reflog_path(refs, &sb, refname);
ret = !lstat(sb.buf, &st) && S_ISREG(st.st_mode);
strbuf_release(&sb);
return ret;
@@ -3148,13 +3179,12 @@ static int files_reflog_exists(struct ref_store *ref_store,
static int files_delete_reflog(struct ref_store *ref_store,
const char *refname)
{
+ struct files_ref_store *refs =
+ files_downcast(ref_store, 0, "delete_reflog");
struct strbuf sb = STRBUF_INIT;
int ret;
- /* Check validity (but we don't need the result): */
- files_downcast(ref_store, 0, "delete_reflog");
-
- strbuf_git_path(&sb, "logs/%s", refname);
+ files_reflog_path(refs, &sb, refname);
ret = remove_path(sb.buf);
strbuf_release(&sb);
return ret;
@@ -3204,15 +3234,14 @@ static int files_for_each_reflog_ent_reverse(struct ref_store *ref_store,
each_reflog_ent_fn fn,
void *cb_data)
{
+ struct files_ref_store *refs =
+ files_downcast(ref_store, 0, "for_each_reflog_ent_reverse");
struct strbuf sb = STRBUF_INIT;
FILE *logfp;
long pos;
int ret = 0, at_tail = 1;
- /* Check validity (but we don't need the result): */
- files_downcast(ref_store, 0, "for_each_reflog_ent_reverse");
-
- strbuf_git_path(&sb, "logs/%s", refname);
+ files_reflog_path(refs, &sb, refname);
logfp = fopen(sb.buf, "r");
strbuf_release(&sb);
if (!logfp)
@@ -3313,14 +3342,13 @@ static int files_for_each_reflog_ent(struct ref_store *ref_store,
const char *refname,
each_reflog_ent_fn fn, void *cb_data)
{
+ struct files_ref_store *refs =
+ files_downcast(ref_store, 0, "for_each_reflog_ent");
FILE *logfp;
struct strbuf sb = STRBUF_INIT;
int ret = 0;
- /* Check validity (but we don't need the result): */
- files_downcast(ref_store, 0, "for_each_reflog_ent");
-
- strbuf_git_path(&sb, "logs/%s", refname);
+ files_reflog_path(refs, &sb, refname);
logfp = fopen(sb.buf, "r");
strbuf_release(&sb);
if (!logfp)
@@ -3402,15 +3430,14 @@ static struct ref_iterator_vtable files_reflog_iterator_vtable = {
static struct ref_iterator *files_reflog_iterator_begin(struct ref_store *ref_store)
{
+ struct files_ref_store *refs =
+ files_downcast(ref_store, 0, "reflog_iterator_begin");
struct files_reflog_iterator *iter = xcalloc(1, sizeof(*iter));
struct ref_iterator *ref_iterator = &iter->base;
struct strbuf sb = STRBUF_INIT;
- /* Check validity (but we don't need the result): */
- files_downcast(ref_store, 0, "reflog_iterator_begin");
-
base_ref_iterator_init(ref_iterator, &files_reflog_iterator_vtable);
- strbuf_git_path(&sb, "logs");
+ files_reflog_path(refs, &sb, NULL);
iter->dir_iterator = dir_iterator_begin(sb.buf);
strbuf_release(&sb);
return ref_iterator;
@@ -3835,7 +3862,8 @@ static int files_transaction_commit(struct ref_store *ref_store,
if (update->flags & REF_NEEDS_COMMIT ||
update->flags & REF_LOG_ONLY) {
- if (files_log_ref_write(lock->ref_name,
+ if (files_log_ref_write(refs,
+ lock->ref_name,
lock->old_oid.hash,
update->new_sha1,
update->msg, update->flags,
@@ -3895,9 +3923,9 @@ static int files_transaction_commit(struct ref_store *ref_store,
/* Delete the reflogs of any references that were deleted: */
for_each_string_list_item(ref_to_delete, &refs_to_delete) {
strbuf_reset(&sb);
- strbuf_git_path(&sb, "logs/%s", ref_to_delete->string);
+ files_reflog_path(refs, &sb, ref_to_delete->string);
if (!unlink_or_warn(sb.buf))
- try_remove_empty_parents(ref_to_delete->string,
+ try_remove_empty_parents(refs, ref_to_delete->string,
REMOVE_EMPTY_PARENTS_REFLOG);
}
@@ -3921,7 +3949,7 @@ static int files_transaction_commit(struct ref_store *ref_store,
* can only work because we have already
* removed the lockfile.)
*/
- try_remove_empty_parents(update->refname,
+ try_remove_empty_parents(refs, update->refname,
REMOVE_EMPTY_PARENTS_REF);
}
}
@@ -4072,6 +4100,7 @@ static int files_reflog_expire(struct ref_store *ref_store,
static struct lock_file reflog_lock;
struct expire_reflog_cb cb;
struct ref_lock *lock;
+ struct strbuf log_file_sb = STRBUF_INIT;
char *log_file;
int status = 0;
int type;
@@ -4100,7 +4129,8 @@ static int files_reflog_expire(struct ref_store *ref_store,
return 0;
}
- log_file = git_pathdup("logs/%s", refname);
+ files_reflog_path(refs, &log_file_sb, refname);
+ log_file = strbuf_detach(&log_file_sb, NULL);
if (!(flags & EXPIRE_REFLOGS_DRY_RUN)) {
/*
* Even though holding $GIT_DIR/logs/$reflog.lock has
--
2.11.0.157.gd943d85
^ permalink raw reply related
* [PATCH v5 07/24] files-backend: add and use files_refname_path()
From: Nguyễn Thái Ngọc Duy @ 2017-02-22 14:04 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Michael Haggerty, Johannes Schindelin,
Ramsay Jones, Stefan Beller, novalis,
Nguyễn Thái Ngọc Duy
In-Reply-To: <20170222140450.30886-1-pclouds@gmail.com>
Keep repo-related path handling in one place. This will make it easier
to add submodule/multiworktree support later.
This automatically adds the "if submodule then use the submodule version
of git_path" to other call sites too. But it does not mean those
operations are sumodule-ready. Not yet.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
refs/files-backend.c | 45 +++++++++++++++++++++++++--------------------
1 file changed, 25 insertions(+), 20 deletions(-)
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 7b4ea4c56..72f4e1746 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -1180,6 +1180,18 @@ static void files_reflog_path(struct files_ref_store *refs,
strbuf_git_path(sb, "logs/%s", refname);
}
+static void files_refname_path(struct files_ref_store *refs,
+ struct strbuf *sb,
+ const char *refname)
+{
+ if (refs->submodule) {
+ strbuf_git_path_submodule(sb, refs->submodule, "%s", refname);
+ return;
+ }
+
+ strbuf_git_path(sb, "%s", refname);
+}
+
/*
* Get the packed_ref_cache for the specified files_ref_store,
* creating it if necessary.
@@ -1251,10 +1263,7 @@ static void read_loose_refs(const char *dirname, struct ref_dir *dir)
size_t path_baselen;
int err = 0;
- if (refs->submodule)
- err = strbuf_git_path_submodule(&path, refs->submodule, "%s", dirname);
- else
- strbuf_git_path(&path, "%s", dirname);
+ files_refname_path(refs, &path, dirname);
path_baselen = path.len;
if (err) {
@@ -1396,10 +1405,7 @@ static int files_read_raw_ref(struct ref_store *ref_store,
*type = 0;
strbuf_reset(&sb_path);
- if (refs->submodule)
- strbuf_git_path_submodule(&sb_path, refs->submodule, "%s", refname);
- else
- strbuf_git_path(&sb_path, "%s", refname);
+ files_refname_path(refs, &sb_path, refname);
path = sb_path.buf;
@@ -1587,7 +1593,7 @@ static int lock_raw_ref(struct files_ref_store *refs,
*lock_p = lock = xcalloc(1, sizeof(*lock));
lock->ref_name = xstrdup(refname);
- strbuf_git_path(&ref_file, "%s", refname);
+ files_refname_path(refs, &ref_file, refname);
retry:
switch (safe_create_leading_directories(ref_file.buf)) {
@@ -2059,7 +2065,7 @@ static struct ref_lock *lock_ref_sha1_basic(struct files_ref_store *refs,
if (flags & REF_DELETING)
resolve_flags |= RESOLVE_REF_ALLOW_BAD_NAME;
- strbuf_git_path(&ref_file, "%s", refname);
+ files_refname_path(refs, &ref_file, refname);
resolved = !!resolve_ref_unsafe(refname, resolve_flags,
lock->old_oid.hash, type);
if (!resolved && errno == EISDIR) {
@@ -2358,7 +2364,7 @@ static void try_remove_empty_parents(struct files_ref_store *refs,
strbuf_setlen(&buf, q - buf.buf);
strbuf_reset(&sb);
- strbuf_git_path(&sb, "%s", buf.buf);
+ files_refname_path(refs, &sb, buf.buf);
if ((flags & REMOVE_EMPTY_PARENTS_REF) && rmdir(sb.buf))
flags &= ~REMOVE_EMPTY_PARENTS_REF;
@@ -2668,7 +2674,7 @@ static int files_rename_ref(struct ref_store *ref_store,
struct strbuf path = STRBUF_INIT;
int result;
- strbuf_git_path(&path, "%s", newrefname);
+ files_refname_path(refs, &path, newrefname);
result = remove_empty_directories(&path);
strbuf_release(&path);
@@ -3901,7 +3907,7 @@ static int files_transaction_commit(struct ref_store *ref_store,
update->type & REF_ISSYMREF) {
/* It is a loose reference. */
strbuf_reset(&sb);
- strbuf_git_path(&sb, "%s", lock->ref_name);
+ files_refname_path(refs, &sb, lock->ref_name);
if (unlink_or_msg(sb.buf, err)) {
ret = TRANSACTION_GENERIC_ERROR;
goto cleanup;
@@ -4201,25 +4207,24 @@ static int files_reflog_expire(struct ref_store *ref_store,
static int files_init_db(struct ref_store *ref_store, struct strbuf *err)
{
+ struct files_ref_store *refs =
+ files_downcast(ref_store, 0, "init_db");
struct strbuf sb = STRBUF_INIT;
- /* Check validity (but we don't need the result): */
- files_downcast(ref_store, 0, "init_db");
-
/*
* Create .git/refs/{heads,tags}
*/
- strbuf_git_path(&sb, "refs/heads");
+ files_refname_path(refs, &sb, "refs/heads");
safe_create_dir(sb.buf, 1);
strbuf_reset(&sb);
- strbuf_git_path(&sb, "refs/tags");
+ files_refname_path(refs, &sb, "refs/tags");
safe_create_dir(sb.buf, 1);
strbuf_reset(&sb);
if (get_shared_repository()) {
- strbuf_git_path(&sb, "refs/heads");
+ files_refname_path(refs, &sb, "refs/heads");
adjust_shared_perm(sb.buf);
strbuf_reset(&sb);
- strbuf_git_path(&sb, "refs/tags");
+ files_refname_path(refs, &sb, "refs/tags");
adjust_shared_perm(sb.buf);
}
strbuf_release(&sb);
--
2.11.0.157.gd943d85
^ permalink raw reply related
* [PATCH v5 05/24] files-backend: move "logs/" out of TMP_RENAMED_LOG
From: Nguyễn Thái Ngọc Duy @ 2017-02-22 14:04 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Michael Haggerty, Johannes Schindelin,
Ramsay Jones, Stefan Beller, novalis,
Nguyễn Thái Ngọc Duy
In-Reply-To: <20170222140450.30886-1-pclouds@gmail.com>
This makes reflog path building consistent, always in the form of
strbuf_git_path(sb, "logs/%s", refname);
It reduces the mental workload a bit in the next patch when that
function call is converted.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
refs/files-backend.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 435db1293..69946b0de 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -2513,7 +2513,7 @@ static int files_delete_refs(struct ref_store *ref_store,
* IOW, to avoid cross device rename errors, the temporary renamed log must
* live into logs/refs.
*/
-#define TMP_RENAMED_LOG "logs/refs/.tmp-renamed-log"
+#define TMP_RENAMED_LOG "refs/.tmp-renamed-log"
struct rename_cb {
const char *tmp_renamed_log;
@@ -2549,7 +2549,7 @@ static int rename_tmp_log(const char *newrefname)
int ret;
strbuf_git_path(&path, "logs/%s", newrefname);
- strbuf_git_path(&tmp, TMP_RENAMED_LOG);
+ strbuf_git_path(&tmp, "logs/%s", TMP_RENAMED_LOG);
cb.tmp_renamed_log = tmp.buf;
ret = raceproof_create_file(path.buf, rename_tmp_log_callback, &cb);
if (ret) {
@@ -2626,12 +2626,12 @@ static int files_rename_ref(struct ref_store *ref_store,
return 1;
strbuf_git_path(&sb_oldref, "logs/%s", oldrefname);
- strbuf_git_path(&tmp_renamed_log, TMP_RENAMED_LOG);
+ strbuf_git_path(&tmp_renamed_log, "logs/%s", TMP_RENAMED_LOG);
ret = log && rename(sb_oldref.buf, tmp_renamed_log.buf);
strbuf_release(&sb_oldref);
strbuf_release(&tmp_renamed_log);
if (ret)
- return error("unable to move logfile logs/%s to "TMP_RENAMED_LOG": %s",
+ return error("unable to move logfile logs/%s to logs/"TMP_RENAMED_LOG": %s",
oldrefname, strerror(errno));
if (delete_ref(oldrefname, orig_sha1, REF_NODEREF)) {
@@ -2714,10 +2714,10 @@ static int files_rename_ref(struct ref_store *ref_store,
if (logmoved && rename(sb_newref.buf, sb_oldref.buf))
error("unable to restore logfile %s from %s: %s",
oldrefname, newrefname, strerror(errno));
- strbuf_git_path(&tmp_renamed_log, TMP_RENAMED_LOG);
+ strbuf_git_path(&tmp_renamed_log, "logs/%s", TMP_RENAMED_LOG);
if (!logmoved && log &&
rename(tmp_renamed_log.buf, sb_oldref.buf))
- error("unable to restore logfile %s from "TMP_RENAMED_LOG": %s",
+ error("unable to restore logfile %s from logs/"TMP_RENAMED_LOG": %s",
oldrefname, strerror(errno));
strbuf_release(&sb_newref);
strbuf_release(&sb_oldref);
--
2.11.0.157.gd943d85
^ permalink raw reply related
* [PATCH v5 04/24] files-backend: convert git_path() to strbuf_git_path()
From: Nguyễn Thái Ngọc Duy @ 2017-02-22 14:04 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Michael Haggerty, Johannes Schindelin,
Ramsay Jones, Stefan Beller, novalis,
Nguyễn Thái Ngọc Duy
In-Reply-To: <20170222140450.30886-1-pclouds@gmail.com>
git_path() and friends are going to be killed in files-backend.c in near
future. And because there's a risk with overwriting buffer in
git_path(), let's convert them all to strbuf_git_path(). We'll have
easier time killing/converting strbuf_git_path() then because we won't
have to worry about memory management again.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
refs/files-backend.c | 139 +++++++++++++++++++++++++++++++++++++++------------
1 file changed, 106 insertions(+), 33 deletions(-)
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 4676525de..435db1293 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -2319,6 +2319,7 @@ enum {
static void try_remove_empty_parents(const char *refname, unsigned int flags)
{
struct strbuf buf = STRBUF_INIT;
+ struct strbuf sb = STRBUF_INIT;
char *p, *q;
int i;
@@ -2340,14 +2341,19 @@ static void try_remove_empty_parents(const char *refname, unsigned int flags)
if (q == p)
break;
strbuf_setlen(&buf, q - buf.buf);
- if ((flags & REMOVE_EMPTY_PARENTS_REF) &&
- rmdir(git_path("%s", buf.buf)))
+
+ strbuf_reset(&sb);
+ strbuf_git_path(&sb, "%s", buf.buf);
+ if ((flags & REMOVE_EMPTY_PARENTS_REF) && rmdir(sb.buf))
flags &= ~REMOVE_EMPTY_PARENTS_REF;
- if ((flags & REMOVE_EMPTY_PARENTS_REFLOG) &&
- rmdir(git_path("logs/%s", buf.buf)))
+
+ strbuf_reset(&sb);
+ strbuf_git_path(&sb, "logs/%s", buf.buf);
+ if ((flags & REMOVE_EMPTY_PARENTS_REFLOG) && rmdir(sb.buf))
flags &= ~REMOVE_EMPTY_PARENTS_REFLOG;
}
strbuf_release(&buf);
+ strbuf_release(&sb);
}
/* make sure nobody touched the ref, and unlink */
@@ -2509,11 +2515,16 @@ static int files_delete_refs(struct ref_store *ref_store,
*/
#define TMP_RENAMED_LOG "logs/refs/.tmp-renamed-log"
-static int rename_tmp_log_callback(const char *path, void *cb)
+struct rename_cb {
+ const char *tmp_renamed_log;
+ int true_errno;
+};
+
+static int rename_tmp_log_callback(const char *path, void *cb_data)
{
- int *true_errno = cb;
+ struct rename_cb *cb = cb_data;
- if (rename(git_path(TMP_RENAMED_LOG), path)) {
+ if (rename(cb->tmp_renamed_log, path)) {
/*
* rename(a, b) when b is an existing directory ought
* to result in ISDIR, but Solaris 5.8 gives ENOTDIR.
@@ -2521,7 +2532,7 @@ static int rename_tmp_log_callback(const char *path, void *cb)
* but report EISDIR to raceproof_create_file() so
* that it knows to retry.
*/
- *true_errno = errno;
+ cb->true_errno = errno;
if (errno == ENOTDIR)
errno = EISDIR;
return -1;
@@ -2532,20 +2543,26 @@ static int rename_tmp_log_callback(const char *path, void *cb)
static int rename_tmp_log(const char *newrefname)
{
- char *path = git_pathdup("logs/%s", newrefname);
- int ret, true_errno;
+ struct strbuf path = STRBUF_INIT;
+ struct strbuf tmp = STRBUF_INIT;
+ struct rename_cb cb;
+ int ret;
- ret = raceproof_create_file(path, rename_tmp_log_callback, &true_errno);
+ strbuf_git_path(&path, "logs/%s", newrefname);
+ strbuf_git_path(&tmp, TMP_RENAMED_LOG);
+ cb.tmp_renamed_log = tmp.buf;
+ ret = raceproof_create_file(path.buf, rename_tmp_log_callback, &cb);
if (ret) {
if (errno == EISDIR)
- error("directory not empty: %s", path);
+ error("directory not empty: %s", path.buf);
else
error("unable to move logfile %s to %s: %s",
- git_path(TMP_RENAMED_LOG), path,
- strerror(true_errno));
+ tmp.buf, path.buf,
+ strerror(cb.true_errno));
}
- free(path);
+ strbuf_release(&path);
+ strbuf_release(&tmp);
return ret;
}
@@ -2586,9 +2603,15 @@ static int files_rename_ref(struct ref_store *ref_store,
int flag = 0, logmoved = 0;
struct ref_lock *lock;
struct stat loginfo;
- int log = !lstat(git_path("logs/%s", oldrefname), &loginfo);
+ struct strbuf sb_oldref = STRBUF_INIT;
+ struct strbuf sb_newref = STRBUF_INIT;
+ struct strbuf tmp_renamed_log = STRBUF_INIT;
+ int log, ret;
struct strbuf err = STRBUF_INIT;
+ strbuf_git_path(&sb_oldref, "logs/%s", oldrefname);
+ log = !lstat(sb_oldref.buf, &loginfo);
+ strbuf_release(&sb_oldref);
if (log && S_ISLNK(loginfo.st_mode))
return error("reflog for %s is a symlink", oldrefname);
@@ -2602,7 +2625,12 @@ static int files_rename_ref(struct ref_store *ref_store,
if (!rename_ref_available(oldrefname, newrefname))
return 1;
- if (log && rename(git_path("logs/%s", oldrefname), git_path(TMP_RENAMED_LOG)))
+ strbuf_git_path(&sb_oldref, "logs/%s", oldrefname);
+ strbuf_git_path(&tmp_renamed_log, TMP_RENAMED_LOG);
+ ret = log && rename(sb_oldref.buf, tmp_renamed_log.buf);
+ strbuf_release(&sb_oldref);
+ strbuf_release(&tmp_renamed_log);
+ if (ret)
return error("unable to move logfile logs/%s to "TMP_RENAMED_LOG": %s",
oldrefname, strerror(errno));
@@ -2681,13 +2709,19 @@ static int files_rename_ref(struct ref_store *ref_store,
log_all_ref_updates = flag;
rollbacklog:
- if (logmoved && rename(git_path("logs/%s", newrefname), git_path("logs/%s", oldrefname)))
+ strbuf_git_path(&sb_newref, "logs/%s", newrefname);
+ strbuf_git_path(&sb_oldref, "logs/%s", oldrefname);
+ if (logmoved && rename(sb_newref.buf, sb_oldref.buf))
error("unable to restore logfile %s from %s: %s",
oldrefname, newrefname, strerror(errno));
+ strbuf_git_path(&tmp_renamed_log, TMP_RENAMED_LOG);
if (!logmoved && log &&
- rename(git_path(TMP_RENAMED_LOG), git_path("logs/%s", oldrefname)))
+ rename(tmp_renamed_log.buf, sb_oldref.buf))
error("unable to restore logfile %s from "TMP_RENAMED_LOG": %s",
oldrefname, strerror(errno));
+ strbuf_release(&sb_newref);
+ strbuf_release(&sb_oldref);
+ strbuf_release(&tmp_renamed_log);
return 1;
}
@@ -2861,18 +2895,24 @@ int files_log_ref_write(const char *refname, const unsigned char *old_sha1,
result = log_ref_write_fd(logfd, old_sha1, new_sha1,
git_committer_info(0), msg);
if (result) {
+ struct strbuf sb = STRBUF_INIT;
int save_errno = errno;
+ strbuf_git_path(&sb, "logs/%s", refname);
strbuf_addf(err, "unable to append to '%s': %s",
- git_path("logs/%s", refname), strerror(save_errno));
+ sb.buf, strerror(save_errno));
+ strbuf_release(&sb);
close(logfd);
return -1;
}
if (close(logfd)) {
+ struct strbuf sb = STRBUF_INIT;
int save_errno = errno;
+ strbuf_git_path(&sb, "logs/%s", refname);
strbuf_addf(err, "unable to append to '%s': %s",
- git_path("logs/%s", refname), strerror(save_errno));
+ sb.buf, strerror(save_errno));
+ strbuf_release(&sb);
return -1;
}
return 0;
@@ -3092,22 +3132,32 @@ int set_worktree_head_symref(const char *gitdir, const char *target)
static int files_reflog_exists(struct ref_store *ref_store,
const char *refname)
{
+ struct strbuf sb = STRBUF_INIT;
struct stat st;
+ int ret;
/* Check validity (but we don't need the result): */
files_downcast(ref_store, 0, "reflog_exists");
- return !lstat(git_path("logs/%s", refname), &st) &&
- S_ISREG(st.st_mode);
+ strbuf_git_path(&sb, "logs/%s", refname);
+ ret = !lstat(sb.buf, &st) && S_ISREG(st.st_mode);
+ strbuf_release(&sb);
+ return ret;
}
static int files_delete_reflog(struct ref_store *ref_store,
const char *refname)
{
+ struct strbuf sb = STRBUF_INIT;
+ int ret;
+
/* Check validity (but we don't need the result): */
files_downcast(ref_store, 0, "delete_reflog");
- return remove_path(git_path("logs/%s", refname));
+ strbuf_git_path(&sb, "logs/%s", refname);
+ ret = remove_path(sb.buf);
+ strbuf_release(&sb);
+ return ret;
}
static int show_one_reflog_ent(struct strbuf *sb, each_reflog_ent_fn fn, void *cb_data)
@@ -3162,7 +3212,9 @@ static int files_for_each_reflog_ent_reverse(struct ref_store *ref_store,
/* Check validity (but we don't need the result): */
files_downcast(ref_store, 0, "for_each_reflog_ent_reverse");
- logfp = fopen(git_path("logs/%s", refname), "r");
+ strbuf_git_path(&sb, "logs/%s", refname);
+ logfp = fopen(sb.buf, "r");
+ strbuf_release(&sb);
if (!logfp)
return -1;
@@ -3268,7 +3320,9 @@ static int files_for_each_reflog_ent(struct ref_store *ref_store,
/* Check validity (but we don't need the result): */
files_downcast(ref_store, 0, "for_each_reflog_ent");
- logfp = fopen(git_path("logs/%s", refname), "r");
+ strbuf_git_path(&sb, "logs/%s", refname);
+ logfp = fopen(sb.buf, "r");
+ strbuf_release(&sb);
if (!logfp)
return -1;
@@ -3350,12 +3404,15 @@ static struct ref_iterator *files_reflog_iterator_begin(struct ref_store *ref_st
{
struct files_reflog_iterator *iter = xcalloc(1, sizeof(*iter));
struct ref_iterator *ref_iterator = &iter->base;
+ struct strbuf sb = STRBUF_INIT;
/* Check validity (but we don't need the result): */
files_downcast(ref_store, 0, "reflog_iterator_begin");
base_ref_iterator_init(ref_iterator, &files_reflog_iterator_vtable);
- iter->dir_iterator = dir_iterator_begin(git_path("logs"));
+ strbuf_git_path(&sb, "logs");
+ iter->dir_iterator = dir_iterator_begin(sb.buf);
+ strbuf_release(&sb);
return ref_iterator;
}
@@ -3693,6 +3750,7 @@ static int files_transaction_commit(struct ref_store *ref_store,
char *head_ref = NULL;
int head_type;
struct object_id head_oid;
+ struct strbuf sb = STRBUF_INIT;
assert(err);
@@ -3814,7 +3872,9 @@ static int files_transaction_commit(struct ref_store *ref_store,
if (!(update->type & REF_ISPACKED) ||
update->type & REF_ISSYMREF) {
/* It is a loose reference. */
- if (unlink_or_msg(git_path("%s", lock->ref_name), err)) {
+ strbuf_reset(&sb);
+ strbuf_git_path(&sb, "%s", lock->ref_name);
+ if (unlink_or_msg(sb.buf, err)) {
ret = TRANSACTION_GENERIC_ERROR;
goto cleanup;
}
@@ -3834,7 +3894,9 @@ static int files_transaction_commit(struct ref_store *ref_store,
/* Delete the reflogs of any references that were deleted: */
for_each_string_list_item(ref_to_delete, &refs_to_delete) {
- if (!unlink_or_warn(git_path("logs/%s", ref_to_delete->string)))
+ strbuf_reset(&sb);
+ strbuf_git_path(&sb, "logs/%s", ref_to_delete->string);
+ if (!unlink_or_warn(sb.buf))
try_remove_empty_parents(ref_to_delete->string,
REMOVE_EMPTY_PARENTS_REFLOG);
}
@@ -3842,6 +3904,7 @@ static int files_transaction_commit(struct ref_store *ref_store,
clear_loose_ref_cache(refs);
cleanup:
+ strbuf_release(&sb);
transaction->state = REF_TRANSACTION_CLOSED;
for (i = 0; i < transaction->nr; i++) {
@@ -4108,18 +4171,28 @@ static int files_reflog_expire(struct ref_store *ref_store,
static int files_init_db(struct ref_store *ref_store, struct strbuf *err)
{
+ struct strbuf sb = STRBUF_INIT;
+
/* Check validity (but we don't need the result): */
files_downcast(ref_store, 0, "init_db");
/*
* Create .git/refs/{heads,tags}
*/
- safe_create_dir(git_path("refs/heads"), 1);
- safe_create_dir(git_path("refs/tags"), 1);
+ strbuf_git_path(&sb, "refs/heads");
+ safe_create_dir(sb.buf, 1);
+ strbuf_reset(&sb);
+ strbuf_git_path(&sb, "refs/tags");
+ safe_create_dir(sb.buf, 1);
+ strbuf_reset(&sb);
if (get_shared_repository()) {
- adjust_shared_perm(git_path("refs/heads"));
- adjust_shared_perm(git_path("refs/tags"));
+ strbuf_git_path(&sb, "refs/heads");
+ adjust_shared_perm(sb.buf);
+ strbuf_reset(&sb);
+ strbuf_git_path(&sb, "refs/tags");
+ adjust_shared_perm(sb.buf);
}
+ strbuf_release(&sb);
return 0;
}
--
2.11.0.157.gd943d85
^ permalink raw reply related
* [PATCH v5 03/24] files-backend: add and use files_packed_refs_path()
From: Nguyễn Thái Ngọc Duy @ 2017-02-22 14:04 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Michael Haggerty, Johannes Schindelin,
Ramsay Jones, Stefan Beller, novalis,
Nguyễn Thái Ngọc Duy
In-Reply-To: <20170222140450.30886-1-pclouds@gmail.com>
Keep repo-related path handling in one place. This will make it easier
to add submodule/multiworktree support later.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
refs/files-backend.c | 29 ++++++++++++++++++-----------
1 file changed, 18 insertions(+), 11 deletions(-)
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 1ebd59ec0..4676525de 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -923,6 +923,8 @@ struct files_ref_store {
*/
const char *submodule;
+ char *packed_refs_path;
+
struct ref_entry *loose;
struct packed_ref_cache *packed;
};
@@ -985,7 +987,14 @@ static struct ref_store *files_ref_store_create(const char *submodule)
base_ref_store_init(ref_store, &refs_be_files);
- refs->submodule = xstrdup_or_null(submodule);
+ if (submodule) {
+ refs->submodule = xstrdup(submodule);
+ refs->packed_refs_path = git_pathdup_submodule(
+ refs->submodule, "packed-refs");
+ return ref_store;
+ }
+
+ refs->packed_refs_path = git_pathdup("packed-refs");
return ref_store;
}
@@ -1153,19 +1162,18 @@ static void read_packed_refs(FILE *f, struct ref_dir *dir)
strbuf_release(&line);
}
+static const char *files_packed_refs_path(struct files_ref_store *refs)
+{
+ return refs->packed_refs_path;
+}
+
/*
* Get the packed_ref_cache for the specified files_ref_store,
* creating it if necessary.
*/
static struct packed_ref_cache *get_packed_ref_cache(struct files_ref_store *refs)
{
- char *packed_refs_file;
-
- if (refs->submodule)
- packed_refs_file = git_pathdup_submodule(refs->submodule,
- "packed-refs");
- else
- packed_refs_file = git_pathdup("packed-refs");
+ const char *packed_refs_file = files_packed_refs_path(refs);
if (refs->packed &&
!stat_validity_check(&refs->packed->validity, packed_refs_file))
@@ -1184,7 +1192,6 @@ static struct packed_ref_cache *get_packed_ref_cache(struct files_ref_store *ref
fclose(f);
}
}
- free(packed_refs_file);
return refs->packed;
}
@@ -2160,7 +2167,7 @@ static int lock_packed_refs(struct files_ref_store *refs, int flags)
}
if (hold_lock_file_for_update_timeout(
- &packlock, git_path("packed-refs"),
+ &packlock, files_packed_refs_path(refs),
flags, timeout_value) < 0)
return -1;
/*
@@ -2426,7 +2433,7 @@ static int repack_without_refs(struct files_ref_store *refs,
return 0; /* no refname exists in packed refs */
if (lock_packed_refs(refs, 0)) {
- unable_to_lock_message(git_path("packed-refs"), errno, err);
+ unable_to_lock_message(files_packed_refs_path(refs), errno, err);
return -1;
}
packed = get_packed_refs(refs);
--
2.11.0.157.gd943d85
^ permalink raw reply related
* [PATCH v5 02/24] files-backend: make files_log_ref_write() static
From: Nguyễn Thái Ngọc Duy @ 2017-02-22 14:04 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Michael Haggerty, Johannes Schindelin,
Ramsay Jones, Stefan Beller, novalis,
Nguyễn Thái Ngọc Duy
In-Reply-To: <20170222140450.30886-1-pclouds@gmail.com>
Created in 5f3c3a4e6f (files_log_ref_write: new function - 2015-11-10)
but probably never used outside refs-internal.c
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
refs/files-backend.c | 3 +++
refs/refs-internal.h | 4 ----
2 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/refs/files-backend.c b/refs/files-backend.c
index db3bd42a9..1ebd59ec0 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -165,6 +165,9 @@ static struct ref_entry *create_dir_entry(struct files_ref_store *ref_store,
const char *dirname, size_t len,
int incomplete);
static void add_entry_to_dir(struct ref_dir *dir, struct ref_entry *entry);
+static int files_log_ref_write(const char *refname, const unsigned char *old_sha1,
+ const unsigned char *new_sha1, const char *msg,
+ int flags, struct strbuf *err);
static struct ref_dir *get_ref_dir(struct ref_entry *entry)
{
diff --git a/refs/refs-internal.h b/refs/refs-internal.h
index fa93c9a32..f732473e1 100644
--- a/refs/refs-internal.h
+++ b/refs/refs-internal.h
@@ -228,10 +228,6 @@ struct ref_transaction {
enum ref_transaction_state state;
};
-int files_log_ref_write(const char *refname, const unsigned char *old_sha1,
- const unsigned char *new_sha1, const char *msg,
- int flags, struct strbuf *err);
-
/*
* Check for entries in extras that are within the specified
* directory, where dirname is a reference directory name including
--
2.11.0.157.gd943d85
^ permalink raw reply related
* [PATCH v5 01/24] refs.h: add forward declaration for structs used in this file
From: Nguyễn Thái Ngọc Duy @ 2017-02-22 14:04 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Michael Haggerty, Johannes Schindelin,
Ramsay Jones, Stefan Beller, novalis,
Nguyễn Thái Ngọc Duy
In-Reply-To: <20170222140450.30886-1-pclouds@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
refs.h | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/refs.h b/refs.h
index 9fbff90e7..c494b641a 100644
--- a/refs.h
+++ b/refs.h
@@ -1,6 +1,11 @@
#ifndef REFS_H
#define REFS_H
+struct object_id;
+struct ref_transaction;
+struct strbuf;
+struct string_list;
+
/*
* Resolve a reference, recursively following symbolic refererences.
*
@@ -144,7 +149,6 @@ int dwim_log(const char *str, int len, unsigned char *sha1, char **ref);
* `ref_transaction_commit` is called. So `ref_transaction_verify`
* won't report a verification failure until the commit is attempted.
*/
-struct ref_transaction;
/*
* Bit values set in the flags argument passed to each_ref_fn() and
--
2.11.0.157.gd943d85
^ permalink raw reply related
* [PATCH v5 00/24] Remove submodule from files-backend.c
From: Nguyễn Thái Ngọc Duy @ 2017-02-22 14:04 UTC (permalink / raw)
To: git
Cc: Junio C Hamano, Michael Haggerty, Johannes Schindelin,
Ramsay Jones, Stefan Beller, novalis,
Nguyễn Thái Ngọc Duy
In-Reply-To: <20170218133303.3682-1-pclouds@gmail.com>
v5 goes a bit longer than v4, basically:
- files_path() is broken down into three smaller functions,
files_{packed_refs,reflog,refname}_path().
- most of store-based api is added because..
- test-ref-store.c is added with t1405 and t1406 for some basic tests
I'm not aimimg for complete ref store coverage. But we can continue
to improve from there.
- refs_store_init() now takes a "permission" flag, like open().
Operations are allowed or forbidden based on this flag. The
submodule_allowed flag is killed. files_assert_main.. remains.
- get_*_ref_store() remain public api because it's used by
test-ref-store.c and pack-refs.c.
- files-backend.c should now make no function calls that implicitly
target the main store. But this will have to be tested more to be
sure. I'm tempted to add a tracing backend just for this purpose.
Junio, if you take this on 'pu', you'll have to kick my other two
series out (they should not even compile). I'm not resending them
until I get a "looks mostly ok" from Michael. No point in updating
them when this series keeps moving.
This series is also available on my github repo. branch
files-backend-git-dir-2.
Nguyễn Thái Ngọc Duy (24):
refs.h: add forward declaration for structs used in this file
files-backend: make files_log_ref_write() static
files-backend: add and use files_packed_refs_path()
files-backend: convert git_path() to strbuf_git_path()
files-backend: move "logs/" out of TMP_RENAMED_LOG
files-backend: add and use files_reflog_path()
files-backend: add and use files_refname_path()
files-backend: remove the use of git_path()
refs.c: introduce get_main_ref_store()
refs: rename lookup_ref_store() to lookup_submodule_ref_store()
refs.c: flatten get_ref_store() a bit
refs.c: kill register_ref_store(), add register_submodule_ref_store()
refs.c: make get_main_ref_store() public and use it
path.c: move some code out of strbuf_git_path_submodule()
refs: move submodule code out of files-backend.c
files-backend: replace submodule_allowed check in files_downcast()
refs: rename get_ref_store() to get_submodule_ref_store() and make it public
refs: add new ref-store api
refs: new transaction related ref-store api
files-backend: avoid ref api targetting main ref store
refs: delete pack_refs() in favor of refs_pack_refs()
t/helper: add test-ref-store to test ref-store functions
t1405: some basic tests on main ref store
t1406: new tests for submodule ref store
Makefile | 1 +
builtin/pack-refs.c | 2 +-
path.c | 34 +--
refs.c | 411 ++++++++++++++++++--------
refs.h | 100 ++++++-
refs/files-backend.c | 509 +++++++++++++++++++++-----------
refs/refs-internal.h | 64 +---
submodule.c | 31 ++
submodule.h | 1 +
t/helper/.gitignore | 1 +
t/helper/test-ref-store.c (new) | 274 +++++++++++++++++
t/t1405-main-ref-store.sh (new +x) | 123 ++++++++
t/t1406-submodule-ref-store.sh (new +x) | 95 ++++++
13 files changed, 1269 insertions(+), 377 deletions(-)
create mode 100644 t/helper/test-ref-store.c
create mode 100755 t/t1405-main-ref-store.sh
create mode 100755 t/t1406-submodule-ref-store.sh
--
2.11.0.157.gd943d85
^ permalink raw reply
* Re: feature request: user email config per domain
From: Pranit Bauva @ 2017-02-22 13:51 UTC (permalink / raw)
To: Tushar Kapila; +Cc: Git List
In-Reply-To: <CAN0Skmmjd5Y0uWz_WC69mAStucZ6nR0mjdp4-ODJz2UnTaB-eQ@mail.gmail.com>
Hey Tushar,
When you run `git config --global user.email abc@xyz.com` it writes
out this setting in ~/.gitconfig which is then considered to be
"global" ie. this same email will be used for every repo, but ...
You can always override this. Let's say there is a repo named "foo" in
which you want the email "xyz@abc.com", then you go inside that folder
and type `git config user.email xyz@abc.com`. Note: the option
`--global` is skipped here. This creates a file `.gitconfig` in the
folder "foo" and now whenever you commit, the .gitconfig file inside
the repo will get the first preference and then the global
~/.gitconfig.
This will work for you assuming that you have different repos for your
company and for your open source work. Will this solve your problem?
Regards,
Pranit Bauva
^ permalink raw reply
* feature request: user email config per domain
From: Tushar Kapila @ 2017-02-22 13:12 UTC (permalink / raw)
To: git
I can set my email via:
git config --global user.email tgkprog@xyz.dom
this is dangerous when I use this my office or in a multi repository
provider environment where my email is different for a few (like
tgkprog@search.com for github and tushar@mycompany.com for my company
private repo). I know I can over ride it per repository, but sometimes
forget to do that. And even if I unset it, it inadvertantly gets set
elsewhere when I make a repo and the site 'helps' me by showing me the
commands to init and clone my new repo.
I did an analysis on a bunch of company git repositories using jgit
(only master branch), and we have 57 emails out of 346 which are not
the company email. Also in there are cases when name is the same but
some commits are by email 1 and others by email 2, because of this
global config. As some of us work on open source and company repos on
the same computer.
Feature request : can we have a config for email per repo domain ?
Something like:
git config --global domain.user.email tgkprog@test.xyz.com
testing.abc.doman:8080
git config --global domain.user.email tgkprog@xyz.com abc.doman:80
git config --global domain.user.email tgkprog@search.com github.com
So when remote URL has github.com push as tgkprog@search.com but for
testing.abc.doman:8080 use tgkprog@test.xyz.com ?
For me one name is enough. But can do the same for name if others need it?
Thank you.
Regards
Tushar Kapila
^ permalink raw reply
* [PATCH] Documentation: correctly spell git worktree --detach
From: brian m. carlson @ 2017-02-22 12:34 UTC (permalink / raw)
To: git; +Cc: Casey Rodarmor
In-Reply-To: <CANLPe+OaSnNb1jhAnFtMsOCfho0H7mHVHiXs7rqo6ZHNvRe3-w@mail.gmail.com>
The option is “--detach”, but we accidentally spelled it “--detached” at
one point in the man page.
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Reported-by: Casey Rodarmor <casey@rodarmor.com>
---
Documentation/git-worktree.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Documentation/git-worktree.txt b/Documentation/git-worktree.txt
index e257c19ebe..553cf8413f 100644
--- a/Documentation/git-worktree.txt
+++ b/Documentation/git-worktree.txt
@@ -52,7 +52,7 @@ is linked to the current repository, sharing everything except working
directory specific files such as HEAD, index, etc. `-` may also be
specified as `<branch>`; it is synonymous with `@{-1}`.
+
-If `<branch>` is omitted and neither `-b` nor `-B` nor `--detached` used,
+If `<branch>` is omitted and neither `-b` nor `-B` nor `--detach` used,
then, as a convenience, a new branch based at HEAD is created automatically,
as if `-b $(basename <path>)` was specified.
^ permalink raw reply related
* Re: Fwd: Typo in worktree man page
From: brian m. carlson @ 2017-02-22 12:32 UTC (permalink / raw)
To: Casey Rodarmor; +Cc: git
In-Reply-To: <CANLPe+OaSnNb1jhAnFtMsOCfho0H7mHVHiXs7rqo6ZHNvRe3-w@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 439 bytes --]
On Tue, Feb 21, 2017 at 04:52:11PM -0800, Casey Rodarmor wrote:
> Hi there,
>
> The git worktree man page mentions the `--detached` flag in the
> section on `add`, but the flag is actually called `--detach`.
Thanks for reporting this. I'll send a patch.
--
brian m. carlson / brian with sandals: Houston, Texas, US
+1 832 623 2791 | https://www.crustytoothpaste.net/~bmc | My opinion only
OpenPGP: https://keybase.io/bk2204
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 868 bytes --]
^ permalink raw reply
* [PATCH] Documentation: use brackets for optional arguments
From: brian m. carlson @ 2017-02-22 12:25 UTC (permalink / raw)
To: git
The documentation for git blame used vertical bars for optional
arguments to -M and -C, which is unusual and potentially confusing.
Since most man pages use brackets for optional items, and that's
consistent with how we document the same options for git diff and
friends, use brackets here, too.
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
Documentation/blame-options.txt | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Documentation/blame-options.txt b/Documentation/blame-options.txt
index 2669b87c9d..dc41957afa 100644
--- a/Documentation/blame-options.txt
+++ b/Documentation/blame-options.txt
@@ -77,7 +77,7 @@ include::line-range-format.txt[]
terminal. Can't use `--progress` together with `--porcelain`
or `--incremental`.
--M|<num>|::
+-M[<num>]::
Detect moved or copied lines within a file. When a commit
moves or copies a block of lines (e.g. the original file
has A and then B, and the commit changes it to B and then
@@ -93,7 +93,7 @@ alphanumeric characters that Git must detect as moving/copying
within a file for it to associate those lines with the parent
commit. The default value is 20.
--C|<num>|::
+-C[<num>]::
In addition to `-M`, detect lines moved or copied from other
files that were modified in the same commit. This is
useful when you reorganize your program and move code
^ permalink raw reply related
* Re: [RFC][Git GUI] Make Commit message field in git GUI re sizable.
From: Jessie Hernandez @ 2017-02-22 11:59 UTC (permalink / raw)
To: Bert Wesarg; +Cc: Jessie Hernandez, Git Mailing List, Pat Thoyts
In-Reply-To: <CAKPyHN3f0NwMt1aXx6keSrhaiqRqH6s_xQFdKv5rZ+pL7fmXFw@mail.gmail.com>
> HI,
>
> the reason why it is fixed, is because commit messages should be
> wrapped at 76 characters to be used in mails. So it helps you with the
> wrapping.
>
> Bert
Right ok. I understand.
Knowing this I think I might start writing my commit messages differently
then.
Thank you for this.
Regards
-----------------
Jessie Hernandez
>
>
> On Wed, Feb 22, 2017 at 10:27 AM, Jessie Hernandez
> <jessie@jessiehernandez.com> wrote:
>> Hi all,
>>
>> I have been using git for a few years now and really like the software.
>> I have a small annoyance and was wondering if I could get the
>> communities
>> view on this.
>>
>> When using git GUI I find it handy to be able to re-size the "Unstaged
>> Changes" and the "Staged Changed" fields.
>>
>> I would like the same thing for the "Commit Message" field, or to have
>> it
>> re-size with the git GUI window.
>>
>> I can re-size the "Commit Message" vertically when making the "Modified"
>> panel smaller.
>>
>> Does this make sense?
>> I would be happy to get into more detail if that is necessary or if
>> something is not clear.
>>
>> Thank you.
>>
>> -----------------
>> Jessie Hernandez
>>
>>
>
^ permalink raw reply
* Re: [RFC][Git GUI] Make Commit message field in git GUI re sizable.
From: Bert Wesarg @ 2017-02-22 9:50 UTC (permalink / raw)
To: Jessie Hernandez; +Cc: Git Mailing List, Pat Thoyts
In-Reply-To: <44fd4dce451fb0783de02c0a8c4a14aa.squirrel@mail.jessiehernandez.com>
HI,
the reason why it is fixed, is because commit messages should be
wrapped at 76 characters to be used in mails. So it helps you with the
wrapping.
Bert
On Wed, Feb 22, 2017 at 10:27 AM, Jessie Hernandez
<jessie@jessiehernandez.com> wrote:
> Hi all,
>
> I have been using git for a few years now and really like the software.
> I have a small annoyance and was wondering if I could get the communities
> view on this.
>
> When using git GUI I find it handy to be able to re-size the "Unstaged
> Changes" and the "Staged Changed" fields.
>
> I would like the same thing for the "Commit Message" field, or to have it
> re-size with the git GUI window.
>
> I can re-size the "Commit Message" vertically when making the "Modified"
> panel smaller.
>
> Does this make sense?
> I would be happy to get into more detail if that is necessary or if
> something is not clear.
>
> Thank you.
>
> -----------------
> Jessie Hernandez
>
>
^ permalink raw reply
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox