Commit 86194b24 by Vicent Marti

Split packed from unpacked references

These two reference types are now stored separately to eventually allow
the removal/renaming of loose references and rewriting of the refs
packfile.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
parent 32054c24
...@@ -53,6 +53,5 @@ typedef SSIZE_T ssize_t; ...@@ -53,6 +53,5 @@ typedef SSIZE_T ssize_t;
#include "bswap.h" #include "bswap.h"
#define GIT_PATH_MAX 4096 #define GIT_PATH_MAX 4096
#define GIT_FILELOCK_EXTENSION ".lock\0"
#endif /* INCLUDE_common_h__ */ #endif /* INCLUDE_common_h__ */
...@@ -28,9 +28,6 @@ ...@@ -28,9 +28,6 @@
#include "filebuf.h" #include "filebuf.h"
#include "fileops.h" #include "fileops.h"
static const char *GIT_FILELOCK_EXTENSION = ".lock\0";
static const size_t GIT_FILELOCK_EXTLENGTH = 6;
static const size_t WRITE_BUFFER_SIZE = (4096 * 2); static const size_t WRITE_BUFFER_SIZE = (4096 * 2);
static int lock_file(git_filebuf *file, int flags) static int lock_file(git_filebuf *file, int flags)
......
...@@ -12,6 +12,9 @@ ...@@ -12,6 +12,9 @@
#define GIT_FILEBUF_APPEND 0x2 #define GIT_FILEBUF_APPEND 0x2
#define GIT_FILEBUF_FORCE 0x4 #define GIT_FILEBUF_FORCE 0x4
#define GIT_FILELOCK_EXTENSION ".lock\0"
#define GIT_FILELOCK_EXTLENGTH 6
struct git_filebuf { struct git_filebuf {
char *path_original; char *path_original;
char *path_lock; char *path_lock;
......
...@@ -140,10 +140,11 @@ typedef struct git_reference git_reference; ...@@ -140,10 +140,11 @@ typedef struct git_reference git_reference;
/** Basic type of any Git reference. */ /** Basic type of any Git reference. */
typedef enum { typedef enum {
GIT_REF_ANY = -2, /** Reference can be an object id reference or a symbolic reference */ GIT_REF_INVALID = 0, /** Invalid reference */
GIT_REF_INVALID = -1, /** Invalid reference */
GIT_REF_OID = 1, /** A reference which points at an object id */ GIT_REF_OID = 1, /** A reference which points at an object id */
GIT_REF_SYMBOLIC = 2, /** A reference which points at another reference */ GIT_REF_SYMBOLIC = 2, /** A reference which points at another reference */
GIT_REF_PACKED = 4,
GIT_REF_HAS_PEEL = 8,
} git_rtype; } git_rtype;
/** @} */ /** @} */
......
...@@ -18,25 +18,22 @@ ...@@ -18,25 +18,22 @@
struct git_reference { struct git_reference {
git_repository *owner; git_repository *owner;
git_rtype type;
char *name; char *name;
unsigned int type;
unsigned packed:1;
union {
char *ref;
git_oid oid;
} target;
}; };
typedef struct { typedef struct {
git_hashtable *cache; git_hashtable *packed_refs;
git_hashtable *loose_refs;
unsigned pack_loaded:1; unsigned pack_loaded:1;
} git_refcache; } git_refcache;
void git_repository__refcache_free(git_refcache *refs); void git_repository__refcache_free(git_refcache *refs);
int git_repository__refcache_init(git_refcache *refs); int git_repository__refcache_init(git_refcache *refs);
int git_reference__normalize_name(char *buffer_out, const char *name, git_rtype type);
int git_reference__normalize_name(char *buffer_out, const char *name);
int git_reference__normalize_name_oid(char *buffer_out, const char *name);
#endif #endif
...@@ -35,18 +35,13 @@ static int resize_vector(git_vector *v) ...@@ -35,18 +35,13 @@ static int resize_vector(git_vector *v)
void **new_contents; void **new_contents;
v->_alloc_size = ((unsigned int)(v->_alloc_size * resize_factor)) + 1; v->_alloc_size = ((unsigned int)(v->_alloc_size * resize_factor)) + 1;
if (v->_alloc_size == 0) if (v->_alloc_size < minimum_size)
v->_alloc_size = minimum_size; v->_alloc_size = minimum_size;
new_contents = git__malloc(v->_alloc_size * sizeof(void *)); v->contents = realloc(v->contents, v->_alloc_size * sizeof(void *));
if (new_contents == NULL) if (v->contents == NULL)
return GIT_ENOMEM; return GIT_ENOMEM;
memcpy(new_contents, v->contents, v->length * sizeof(void *));
free(v->contents);
v->contents = new_contents;
return GIT_SUCCESS; return GIT_SUCCESS;
} }
...@@ -93,12 +88,6 @@ int git_vector_insert(git_vector *v, void *element) ...@@ -93,12 +88,6 @@ int git_vector_insert(git_vector *v, void *element)
return GIT_SUCCESS; return GIT_SUCCESS;
} }
void *git_vector_get(git_vector *v, unsigned int position)
{
assert(v);
return (position < v->length) ? v->contents[position] : NULL;
}
void git_vector_sort(git_vector *v) void git_vector_sort(git_vector *v)
{ {
assert(v); assert(v);
......
...@@ -24,7 +24,10 @@ void git_vector_clear(git_vector *v); ...@@ -24,7 +24,10 @@ void git_vector_clear(git_vector *v);
int git_vector_search(git_vector *v, const void *key); int git_vector_search(git_vector *v, const void *key);
void git_vector_sort(git_vector *v); void git_vector_sort(git_vector *v);
void *git_vector_get(git_vector *v, unsigned int position); GIT_INLINE(void *) git_vector_get(git_vector *v, unsigned int position)
{
return (position < v->length) ? v->contents[position] : NULL;
}
int git_vector_insert(git_vector *v, void *element); int git_vector_insert(git_vector *v, void *element);
int git_vector_remove(git_vector *v, unsigned int idx); int git_vector_remove(git_vector *v, unsigned int idx);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment