Commit f063a758 by Vicent Martí

Merge pull request #1485 from libgit2/include-git2-sys

Create include/git2/sys and move backend APIs there
parents bfb4facb 21ca0451
...@@ -201,14 +201,12 @@ GIT_EXTERN(int) git_commit_nth_gen_ancestor( ...@@ -201,14 +201,12 @@ GIT_EXTERN(int) git_commit_nth_gen_ancestor(
unsigned int n); unsigned int n);
/** /**
* Create a new commit in the repository using `git_object` * Create new commit in the repository from a list of `git_object` pointers
* instances as parameters.
* *
* The message will not be cleaned up. This can be achieved * The message will not be cleaned up automatically. You can do that with
* through `git_message_prettify()`. * the `git_message_prettify()` function.
* *
* @param id Pointer where to store the OID of the * @param id Pointer in which to store the OID of the newly created commit
* newly created commit
* *
* @param repo Repository where to store the commit * @param repo Repository where to store the commit
* *
...@@ -219,73 +217,69 @@ GIT_EXTERN(int) git_commit_nth_gen_ancestor( ...@@ -219,73 +217,69 @@ GIT_EXTERN(int) git_commit_nth_gen_ancestor(
* make it point to this commit. If the reference doesn't * make it point to this commit. If the reference doesn't
* exist yet, it will be created. * exist yet, it will be created.
* *
* @param author Signature representing the author and the authory * @param author Signature with author and author time of commit
* time of this commit
* *
* @param committer Signature representing the committer and the * @param committer Signature with committer and * commit time of commit
* commit time of this commit
* *
* @param message_encoding The encoding for the message in the * @param message_encoding The encoding for the message in the
* commit, represented with a standard encoding name. * commit, represented with a standard encoding name.
* E.g. "UTF-8". If NULL, no encoding header is written and * E.g. "UTF-8". If NULL, no encoding header is written and
* UTF-8 is assumed. * UTF-8 is assumed.
* *
* @param message Full message for this commit * @param message Full message for this commit
* *
* @param tree An instance of a `git_tree` object that will * @param tree An instance of a `git_tree` object that will
* be used as the tree for the commit. This tree object must * be used as the tree for the commit. This tree object must
* also be owned by the given `repo`. * also be owned by the given `repo`.
* *
* @param parent_count Number of parents for this commit * @param parent_count Number of parents for this commit
* *
* @param parents[] Array of `parent_count` pointers to `git_commit` * @param parents[] Array of `parent_count` pointers to `git_commit`
* objects that will be used as the parents for this commit. This * objects that will be used as the parents for this commit. This
* array may be NULL if `parent_count` is 0 (root commit). All the * array may be NULL if `parent_count` is 0 (root commit). All the
* given commits must be owned by the `repo`. * given commits must be owned by the `repo`.
* *
* @return 0 or an error code * @return 0 or an error code
* The created commit will be written to the Object Database and * The created commit will be written to the Object Database and
* the given reference will be updated to point to it * the given reference will be updated to point to it
*/ */
GIT_EXTERN(int) git_commit_create( GIT_EXTERN(int) git_commit_create(
git_oid *id, git_oid *id,
git_repository *repo, git_repository *repo,
const char *update_ref, const char *update_ref,
const git_signature *author, const git_signature *author,
const git_signature *committer, const git_signature *committer,
const char *message_encoding, const char *message_encoding,
const char *message, const char *message,
const git_tree *tree, const git_tree *tree,
int parent_count, int parent_count,
const git_commit *parents[]); const git_commit *parents[]);
/** /**
* Create a new commit in the repository using a variable * Create new commit in the repository using a variable argument list.
* argument list.
* *
* The message will be cleaned up from excess whitespace * The message will be cleaned up from excess whitespace and it will be made
* it will be made sure that the last line ends with a '\n'. * sure that the last line ends with a '\n'.
* *
* The parents for the commit are specified as a variable * The parents for the commit are specified as a variable list of pointers
* list of pointers to `const git_commit *`. Note that this * to `const git_commit *`. Note that this is a convenience method which may
* is a convenience method which may not be safe to export * not be safe to export for certain languages or compilers
* for certain languages or compilers
* *
* All other parameters remain the same * All other parameters remain the same at `git_commit_create()`.
* *
* @see git_commit_create * @see git_commit_create
*/ */
GIT_EXTERN(int) git_commit_create_v( GIT_EXTERN(int) git_commit_create_v(
git_oid *id, git_oid *id,
git_repository *repo, git_repository *repo,
const char *update_ref, const char *update_ref,
const git_signature *author, const git_signature *author,
const git_signature *committer, const git_signature *committer,
const char *message_encoding, const char *message_encoding,
const char *message, const char *message,
const git_tree *tree, const git_tree *tree,
int parent_count, int parent_count,
...); ...);
/** @} */ /** @} */
GIT_END_DECL GIT_END_DECL
......
...@@ -43,29 +43,6 @@ typedef struct { ...@@ -43,29 +43,6 @@ typedef struct {
typedef int (*git_config_foreach_cb)(const git_config_entry *, void *); typedef int (*git_config_foreach_cb)(const git_config_entry *, void *);
/**
* Generic backend that implements the interface to
* access a configuration file
*/
struct git_config_backend {
unsigned int version;
struct git_config *cfg;
/* Open means open the file/database and parse if necessary */
int (*open)(struct git_config_backend *, unsigned int level);
int (*get)(const struct git_config_backend *, const char *key, const git_config_entry **entry);
int (*get_multivar)(struct git_config_backend *, const char *key, const char *regexp, git_config_foreach_cb callback, void *payload);
int (*set)(struct git_config_backend *, const char *key, const char *value);
int (*set_multivar)(git_config_backend *cfg, const char *name, const char *regexp, const char *value);
int (*del)(struct git_config_backend *, const char *key);
int (*foreach)(struct git_config_backend *, const char *, git_config_foreach_cb callback, void *payload);
int (*refresh)(struct git_config_backend *);
void (*free)(struct git_config_backend *);
};
#define GIT_CONFIG_BACKEND_VERSION 1
#define GIT_CONFIG_BACKEND_INIT {GIT_CONFIG_BACKEND_VERSION}
typedef enum { typedef enum {
GIT_CVAR_FALSE = 0, GIT_CVAR_FALSE = 0,
GIT_CVAR_TRUE = 1, GIT_CVAR_TRUE = 1,
...@@ -154,30 +131,6 @@ GIT_EXTERN(int) git_config_open_default(git_config **out); ...@@ -154,30 +131,6 @@ GIT_EXTERN(int) git_config_open_default(git_config **out);
GIT_EXTERN(int) git_config_new(git_config **out); GIT_EXTERN(int) git_config_new(git_config **out);
/** /**
* Add a generic config file instance to an existing config
*
* Note that the configuration object will free the file
* automatically.
*
* Further queries on this config object will access each
* of the config file instances in order (instances with
* a higher priority level will be accessed first).
*
* @param cfg the configuration to add the file to
* @param file the configuration file (backend) to add
* @param level the priority level of the backend
* @param force if a config file already exists for the given
* priority level, replace it
* @return 0 on success, GIT_EEXISTS when adding more than one file
* for a given priority level (and force_replace set to 0), or error code
*/
GIT_EXTERN(int) git_config_add_backend(
git_config *cfg,
git_config_backend *file,
unsigned int level,
int force);
/**
* Add an on-disk config file instance to an existing config * Add an on-disk config file instance to an existing config
* *
* The on-disk file pointed at by `path` will be opened and * The on-disk file pointed at by `path` will be opened and
...@@ -192,10 +145,9 @@ GIT_EXTERN(int) git_config_add_backend( ...@@ -192,10 +145,9 @@ GIT_EXTERN(int) git_config_add_backend(
* a higher priority level will be accessed first). * a higher priority level will be accessed first).
* *
* @param cfg the configuration to add the file to * @param cfg the configuration to add the file to
* @param path path to the configuration file (backend) to add * @param path path to the configuration file to add
* @param level the priority level of the backend * @param level the priority level of the backend
* @param force if a config file already exists for the given * @param force replace config file at the given priority level
* priority level, replace it
* @return 0 on success, GIT_EEXISTS when adding more than one file * @return 0 on success, GIT_EEXISTS when adding more than one file
* for a given priority level (and force_replace set to 0), * for a given priority level (and force_replace set to 0),
* GIT_ENOTFOUND when the file doesn't exist or error code * GIT_ENOTFOUND when the file doesn't exist or error code
......
...@@ -8,31 +8,11 @@ ...@@ -8,31 +8,11 @@
#define _INCLUDE_git_indexer_h__ #define _INCLUDE_git_indexer_h__
#include "common.h" #include "common.h"
#include "types.h"
#include "oid.h" #include "oid.h"
GIT_BEGIN_DECL GIT_BEGIN_DECL
/**
* This is passed as the first argument to the callback to allow the
* user to see the progress.
*/
typedef struct git_transfer_progress {
unsigned int total_objects;
unsigned int indexed_objects;
unsigned int received_objects;
size_t received_bytes;
} git_transfer_progress;
/**
* Type for progress callbacks during indexing. Return a value less than zero
* to cancel the transfer.
*
* @param stats Structure containing information about the state of the transfer
* @param payload Payload provided by caller
*/
typedef int (*git_transfer_progress_callback)(const git_transfer_progress *stats, void *payload);
typedef struct git_indexer_stream git_indexer_stream; typedef struct git_indexer_stream git_indexer_stream;
/** /**
......
...@@ -10,8 +10,6 @@ ...@@ -10,8 +10,6 @@
#include "common.h" #include "common.h"
#include "types.h" #include "types.h"
#include "oid.h" #include "oid.h"
#include "odb_backend.h"
#include "indexer.h"
/** /**
* @file git2/odb.h * @file git2/odb.h
...@@ -23,6 +21,11 @@ ...@@ -23,6 +21,11 @@
GIT_BEGIN_DECL GIT_BEGIN_DECL
/** /**
* Function type for callbacks from git_odb_foreach.
*/
typedef int (*git_odb_foreach_cb)(const git_oid *id, void *payload);
/**
* Create a new object database with no backends. * Create a new object database with no backends.
* *
* Before the ODB can be used for read/writing, a custom database * Before the ODB can be used for read/writing, a custom database
...@@ -53,42 +56,6 @@ GIT_EXTERN(int) git_odb_new(git_odb **out); ...@@ -53,42 +56,6 @@ GIT_EXTERN(int) git_odb_new(git_odb **out);
GIT_EXTERN(int) git_odb_open(git_odb **out, const char *objects_dir); GIT_EXTERN(int) git_odb_open(git_odb **out, const char *objects_dir);
/** /**
* Add a custom backend to an existing Object DB
*
* The backends are checked in relative ordering, based on the
* value of the `priority` parameter.
*
* Read <odb_backends.h> for more information.
*
* @param odb database to add the backend to
* @param backend pointer to a git_odb_backend instance
* @param priority Value for ordering the backends queue
* @return 0 on success; error code otherwise
*/
GIT_EXTERN(int) git_odb_add_backend(git_odb *odb, git_odb_backend *backend, int priority);
/**
* Add a custom backend to an existing Object DB; this
* backend will work as an alternate.
*
* Alternate backends are always checked for objects *after*
* all the main backends have been exhausted.
*
* The backends are checked in relative ordering, based on the
* value of the `priority` parameter.
*
* Writing is disabled on alternate backends.
*
* Read <odb_backends.h> for more information.
*
* @param odb database to add the backend to
* @param backend pointer to a git_odb_backend instance
* @param priority Value for ordering the backends queue
* @return 0 on success; error code otherwise
*/
GIT_EXTERN(int) git_odb_add_alternate(git_odb *odb, git_odb_backend *backend, int priority);
/**
* Add an on-disk alternate to an existing Object DB. * Add an on-disk alternate to an existing Object DB.
* *
* Note that the added path must point to an `objects`, not * Note that the added path must point to an `objects`, not
...@@ -406,6 +373,60 @@ GIT_EXTERN(size_t) git_odb_object_size(git_odb_object *object); ...@@ -406,6 +373,60 @@ GIT_EXTERN(size_t) git_odb_object_size(git_odb_object *object);
*/ */
GIT_EXTERN(git_otype) git_odb_object_type(git_odb_object *object); GIT_EXTERN(git_otype) git_odb_object_type(git_odb_object *object);
/**
* Add a custom backend to an existing Object DB
*
* The backends are checked in relative ordering, based on the
* value of the `priority` parameter.
*
* Read <odb_backends.h> for more information.
*
* @param odb database to add the backend to
* @param backend pointer to a git_odb_backend instance
* @param priority Value for ordering the backends queue
* @return 0 on success; error code otherwise
*/
GIT_EXTERN(int) git_odb_add_backend(git_odb *odb, git_odb_backend *backend, int priority);
/**
* Add a custom backend to an existing Object DB; this
* backend will work as an alternate.
*
* Alternate backends are always checked for objects *after*
* all the main backends have been exhausted.
*
* The backends are checked in relative ordering, based on the
* value of the `priority` parameter.
*
* Writing is disabled on alternate backends.
*
* Read <odb_backends.h> for more information.
*
* @param odb database to add the backend to
* @param backend pointer to a git_odb_backend instance
* @param priority Value for ordering the backends queue
* @return 0 on success; error code otherwise
*/
GIT_EXTERN(int) git_odb_add_alternate(git_odb *odb, git_odb_backend *backend, int priority);
/**
* Get the number of ODB backend objects
*
* @param odb object database
* @return number of backends in the ODB
*/
GIT_EXTERN(size_t) git_odb_num_backends(git_odb *odb);
/**
* Lookup an ODB backend object by index
*
* @param out output pointer to ODB backend at pos
* @param odb object database
* @param pos index into object database backend list
* @return 0 on success; GIT_ENOTFOUND if pos is invalid; other errors < 0
*/
GIT_EXTERN(int) git_odb_get_backend(git_odb_backend **out, git_odb *odb, size_t pos);
/** @} */ /** @} */
GIT_END_DECL GIT_END_DECL
#endif #endif
...@@ -7,106 +7,24 @@ ...@@ -7,106 +7,24 @@
#ifndef INCLUDE_git_odb_backend_h__ #ifndef INCLUDE_git_odb_backend_h__
#define INCLUDE_git_odb_backend_h__ #define INCLUDE_git_odb_backend_h__
#include "common.h" #include "git2/common.h"
#include "types.h" #include "git2/types.h"
#include "oid.h"
#include "indexer.h"
/** /**
* @file git2/backend.h * @file git2/backend.h
* @brief Git custom backend functions * @brief Git custom backend functions
* @defgroup git_backend Git custom backend API * @defgroup git_odb Git object database routines
* @ingroup Git * @ingroup Git
* @{ * @{
*/ */
GIT_BEGIN_DECL GIT_BEGIN_DECL
struct git_odb_stream;
struct git_odb_writepack;
/**
* Function type for callbacks from git_odb_foreach.
*/
typedef int (*git_odb_foreach_cb)(const git_oid *id, void *payload);
/** /**
* An instance for a custom backend * Constructors for in-box ODB backends.
*/ */
struct git_odb_backend { GIT_EXTERN(int) git_odb_backend_pack(git_odb_backend **out, const char *objects_dir);
unsigned int version; GIT_EXTERN(int) git_odb_backend_loose(git_odb_backend **out, const char *objects_dir, int compression_level, int do_fsync);
git_odb *odb; GIT_EXTERN(int) git_odb_backend_one_pack(git_odb_backend **out, const char *index_file);
/* read and read_prefix each return to libgit2 a buffer which
* will be freed later. The buffer should be allocated using
* the function git_odb_backend_malloc to ensure that it can
* be safely freed later. */
int (* read)(
void **, size_t *, git_otype *,
struct git_odb_backend *,
const git_oid *);
/* To find a unique object given a prefix
* of its oid.
* The oid given must be so that the
* remaining (GIT_OID_HEXSZ - len)*4 bits
* are 0s.
*/
int (* read_prefix)(
git_oid *,
void **, size_t *, git_otype *,
struct git_odb_backend *,
const git_oid *,
size_t);
int (* read_header)(
size_t *, git_otype *,
struct git_odb_backend *,
const git_oid *);
/* The writer may assume that the object
* has already been hashed and is passed
* in the first parameter.
*/
int (* write)(
git_oid *,
struct git_odb_backend *,
const void *,
size_t,
git_otype);
int (* writestream)(
struct git_odb_stream **,
struct git_odb_backend *,
size_t,
git_otype);
int (* readstream)(
struct git_odb_stream **,
struct git_odb_backend *,
const git_oid *);
int (* exists)(
struct git_odb_backend *,
const git_oid *);
int (* refresh)(struct git_odb_backend *);
int (* foreach)(
struct git_odb_backend *,
git_odb_foreach_cb cb,
void *payload);
int (* writepack)(
struct git_odb_writepack **,
struct git_odb_backend *,
git_transfer_progress_callback progress_cb,
void *progress_payload);
void (* free)(struct git_odb_backend *);
};
#define GIT_ODB_BACKEND_VERSION 1
#define GIT_ODB_BACKEND_INIT {GIT_ODB_BACKEND_VERSION}
/** Streaming mode */ /** Streaming mode */
enum { enum {
...@@ -117,33 +35,24 @@ enum { ...@@ -117,33 +35,24 @@ enum {
/** A stream to read/write from a backend */ /** A stream to read/write from a backend */
struct git_odb_stream { struct git_odb_stream {
struct git_odb_backend *backend; git_odb_backend *backend;
unsigned int mode; unsigned int mode;
int (*read)(struct git_odb_stream *stream, char *buffer, size_t len); int (*read)(git_odb_stream *stream, char *buffer, size_t len);
int (*write)(struct git_odb_stream *stream, const char *buffer, size_t len); int (*write)(git_odb_stream *stream, const char *buffer, size_t len);
int (*finalize_write)(git_oid *oid_p, struct git_odb_stream *stream); int (*finalize_write)(git_oid *oid_p, git_odb_stream *stream);
void (*free)(struct git_odb_stream *stream); void (*free)(git_odb_stream *stream);
}; };
/** A stream to write a pack file to the ODB */ /** A stream to write a pack file to the ODB */
struct git_odb_writepack { struct git_odb_writepack {
struct git_odb_backend *backend; git_odb_backend *backend;
int (*add)(struct git_odb_writepack *writepack, const void *data, size_t size, git_transfer_progress *stats); int (*add)(git_odb_writepack *writepack, const void *data, size_t size, git_transfer_progress *stats);
int (*commit)(struct git_odb_writepack *writepack, git_transfer_progress *stats); int (*commit)(git_odb_writepack *writepack, git_transfer_progress *stats);
void (*free)(struct git_odb_writepack *writepack); void (*free)(git_odb_writepack *writepack);
}; };
GIT_EXTERN(void *) git_odb_backend_malloc(git_odb_backend *backend, size_t len);
/**
* Constructors for in-box ODB backends.
*/
GIT_EXTERN(int) git_odb_backend_pack(git_odb_backend **out, const char *objects_dir);
GIT_EXTERN(int) git_odb_backend_loose(git_odb_backend **out, const char *objects_dir, int compression_level, int do_fsync);
GIT_EXTERN(int) git_odb_backend_one_pack(git_odb_backend **out, const char *index_file);
GIT_END_DECL GIT_END_DECL
#endif #endif
...@@ -22,25 +22,6 @@ ...@@ -22,25 +22,6 @@
GIT_BEGIN_DECL GIT_BEGIN_DECL
/** /**
* Create a new reference. Either an oid or a symbolic target must be
* specified.
*
* @param refdb the reference database to associate with this reference
* @param name the reference name
* @param oid the object id for a direct reference
* @param symbolic the target for a symbolic reference
* @return the created git_reference or NULL on error
*/
GIT_EXTERN(git_reference *) git_reference__alloc(
const char *name,
const git_oid *oid,
const git_oid *peel);
GIT_EXTERN(git_reference *) git_reference__alloc_symbolic(
const char *name,
const char *target);
/**
* Create a new reference database with no backends. * Create a new reference database with no backends.
* *
* Before the Ref DB can be used for read/writing, a custom database * Before the Ref DB can be used for read/writing, a custom database
...@@ -81,20 +62,6 @@ GIT_EXTERN(int) git_refdb_compress(git_refdb *refdb); ...@@ -81,20 +62,6 @@ GIT_EXTERN(int) git_refdb_compress(git_refdb *refdb);
*/ */
GIT_EXTERN(void) git_refdb_free(git_refdb *refdb); GIT_EXTERN(void) git_refdb_free(git_refdb *refdb);
/**
* Sets the custom backend to an existing reference DB
*
* Read <refdb_backends.h> for more information.
*
* @param refdb database to add the backend to
* @param backend pointer to a git_refdb_backend instance
* @param priority Value for ordering the backends queue
* @return 0 on success; error code otherwise
*/
GIT_EXTERN(int) git_refdb_set_backend(
git_refdb *refdb,
git_refdb_backend *backend);
/** @} */ /** @} */
GIT_END_DECL GIT_END_DECL
......
...@@ -401,21 +401,6 @@ GIT_EXTERN(int) git_repository_is_bare(git_repository *repo); ...@@ -401,21 +401,6 @@ GIT_EXTERN(int) git_repository_is_bare(git_repository *repo);
GIT_EXTERN(int) git_repository_config(git_config **out, git_repository *repo); GIT_EXTERN(int) git_repository_config(git_config **out, git_repository *repo);
/** /**
* Set the configuration file for this repository
*
* This configuration file will be used for all configuration
* queries involving this repository.
*
* The repository will keep a reference to the config file;
* the user must still free the config after setting it
* to the repository, or it will leak.
*
* @param repo A repository object
* @param config A Config object
*/
GIT_EXTERN(void) git_repository_set_config(git_repository *repo, git_config *config);
/**
* Get the Object Database for this repository. * Get the Object Database for this repository.
* *
* If a custom ODB has not been set, the default * If a custom ODB has not been set, the default
...@@ -432,21 +417,6 @@ GIT_EXTERN(void) git_repository_set_config(git_repository *repo, git_config *con ...@@ -432,21 +417,6 @@ GIT_EXTERN(void) git_repository_set_config(git_repository *repo, git_config *con
GIT_EXTERN(int) git_repository_odb(git_odb **out, git_repository *repo); GIT_EXTERN(int) git_repository_odb(git_odb **out, git_repository *repo);
/** /**
* Set the Object Database for this repository
*
* The ODB will be used for all object-related operations
* involving this repository.
*
* The repository will keep a reference to the ODB; the user
* must still free the ODB object after setting it to the
* repository, or it will leak.
*
* @param repo A repository object
* @param odb An ODB object
*/
GIT_EXTERN(void) git_repository_set_odb(git_repository *repo, git_odb *odb);
/**
* Get the Reference Database Backend for this repository. * Get the Reference Database Backend for this repository.
* *
* If a custom refsdb has not been set, the default database for * If a custom refsdb has not been set, the default database for
...@@ -463,23 +433,6 @@ GIT_EXTERN(void) git_repository_set_odb(git_repository *repo, git_odb *odb); ...@@ -463,23 +433,6 @@ GIT_EXTERN(void) git_repository_set_odb(git_repository *repo, git_odb *odb);
GIT_EXTERN(int) git_repository_refdb(git_refdb **out, git_repository *repo); GIT_EXTERN(int) git_repository_refdb(git_refdb **out, git_repository *repo);
/** /**
* Set the Reference Database Backend for this repository
*
* The refdb will be used for all reference related operations
* involving this repository.
*
* The repository will keep a reference to the refdb; the user
* must still free the refdb object after setting it to the
* repository, or it will leak.
*
* @param repo A repository object
* @param refdb An refdb object
*/
GIT_EXTERN(void) git_repository_set_refdb(
git_repository *repo,
git_refdb *refdb);
/**
* Get the Index file for this repository. * Get the Index file for this repository.
* *
* If a custom index has not been set, the default * If a custom index has not been set, the default
...@@ -496,21 +449,6 @@ GIT_EXTERN(void) git_repository_set_refdb( ...@@ -496,21 +449,6 @@ GIT_EXTERN(void) git_repository_set_refdb(
GIT_EXTERN(int) git_repository_index(git_index **out, git_repository *repo); GIT_EXTERN(int) git_repository_index(git_index **out, git_repository *repo);
/** /**
* Set the index file for this repository
*
* This index will be used for all index-related operations
* involving this repository.
*
* The repository will keep a reference to the index file;
* the user must still free the index after setting it
* to the repository, or it will leak.
*
* @param repo A repository object
* @param index An index object
*/
GIT_EXTERN(void) git_repository_set_index(git_repository *repo, git_index *index);
/**
* Retrieve git's prepared message * Retrieve git's prepared message
* *
* Operations such as git revert/cherry-pick/merge with the -n option * Operations such as git revert/cherry-pick/merge with the -n option
......
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_sys_git_commit_h__
#define INCLUDE_sys_git_commit_h__
#include "git2/common.h"
#include "git2/types.h"
#include "git2/oid.h"
/**
* @file git2/sys/commit.h
* @brief Low-level Git commit creation
* @defgroup git_backend Git custom backend APIs
* @ingroup Git
* @{
*/
GIT_BEGIN_DECL
/**
* Create new commit in the repository from a list of `git_oid` values
*
* See documentation for `git_commit_create()` for information about the
* parameters, as the meaning is identical excepting that `tree` and
* `parents` now take `git_oid`. This is a dangerous API in that the
* `parents` list of `git_oid`s in not checked for validity.
*/
GIT_EXTERN(int) git_commit_create_from_oids(
git_oid *oid,
git_repository *repo,
const char *update_ref,
const git_signature *author,
const git_signature *committer,
const char *message_encoding,
const char *message,
const git_oid *tree,
int parent_count,
const git_oid *parents[]);
/** @} */
GIT_END_DECL
#endif
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_sys_git_config_backend_h__
#define INCLUDE_sys_git_config_backend_h__
#include "git2/common.h"
#include "git2/types.h"
#include "git2/config.h"
/**
* @file git2/sys/config.h
* @brief Git config backend routines
* @defgroup git_backend Git custom backend APIs
* @ingroup Git
* @{
*/
GIT_BEGIN_DECL
/**
* Generic backend that implements the interface to
* access a configuration file
*/
struct git_config_backend {
unsigned int version;
struct git_config *cfg;
/* Open means open the file/database and parse if necessary */
int (*open)(struct git_config_backend *, unsigned int level);
int (*get)(const struct git_config_backend *, const char *key, const git_config_entry **entry);
int (*get_multivar)(struct git_config_backend *, const char *key, const char *regexp, git_config_foreach_cb callback, void *payload);
int (*set)(struct git_config_backend *, const char *key, const char *value);
int (*set_multivar)(git_config_backend *cfg, const char *name, const char *regexp, const char *value);
int (*del)(struct git_config_backend *, const char *key);
int (*foreach)(struct git_config_backend *, const char *, git_config_foreach_cb callback, void *payload);
int (*refresh)(struct git_config_backend *);
void (*free)(struct git_config_backend *);
};
#define GIT_CONFIG_BACKEND_VERSION 1
#define GIT_CONFIG_BACKEND_INIT {GIT_CONFIG_BACKEND_VERSION}
/**
* Add a generic config file instance to an existing config
*
* Note that the configuration object will free the file
* automatically.
*
* Further queries on this config object will access each
* of the config file instances in order (instances with
* a higher priority level will be accessed first).
*
* @param cfg the configuration to add the file to
* @param file the configuration file (backend) to add
* @param level the priority level of the backend
* @param force if a config file already exists for the given
* priority level, replace it
* @return 0 on success, GIT_EEXISTS when adding more than one file
* for a given priority level (and force_replace set to 0), or error code
*/
GIT_EXTERN(int) git_config_add_backend(
git_config *cfg,
git_config_backend *file,
unsigned int level,
int force);
/** @} */
GIT_END_DECL
#endif
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_sys_git_odb_backend_h__
#define INCLUDE_sys_git_odb_backend_h__
#include "git2/common.h"
#include "git2/types.h"
#include "git2/oid.h"
#include "git2/odb.h"
/**
* @file git2/sys/backend.h
* @brief Git custom backend implementors functions
* @defgroup git_backend Git custom backend APIs
* @ingroup Git
* @{
*/
GIT_BEGIN_DECL
/**
* An instance for a custom backend
*/
struct git_odb_backend {
unsigned int version;
git_odb *odb;
/* read and read_prefix each return to libgit2 a buffer which
* will be freed later. The buffer should be allocated using
* the function git_odb_backend_malloc to ensure that it can
* be safely freed later. */
int (* read)(
void **, size_t *, git_otype *, git_odb_backend *, const git_oid *);
/* To find a unique object given a prefix
* of its oid.
* The oid given must be so that the
* remaining (GIT_OID_HEXSZ - len)*4 bits
* are 0s.
*/
int (* read_prefix)(
git_oid *, void **, size_t *, git_otype *,
git_odb_backend *, const git_oid *, size_t);
int (* read_header)(
size_t *, git_otype *, git_odb_backend *, const git_oid *);
/* The writer may assume that the object
* has already been hashed and is passed
* in the first parameter.
*/
int (* write)(
git_oid *, git_odb_backend *, const void *, size_t, git_otype);
int (* writestream)(
git_odb_stream **, git_odb_backend *, size_t, git_otype);
int (* readstream)(
git_odb_stream **, git_odb_backend *, const git_oid *);
int (* exists)(
git_odb_backend *, const git_oid *);
int (* refresh)(git_odb_backend *);
int (* foreach)(
git_odb_backend *, git_odb_foreach_cb cb, void *payload);
int (* writepack)(
git_odb_writepack **, git_odb_backend *,
git_transfer_progress_callback progress_cb, void *progress_payload);
void (* free)(git_odb_backend *);
};
#define GIT_ODB_BACKEND_VERSION 1
#define GIT_ODB_BACKEND_INIT {GIT_ODB_BACKEND_VERSION}
GIT_EXTERN(void *) git_odb_backend_malloc(git_odb_backend *backend, size_t len);
GIT_END_DECL
#endif
...@@ -4,12 +4,12 @@ ...@@ -4,12 +4,12 @@
* This file is part of libgit2, distributed under the GNU GPL v2 with * This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file. * a Linking Exception. For full terms see the included COPYING file.
*/ */
#ifndef INCLUDE_git_refdb_backend_h__ #ifndef INCLUDE_sys_git_refdb_backend_h__
#define INCLUDE_git_refdb_backend_h__ #define INCLUDE_sys_git_refdb_backend_h__
#include "common.h" #include "git2/common.h"
#include "types.h" #include "git2/types.h"
#include "oid.h" #include "git2/oid.h"
/** /**
* @file git2/refdb_backend.h * @file git2/refdb_backend.h
...@@ -30,7 +30,7 @@ struct git_refdb_backend { ...@@ -30,7 +30,7 @@ struct git_refdb_backend {
*/ */
int (*exists)( int (*exists)(
int *exists, int *exists,
struct git_refdb_backend *backend, git_refdb_backend *backend,
const char *ref_name); const char *ref_name);
/** /**
...@@ -39,7 +39,7 @@ struct git_refdb_backend { ...@@ -39,7 +39,7 @@ struct git_refdb_backend {
*/ */
int (*lookup)( int (*lookup)(
git_reference **out, git_reference **out,
struct git_refdb_backend *backend, git_refdb_backend *backend,
const char *ref_name); const char *ref_name);
/** /**
...@@ -47,7 +47,7 @@ struct git_refdb_backend { ...@@ -47,7 +47,7 @@ struct git_refdb_backend {
* provide this function. * provide this function.
*/ */
int (*foreach)( int (*foreach)(
struct git_refdb_backend *backend, git_refdb_backend *backend,
unsigned int list_flags, unsigned int list_flags,
git_reference_foreach_cb callback, git_reference_foreach_cb callback,
void *payload); void *payload);
...@@ -59,7 +59,7 @@ struct git_refdb_backend { ...@@ -59,7 +59,7 @@ struct git_refdb_backend {
* against the glob. * against the glob.
*/ */
int (*foreach_glob)( int (*foreach_glob)(
struct git_refdb_backend *backend, git_refdb_backend *backend,
const char *glob, const char *glob,
unsigned int list_flags, unsigned int list_flags,
git_reference_foreach_cb callback, git_reference_foreach_cb callback,
...@@ -69,13 +69,13 @@ struct git_refdb_backend { ...@@ -69,13 +69,13 @@ struct git_refdb_backend {
* Writes the given reference to the refdb. A refdb implementation * Writes the given reference to the refdb. A refdb implementation
* must provide this function. * must provide this function.
*/ */
int (*write)(struct git_refdb_backend *backend, const git_reference *ref); int (*write)(git_refdb_backend *backend, const git_reference *ref);
/** /**
* Deletes the given reference from the refdb. A refdb implementation * Deletes the given reference from the refdb. A refdb implementation
* must provide this function. * must provide this function.
*/ */
int (*delete)(struct git_refdb_backend *backend, const git_reference *ref); int (*delete)(git_refdb_backend *backend, const git_reference *ref);
/** /**
* Suggests that the given refdb compress or optimize its references. * Suggests that the given refdb compress or optimize its references.
...@@ -84,25 +84,47 @@ struct git_refdb_backend { ...@@ -84,25 +84,47 @@ struct git_refdb_backend {
* implementation may provide this function; if it is not provided, * implementation may provide this function; if it is not provided,
* nothing will be done. * nothing will be done.
*/ */
int (*compress)(struct git_refdb_backend *backend); int (*compress)(git_refdb_backend *backend);
/** /**
* Frees any resources held by the refdb. A refdb implementation may * Frees any resources held by the refdb. A refdb implementation may
* provide this function; if it is not provided, nothing will be done. * provide this function; if it is not provided, nothing will be done.
*/ */
void (*free)(struct git_refdb_backend *backend); void (*free)(git_refdb_backend *backend);
}; };
#define GIT_ODB_BACKEND_VERSION 1 #define GIT_ODB_BACKEND_VERSION 1
#define GIT_ODB_BACKEND_INIT {GIT_ODB_BACKEND_VERSION} #define GIT_ODB_BACKEND_INIT {GIT_ODB_BACKEND_VERSION}
/** /**
* Constructors for default refdb backends. * Constructors for default filesystem-based refdb backend
*
* Under normal usage, this is called for you when the repository is
* opened / created, but you can use this to explicitly construct a
* filesystem refdb backend for a repository.
*
* @param backend_out Output pointer to the git_refdb_backend object
* @param repo Git repository to access
* @return 0 on success, <0 error code on failure
*/ */
GIT_EXTERN(int) git_refdb_backend_fs( GIT_EXTERN(int) git_refdb_backend_fs(
struct git_refdb_backend **backend_out, git_refdb_backend **backend_out,
git_repository *repo); git_repository *repo);
/**
* Sets the custom backend to an existing reference DB
*
* The `git_refdb` will take ownership of the `git_refdb_backend` so you
* should NOT free it after calling this function.
*
* @param refdb database to add the backend to
* @param backend pointer to a git_refdb_backend instance
* @return 0 on success; error code otherwise
*/
GIT_EXTERN(int) git_refdb_set_backend(
git_refdb *refdb,
git_refdb_backend *backend);
GIT_END_DECL GIT_END_DECL
#endif #endif
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_sys_git_refdb_h__
#define INCLUDE_sys_git_refdb_h__
#include "git2/common.h"
#include "git2/types.h"
#include "git2/oid.h"
/**
* Create a new direct reference from an OID.
*
* @param name the reference name
* @param oid the object id for a direct reference
* @param symbolic the target for a symbolic reference
* @return the created git_reference or NULL on error
*/
GIT_EXTERN(git_reference *) git_reference__alloc(
const char *name,
const git_oid *oid,
const git_oid *peel);
/**
* Create a new symbolic reference.
*
* @param name the reference name
* @param symbolic the target for a symbolic reference
* @return the created git_reference or NULL on error
*/
GIT_EXTERN(git_reference *) git_reference__alloc_symbolic(
const char *name,
const char *target);
#endif
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_sys_git_repository_h__
#define INCLUDE_sys_git_repository_h__
/**
* @file git2/sys/repository.h
* @brief Git repository custom implementation routines
* @defgroup git_backend Git custom backend APIs
* @ingroup Git
* @{
*/
GIT_BEGIN_DECL
/**
* Create a new repository with neither backends nor config object
*
* Note that this is only useful if you wish to associate the repository
* with a non-filesystem-backed object database and config store.
*
* @param out The blank repository
* @return 0 on success, or an error code
*/
GIT_EXTERN(int) git_repository_new(git_repository **out);
/**
* Set the configuration file for this repository
*
* This configuration file will be used for all configuration
* queries involving this repository.
*
* The repository will keep a reference to the config file;
* the user must still free the config after setting it
* to the repository, or it will leak.
*
* @param repo A repository object
* @param config A Config object
*/
GIT_EXTERN(void) git_repository_set_config(git_repository *repo, git_config *config);
/**
* Set the Object Database for this repository
*
* The ODB will be used for all object-related operations
* involving this repository.
*
* The repository will keep a reference to the ODB; the user
* must still free the ODB object after setting it to the
* repository, or it will leak.
*
* @param repo A repository object
* @param odb An ODB object
*/
GIT_EXTERN(void) git_repository_set_odb(git_repository *repo, git_odb *odb);
/**
* Set the Reference Database Backend for this repository
*
* The refdb will be used for all reference related operations
* involving this repository.
*
* The repository will keep a reference to the refdb; the user
* must still free the refdb object after setting it to the
* repository, or it will leak.
*
* @param repo A repository object
* @param refdb An refdb object
*/
GIT_EXTERN(void) git_repository_set_refdb(git_repository *repo, git_refdb *refdb);
/**
* Set the index file for this repository
*
* This index will be used for all index-related operations
* involving this repository.
*
* The repository will keep a reference to the index file;
* the user must still free the index after setting it
* to the repository, or it will leak.
*
* @param repo A repository object
* @param index An index object
*/
GIT_EXTERN(void) git_repository_set_index(git_repository *repo, git_index *index);
/** @} */
GIT_END_DECL
#endif
...@@ -196,6 +196,26 @@ typedef struct git_push git_push; ...@@ -196,6 +196,26 @@ typedef struct git_push git_push;
typedef struct git_remote_head git_remote_head; typedef struct git_remote_head git_remote_head;
typedef struct git_remote_callbacks git_remote_callbacks; typedef struct git_remote_callbacks git_remote_callbacks;
/**
* This is passed as the first argument to the callback to allow the
* user to see the progress.
*/
typedef struct git_transfer_progress {
unsigned int total_objects;
unsigned int indexed_objects;
unsigned int received_objects;
size_t received_bytes;
} git_transfer_progress;
/**
* Type for progress callbacks during indexing. Return a value less than zero
* to cancel the transfer.
*
* @param stats Structure containing information about the state of the transfer
* @param payload Payload provided by caller
*/
typedef int (*git_transfer_progress_callback)(const git_transfer_progress *stats, void *payload);
/** @} */ /** @} */
GIT_END_DECL GIT_END_DECL
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "git2/common.h" #include "git2/common.h"
#include "git2/object.h" #include "git2/object.h"
#include "git2/repository.h" #include "git2/repository.h"
#include "git2/odb_backend.h"
#include "common.h" #include "common.h"
#include "blob.h" #include "blob.h"
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "git2/object.h" #include "git2/object.h"
#include "git2/repository.h" #include "git2/repository.h"
#include "git2/signature.h" #include "git2/signature.h"
#include "git2/sys/commit.h"
#include "common.h" #include "common.h"
#include "odb.h" #include "odb.h"
...@@ -44,16 +45,16 @@ void git_commit__free(git_commit *commit) ...@@ -44,16 +45,16 @@ void git_commit__free(git_commit *commit)
} }
int git_commit_create_v( int git_commit_create_v(
git_oid *oid, git_oid *oid,
git_repository *repo, git_repository *repo,
const char *update_ref, const char *update_ref,
const git_signature *author, const git_signature *author,
const git_signature *committer, const git_signature *committer,
const char *message_encoding, const char *message_encoding,
const char *message, const char *message,
const git_tree *tree, const git_tree *tree,
int parent_count, int parent_count,
...) ...)
{ {
va_list ap; va_list ap;
int i, res; int i, res;
...@@ -76,30 +77,29 @@ int git_commit_create_v( ...@@ -76,30 +77,29 @@ int git_commit_create_v(
return res; return res;
} }
int git_commit_create( int git_commit_create_from_oids(
git_oid *oid, git_oid *oid,
git_repository *repo, git_repository *repo,
const char *update_ref, const char *update_ref,
const git_signature *author, const git_signature *author,
const git_signature *committer, const git_signature *committer,
const char *message_encoding, const char *message_encoding,
const char *message, const char *message,
const git_tree *tree, const git_oid *tree,
int parent_count, int parent_count,
const git_commit *parents[]) const git_oid *parents[])
{ {
git_buf commit = GIT_BUF_INIT; git_buf commit = GIT_BUF_INIT;
int i; int i;
git_odb *odb; git_odb *odb;
assert(oid && repo && tree && parent_count >= 0);
assert(git_object_owner((const git_object *)tree) == repo); assert(git_object_owner((const git_object *)tree) == repo);
git_oid__writebuf(&commit, "tree ", git_object_id((const git_object *)tree)); git_oid__writebuf(&commit, "tree ", tree);
for (i = 0; i < parent_count; ++i) { for (i = 0; i < parent_count; ++i)
assert(git_object_owner((const git_object *)parents[i]) == repo); git_oid__writebuf(&commit, "parent ", parents[i]);
git_oid__writebuf(&commit, "parent ", git_object_id((const git_object *)parents[i]));
}
git_signature__writebuf(&commit, "author ", author); git_signature__writebuf(&commit, "author ", author);
git_signature__writebuf(&commit, "committer ", committer); git_signature__writebuf(&commit, "committer ", committer);
...@@ -131,6 +131,41 @@ on_error: ...@@ -131,6 +131,41 @@ on_error:
return -1; return -1;
} }
int git_commit_create(
git_oid *oid,
git_repository *repo,
const char *update_ref,
const git_signature *author,
const git_signature *committer,
const char *message_encoding,
const char *message,
const git_tree *tree,
int parent_count,
const git_commit *parents[])
{
int retval, i;
const git_oid **parent_oids;
assert(parent_count >= 0);
parent_oids = git__malloc(parent_count * sizeof(git_oid *));
GITERR_CHECK_ALLOC(parent_oids);
for (i = 0; i < parent_count; ++i) {
assert(git_object_owner((const git_object *)parents[i]) == repo);
parent_oids[i] = git_object_id((const git_object *)parents[i]);
}
retval = git_commit_create_from_oids(
oid, repo, update_ref, author, committer,
message_encoding, message,
git_object_id((const git_object *)tree), parent_count, parent_oids);
git__free((void *)parent_oids);
return retval;
}
int git_commit__parse_buffer(git_commit *commit, const void *data, size_t len) int git_commit__parse_buffer(git_commit *commit, const void *data, size_t len)
{ {
const char *buffer = data; const char *buffer = data;
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "fileops.h" #include "fileops.h"
#include "config.h" #include "config.h"
#include "git2/config.h" #include "git2/config.h"
#include "git2/sys/config.h"
#include "vector.h" #include "vector.h"
#include "buf_text.h" #include "buf_text.h"
#include "config_file.h" #include "config_file.h"
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "buffer.h" #include "buffer.h"
#include "buf_text.h" #include "buf_text.h"
#include "git2/config.h" #include "git2/config.h"
#include "git2/sys/config.h"
#include "git2/types.h" #include "git2/types.h"
#include "strmap.h" #include "strmap.h"
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "common.h" #include "common.h"
#include <zlib.h> #include <zlib.h>
#include "git2/object.h" #include "git2/object.h"
#include "git2/sys/odb_backend.h"
#include "fileops.h" #include "fileops.h"
#include "hash.h" #include "hash.h"
#include "odb.h" #include "odb.h"
...@@ -403,6 +404,27 @@ int git_odb_add_alternate(git_odb *odb, git_odb_backend *backend, int priority) ...@@ -403,6 +404,27 @@ int git_odb_add_alternate(git_odb *odb, git_odb_backend *backend, int priority)
return add_backend_internal(odb, backend, priority, 1); return add_backend_internal(odb, backend, priority, 1);
} }
size_t git_odb_num_backends(git_odb *odb)
{
assert(odb);
return odb->backends.length;
}
int git_odb_get_backend(git_odb_backend **out, git_odb *odb, size_t pos)
{
backend_internal *internal;
assert(odb && odb);
internal = git_vector_get(&odb->backends, pos);
if (internal && internal->backend) {
*out = internal->backend;
return 0;
}
return GIT_ENOTFOUND;
}
static int add_default_backends(git_odb *db, const char *objects_dir, int as_alternates, int alternate_depth) static int add_default_backends(git_odb *db, const char *objects_dir, int as_alternates, int alternate_depth)
{ {
git_odb_backend *loose, *packed; git_odb_backend *loose, *packed;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include "common.h" #include "common.h"
#include <zlib.h> #include <zlib.h>
#include "git2/object.h" #include "git2/object.h"
#include "git2/oid.h" #include "git2/sys/odb_backend.h"
#include "fileops.h" #include "fileops.h"
#include "hash.h" #include "hash.h"
#include "odb.h" #include "odb.h"
......
...@@ -8,7 +8,8 @@ ...@@ -8,7 +8,8 @@
#include "common.h" #include "common.h"
#include <zlib.h> #include <zlib.h>
#include "git2/repository.h" #include "git2/repository.h"
#include "git2/oid.h" #include "git2/indexer.h"
#include "git2/sys/odb_backend.h"
#include "fileops.h" #include "fileops.h"
#include "hash.h" #include "hash.h"
#include "odb.h" #include "odb.h"
......
...@@ -7,15 +7,16 @@ ...@@ -7,15 +7,16 @@
#include "common.h" #include "common.h"
#include "posix.h" #include "posix.h"
#include "git2/object.h" #include "git2/object.h"
#include "git2/refs.h" #include "git2/refs.h"
#include "git2/refdb.h" #include "git2/refdb.h"
#include "git2/sys/refdb_backend.h"
#include "hash.h" #include "hash.h"
#include "refdb.h" #include "refdb.h"
#include "refs.h" #include "refs.h"
#include "git2/refdb_backend.h"
int git_refdb_new(git_refdb **out, git_repository *repo) int git_refdb_new(git_refdb **out, git_repository *repo)
{ {
git_refdb *db; git_refdb *db;
...@@ -57,15 +58,19 @@ int git_refdb_open(git_refdb **out, git_repository *repo) ...@@ -57,15 +58,19 @@ int git_refdb_open(git_refdb **out, git_repository *repo)
return 0; return 0;
} }
int git_refdb_set_backend(git_refdb *db, git_refdb_backend *backend) static void refdb_free_backend(git_refdb *db)
{ {
if (db->backend) { if (db->backend) {
if(db->backend->free) if (db->backend->free)
db->backend->free(db->backend); db->backend->free(db->backend);
else else
git__free(db->backend); git__free(db->backend);
} }
}
int git_refdb_set_backend(git_refdb *db, git_refdb_backend *backend)
{
refdb_free_backend(db);
db->backend = backend; db->backend = backend;
return 0; return 0;
...@@ -74,23 +79,16 @@ int git_refdb_set_backend(git_refdb *db, git_refdb_backend *backend) ...@@ -74,23 +79,16 @@ int git_refdb_set_backend(git_refdb *db, git_refdb_backend *backend)
int git_refdb_compress(git_refdb *db) int git_refdb_compress(git_refdb *db)
{ {
assert(db); assert(db);
if (db->backend->compress) { if (db->backend->compress)
return db->backend->compress(db->backend); return db->backend->compress(db->backend);
}
return 0; return 0;
} }
static void refdb_free(git_refdb *db) static void refdb_free(git_refdb *db)
{ {
if (db->backend) { refdb_free_backend(db);
if(db->backend->free)
db->backend->free(db->backend);
else
git__free(db->backend);
}
git__free(db); git__free(db);
} }
...@@ -114,14 +112,13 @@ int git_refdb_lookup(git_reference **out, git_refdb *db, const char *ref_name) ...@@ -114,14 +112,13 @@ int git_refdb_lookup(git_reference **out, git_refdb *db, const char *ref_name)
git_reference *ref; git_reference *ref;
int error; int error;
assert(db && db->backend && ref_name); assert(db && db->backend && out && ref_name);
*out = NULL;
if ((error = db->backend->lookup(&ref, db->backend, ref_name)) == 0) if (!(error = db->backend->lookup(&ref, db->backend, ref_name))) {
{
ref->db = db; ref->db = db;
*out = ref; *out = ref;
} else {
*out = NULL;
} }
return error; return error;
......
...@@ -41,6 +41,6 @@ int git_refdb_foreach_glob( ...@@ -41,6 +41,6 @@ int git_refdb_foreach_glob(
int git_refdb_write(git_refdb *refdb, const git_reference *ref); int git_refdb_write(git_refdb *refdb, const git_reference *ref);
int git_refdb_delete(struct git_refdb *refdb, const git_reference *ref); int git_refdb_delete(git_refdb *refdb, const git_reference *ref);
#endif #endif
...@@ -18,7 +18,8 @@ ...@@ -18,7 +18,8 @@
#include <git2/tag.h> #include <git2/tag.h>
#include <git2/object.h> #include <git2/object.h>
#include <git2/refdb.h> #include <git2/refdb.h>
#include <git2/refdb_backend.h> #include <git2/sys/refdb_backend.h>
#include <git2/sys/refs.h>
GIT__USE_STRMAP; GIT__USE_STRMAP;
...@@ -61,7 +62,7 @@ static int reference_read( ...@@ -61,7 +62,7 @@ static int reference_read(
/* Determine the full path of the file */ /* Determine the full path of the file */
if (git_buf_joinpath(&path, repo_path, ref_name) < 0) if (git_buf_joinpath(&path, repo_path, ref_name) < 0)
return -1; return -1;
result = git_futils_readbuffer_updated(file_content, path.ptr, mtime, NULL, updated); result = git_futils_readbuffer_updated(file_content, path.ptr, mtime, NULL, updated);
git_buf_free(&path); git_buf_free(&path);
...@@ -174,7 +175,7 @@ static int packed_load(refdb_fs_backend *backend) ...@@ -174,7 +175,7 @@ static int packed_load(refdb_fs_backend *backend)
ref_cache->packfile = git_strmap_alloc(); ref_cache->packfile = git_strmap_alloc();
GITERR_CHECK_ALLOC(ref_cache->packfile); GITERR_CHECK_ALLOC(ref_cache->packfile);
} }
result = reference_read(&packfile, &ref_cache->packfile_time, result = reference_read(&packfile, &ref_cache->packfile_time,
backend->path, GIT_PACKEDREFS_FILE, &updated); backend->path, GIT_PACKEDREFS_FILE, &updated);
...@@ -192,7 +193,7 @@ static int packed_load(refdb_fs_backend *backend) ...@@ -192,7 +193,7 @@ static int packed_load(refdb_fs_backend *backend)
if (result < 0) if (result < 0)
return -1; return -1;
if (!updated) if (!updated)
return 0; return 0;
...@@ -433,7 +434,7 @@ static int loose_lookup( ...@@ -433,7 +434,7 @@ static int loose_lookup(
} else { } else {
if ((error = loose_parse_oid(&oid, &ref_file)) < 0) if ((error = loose_parse_oid(&oid, &ref_file)) < 0)
goto done; goto done;
*out = git_reference__alloc(ref_name, &oid, NULL); *out = git_reference__alloc(ref_name, &oid, NULL);
} }
...@@ -455,19 +456,19 @@ static int packed_map_entry( ...@@ -455,19 +456,19 @@ static int packed_map_entry(
if (packed_load(backend) < 0) if (packed_load(backend) < 0)
return -1; return -1;
/* Look up on the packfile */ /* Look up on the packfile */
packfile_refs = backend->refcache.packfile; packfile_refs = backend->refcache.packfile;
*pos = git_strmap_lookup_index(packfile_refs, ref_name); *pos = git_strmap_lookup_index(packfile_refs, ref_name);
if (!git_strmap_valid_index(packfile_refs, *pos)) { if (!git_strmap_valid_index(packfile_refs, *pos)) {
giterr_set(GITERR_REFERENCE, "Reference '%s' not found", ref_name); giterr_set(GITERR_REFERENCE, "Reference '%s' not found", ref_name);
return GIT_ENOTFOUND; return GIT_ENOTFOUND;
} }
*entry = git_strmap_value_at(packfile_refs, *pos); *entry = git_strmap_value_at(packfile_refs, *pos);
return 0; return 0;
} }
...@@ -479,14 +480,14 @@ static int packed_lookup( ...@@ -479,14 +480,14 @@ static int packed_lookup(
struct packref *entry; struct packref *entry;
khiter_t pos; khiter_t pos;
int error = 0; int error = 0;
if ((error = packed_map_entry(&entry, &pos, backend, ref_name)) < 0) if ((error = packed_map_entry(&entry, &pos, backend, ref_name)) < 0)
return error; return error;
if ((*out = git_reference__alloc(ref_name, if ((*out = git_reference__alloc(ref_name,
&entry->oid, &entry->peel)) == NULL) &entry->oid, &entry->peel)) == NULL)
return -1; return -1;
return 0; return 0;
} }
...@@ -582,7 +583,7 @@ static int refdb_fs_backend__foreach( ...@@ -582,7 +583,7 @@ static int refdb_fs_backend__foreach(
git_buf refs_path = GIT_BUF_INIT; git_buf refs_path = GIT_BUF_INIT;
const char *ref_name; const char *ref_name;
void *ref = NULL; void *ref = NULL;
GIT_UNUSED(ref); GIT_UNUSED(ref);
assert(_backend); assert(_backend);
...@@ -590,7 +591,7 @@ static int refdb_fs_backend__foreach( ...@@ -590,7 +591,7 @@ static int refdb_fs_backend__foreach(
if (packed_load(backend) < 0) if (packed_load(backend) < 0)
return -1; return -1;
/* list all the packed references first */ /* list all the packed references first */
if (list_type & GIT_REF_OID) { if (list_type & GIT_REF_OID) {
git_strmap_foreach(backend->refcache.packfile, ref_name, ref, { git_strmap_foreach(backend->refcache.packfile, ref_name, ref, {
...@@ -924,7 +925,7 @@ static int refdb_fs_backend__delete( ...@@ -924,7 +925,7 @@ static int refdb_fs_backend__delete(
repo = backend->repo; repo = backend->repo;
/* If a loose reference exists, remove it from the filesystem */ /* If a loose reference exists, remove it from the filesystem */
if (git_buf_joinpath(&loose_path, repo->path_repository, ref->name) < 0) if (git_buf_joinpath(&loose_path, repo->path_repository, ref->name) < 0)
return -1; return -1;
...@@ -932,7 +933,7 @@ static int refdb_fs_backend__delete( ...@@ -932,7 +933,7 @@ static int refdb_fs_backend__delete(
error = p_unlink(loose_path.ptr); error = p_unlink(loose_path.ptr);
loose_deleted = 1; loose_deleted = 1;
} }
git_buf_free(&loose_path); git_buf_free(&loose_path);
if (error != 0) if (error != 0)
...@@ -946,7 +947,7 @@ static int refdb_fs_backend__delete( ...@@ -946,7 +947,7 @@ static int refdb_fs_backend__delete(
error = packed_write(backend); error = packed_write(backend);
} }
if (pack_error == GIT_ENOTFOUND) if (pack_error == GIT_ENOTFOUND)
error = loose_deleted ? 0 : GIT_ENOTFOUND; error = loose_deleted ? 0 : GIT_ENOTFOUND;
else else
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#include <git2/branch.h> #include <git2/branch.h>
#include <git2/refs.h> #include <git2/refs.h>
#include <git2/refdb.h> #include <git2/refdb.h>
#include <git2/refdb_backend.h> #include <git2/sys/refs.h>
GIT__USE_STRMAP; GIT__USE_STRMAP;
...@@ -45,8 +45,7 @@ static git_reference *alloc_ref(const char *name) ...@@ -45,8 +45,7 @@ static git_reference *alloc_ref(const char *name)
} }
git_reference *git_reference__alloc_symbolic( git_reference *git_reference__alloc_symbolic(
const char *name, const char *name, const char *target)
const char *target)
{ {
git_reference *ref; git_reference *ref;
...@@ -255,10 +254,10 @@ int git_reference_lookup_resolved( ...@@ -255,10 +254,10 @@ int git_reference_lookup_resolved(
max_nesting = MAX_NESTING_LEVEL; max_nesting = MAX_NESTING_LEVEL;
else if (max_nesting < 0) else if (max_nesting < 0)
max_nesting = DEFAULT_NESTING_LEVEL; max_nesting = DEFAULT_NESTING_LEVEL;
strncpy(scan_name, name, GIT_REFNAME_MAX); strncpy(scan_name, name, GIT_REFNAME_MAX);
scan_type = GIT_REF_SYMBOLIC; scan_type = GIT_REF_SYMBOLIC;
if ((error = git_repository_refdb__weakptr(&refdb, repo)) < 0) if ((error = git_repository_refdb__weakptr(&refdb, repo)) < 0)
return -1; return -1;
...@@ -276,7 +275,7 @@ int git_reference_lookup_resolved( ...@@ -276,7 +275,7 @@ int git_reference_lookup_resolved(
if ((error = git_refdb_lookup(&ref, refdb, scan_name)) < 0) if ((error = git_refdb_lookup(&ref, refdb, scan_name)) < 0)
return error; return error;
scan_type = ref->type; scan_type = ref->type;
} }
...@@ -354,7 +353,7 @@ static int reference__create( ...@@ -354,7 +353,7 @@ static int reference__create(
git_refdb *refdb; git_refdb *refdb;
git_reference *ref = NULL; git_reference *ref = NULL;
int error = 0; int error = 0;
if (ref_out) if (ref_out)
*ref_out = NULL; *ref_out = NULL;
...@@ -369,7 +368,7 @@ static int reference__create( ...@@ -369,7 +368,7 @@ static int reference__create(
} else { } else {
ref = git_reference__alloc_symbolic(name, symbolic); ref = git_reference__alloc_symbolic(name, symbolic);
} }
GITERR_CHECK_ALLOC(ref); GITERR_CHECK_ALLOC(ref);
ref->db = refdb; ref->db = refdb;
...@@ -377,7 +376,7 @@ static int reference__create( ...@@ -377,7 +376,7 @@ static int reference__create(
git_reference_free(ref); git_reference_free(ref);
return error; return error;
} }
if (ref_out == NULL) if (ref_out == NULL)
git_reference_free(ref); git_reference_free(ref);
else else
...@@ -397,17 +396,17 @@ int git_reference_create( ...@@ -397,17 +396,17 @@ int git_reference_create(
int error = 0; int error = 0;
assert(repo && name && oid); assert(repo && name && oid);
/* Sanity check the reference being created - target must exist. */ /* Sanity check the reference being created - target must exist. */
if ((error = git_repository_odb__weakptr(&odb, repo)) < 0) if ((error = git_repository_odb__weakptr(&odb, repo)) < 0)
return error; return error;
if (!git_odb_exists(odb, oid)) { if (!git_odb_exists(odb, oid)) {
giterr_set(GITERR_REFERENCE, giterr_set(GITERR_REFERENCE,
"Target OID for the reference doesn't exist on the repository"); "Target OID for the reference doesn't exist on the repository");
return -1; return -1;
} }
return reference__create(ref_out, repo, name, oid, NULL, force); return reference__create(ref_out, repo, name, oid, NULL, force);
} }
...@@ -422,7 +421,7 @@ int git_reference_symbolic_create( ...@@ -422,7 +421,7 @@ int git_reference_symbolic_create(
int error = 0; int error = 0;
assert(repo && name && target); assert(repo && name && target);
if ((error = git_reference__normalize_name_lax( if ((error = git_reference__normalize_name_lax(
normalized, sizeof(normalized), target)) < 0) normalized, sizeof(normalized), target)) < 0)
return error; return error;
...@@ -436,7 +435,7 @@ int git_reference_set_target( ...@@ -436,7 +435,7 @@ int git_reference_set_target(
const git_oid *id) const git_oid *id)
{ {
assert(out && ref && id); assert(out && ref && id);
if (ref->type != GIT_REF_OID) { if (ref->type != GIT_REF_OID) {
giterr_set(GITERR_REFERENCE, "Cannot set OID on symbolic reference"); giterr_set(GITERR_REFERENCE, "Cannot set OID on symbolic reference");
return -1; return -1;
...@@ -451,13 +450,13 @@ int git_reference_symbolic_set_target( ...@@ -451,13 +450,13 @@ int git_reference_symbolic_set_target(
const char *target) const char *target)
{ {
assert(out && ref && target); assert(out && ref && target);
if (ref->type != GIT_REF_SYMBOLIC) { if (ref->type != GIT_REF_SYMBOLIC) {
giterr_set(GITERR_REFERENCE, giterr_set(GITERR_REFERENCE,
"Cannot set symbolic target on a direct reference"); "Cannot set symbolic target on a direct reference");
return -1; return -1;
} }
return git_reference_symbolic_create(out, ref->db->repo, ref->name, target, 1); return git_reference_symbolic_create(out, ref->db->repo, ref->name, target, 1);
} }
...@@ -473,7 +472,7 @@ int git_reference_rename( ...@@ -473,7 +472,7 @@ int git_reference_rename(
git_reference *result = NULL; git_reference *result = NULL;
int error = 0; int error = 0;
int reference_has_log; int reference_has_log;
*out = NULL; *out = NULL;
normalization_flags = ref->type == GIT_REF_SYMBOLIC ? normalization_flags = ref->type == GIT_REF_SYMBOLIC ?
...@@ -488,7 +487,7 @@ int git_reference_rename( ...@@ -488,7 +487,7 @@ int git_reference_rename(
* Create the new reference. * Create the new reference.
*/ */
if (ref->type == GIT_REF_OID) { if (ref->type == GIT_REF_OID) {
result = git_reference__alloc(new_name, &ref->target.oid, &ref->peel); result = git_reference__alloc(new_name, &ref->target.oid, &ref->peel);
} else if (ref->type == GIT_REF_SYMBOLIC) { } else if (ref->type == GIT_REF_SYMBOLIC) {
result = git_reference__alloc_symbolic(new_name, ref->target.symbolic); result = git_reference__alloc_symbolic(new_name, ref->target.symbolic);
} else { } else {
...@@ -509,11 +508,11 @@ int git_reference_rename( ...@@ -509,11 +508,11 @@ int git_reference_rename(
/* Now delete the old ref and save the new one. */ /* Now delete the old ref and save the new one. */
if ((error = git_refdb_delete(ref->db, ref)) < 0) if ((error = git_refdb_delete(ref->db, ref)) < 0)
goto on_error; goto on_error;
/* Save the new reference. */ /* Save the new reference. */
if ((error = git_refdb_write(ref->db, result)) < 0) if ((error = git_refdb_write(ref->db, result)) < 0)
goto rollback; goto rollback;
/* Update HEAD it was poiting to the reference being renamed. */ /* Update HEAD it was poiting to the reference being renamed. */
if (should_head_be_updated && (error = git_repository_set_head(ref->db->repo, new_name)) < 0) { if (should_head_be_updated && (error = git_repository_set_head(ref->db->repo, new_name)) < 0) {
giterr_set(GITERR_REFERENCE, "Failed to update HEAD after renaming reference"); giterr_set(GITERR_REFERENCE, "Failed to update HEAD after renaming reference");
...@@ -547,7 +546,7 @@ int git_reference_resolve(git_reference **ref_out, const git_reference *ref) ...@@ -547,7 +546,7 @@ int git_reference_resolve(git_reference **ref_out, const git_reference *ref)
switch (git_reference_type(ref)) { switch (git_reference_type(ref)) {
case GIT_REF_OID: case GIT_REF_OID:
return git_reference_lookup(ref_out, ref->db->repo, ref->name); return git_reference_lookup(ref_out, ref->db->repo, ref->name);
case GIT_REF_SYMBOLIC: case GIT_REF_SYMBOLIC:
return git_reference_lookup_resolved(ref_out, ref->db->repo, ref->target.symbolic, -1); return git_reference_lookup_resolved(ref_out, ref->db->repo, ref->target.symbolic, -1);
...@@ -846,7 +845,7 @@ static int reference__update_terminal( ...@@ -846,7 +845,7 @@ static int reference__update_terminal(
if (nesting > MAX_NESTING_LEVEL) if (nesting > MAX_NESTING_LEVEL)
return GIT_ENOTFOUND; return GIT_ENOTFOUND;
error = git_reference_lookup(&ref, repo, ref_name); error = git_reference_lookup(&ref, repo, ref_name);
/* If we haven't found the reference at all, create a new reference. */ /* If we haven't found the reference at all, create a new reference. */
...@@ -854,10 +853,10 @@ static int reference__update_terminal( ...@@ -854,10 +853,10 @@ static int reference__update_terminal(
giterr_clear(); giterr_clear();
return git_reference_create(NULL, repo, ref_name, oid, 0); return git_reference_create(NULL, repo, ref_name, oid, 0);
} }
if (error < 0) if (error < 0)
return error; return error;
/* If the ref is a symbolic reference, follow its target. */ /* If the ref is a symbolic reference, follow its target. */
if (git_reference_type(ref) == GIT_REF_SYMBOLIC) { if (git_reference_type(ref) == GIT_REF_SYMBOLIC) {
error = reference__update_terminal(repo, git_reference_symbolic_target(ref), oid, error = reference__update_terminal(repo, git_reference_symbolic_target(ref), oid,
...@@ -867,7 +866,7 @@ static int reference__update_terminal( ...@@ -867,7 +866,7 @@ static int reference__update_terminal(
git_reference_free(ref); git_reference_free(ref);
error = git_reference_create(NULL, repo, ref_name, oid, 1); error = git_reference_create(NULL, repo, ref_name, oid, 1);
} }
return error; return error;
} }
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "git2/object.h" #include "git2/object.h"
#include "git2/refdb.h" #include "git2/refdb.h"
#include "git2/sys/repository.h"
#include "common.h" #include "common.h"
#include "repository.h" #include "repository.h"
...@@ -129,6 +130,12 @@ static git_repository *repository_alloc(void) ...@@ -129,6 +130,12 @@ static git_repository *repository_alloc(void)
return repo; return repo;
} }
int git_repository_new(git_repository **out)
{
*out = repository_alloc();
return 0;
}
static int load_config_data(git_repository *repo) static int load_config_data(git_repository *repo)
{ {
int is_bare; int is_bare;
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "common.h" #include "common.h"
#include "git2/config.h" #include "git2/config.h"
#include "git2/sys/config.h"
#include "git2/types.h" #include "git2/types.h"
#include "git2/repository.h" #include "git2/repository.h"
#include "git2/index.h" #include "git2/index.h"
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "git2/object.h" #include "git2/object.h"
#include "git2/repository.h" #include "git2/repository.h"
#include "git2/signature.h" #include "git2/signature.h"
#include "git2/odb_backend.h"
void git_tag__free(git_tag *tag) void git_tag__free(git_tag *tag)
{ {
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
* a Linking Exception. For full terms see the included COPYING file. * a Linking Exception. For full terms see the included COPYING file.
*/ */
#include "git2.h" #include "git2.h"
#include "git2/odb_backend.h"
#include "smart.h" #include "smart.h"
#include "refs.h" #include "refs.h"
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#ifndef INCLUDE_util_h__ #ifndef INCLUDE_util_h__
#define INCLUDE_util_h__ #define INCLUDE_util_h__
#include "common.h"
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0])) #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
#define bitsizeof(x) (CHAR_BIT * sizeof(x)) #define bitsizeof(x) (CHAR_BIT * sizeof(x))
#define MSB(x, bits) ((x) & (~0ULL << (bitsizeof(x) - (bits)))) #define MSB(x, bits) ((x) & (~0ULL << (bitsizeof(x) - (bits))))
......
#include "clar_libgit2.h" #include "clar_libgit2.h"
#include "git2/sys/config.h"
void test_config_backend__checks_version(void) void test_config_backend__checks_version(void)
{ {
......
#include "clar_libgit2.h" #include "clar_libgit2.h"
#include "git2/sys/repository.h"
#include "diff_helpers.h" #include "diff_helpers.h"
#include "repository.h" #include "repository.h"
#include "buf_text.h" #include "buf_text.h"
......
#include "clar_libgit2.h" #include "clar_libgit2.h"
#include "git2/odb_backend.h"
#include "fileops.h" #include "fileops.h"
#include "odb.h" #include "odb.h"
......
#include "clar_libgit2.h" #include "clar_libgit2.h"
#include "odb.h" #include "git2/odb_backend.h"
#include "pack_data_one.h" #include "pack_data_one.h"
#include "pack.h" #include "pack.h"
......
#include "clar_libgit2.h" #include "clar_libgit2.h"
#include "git2/odb_backend.h" #include "git2/sys/odb_backend.h"
#include "odb.h"
typedef struct { typedef struct {
git_odb_backend base; git_odb_backend base;
int position; size_t position;
} fake_backend; } fake_backend;
static git_odb_backend *new_backend(int position) static git_odb_backend *new_backend(size_t position)
{ {
fake_backend *b; fake_backend *b;
...@@ -22,14 +21,13 @@ static git_odb_backend *new_backend(int position) ...@@ -22,14 +21,13 @@ static git_odb_backend *new_backend(int position)
static void check_backend_sorting(git_odb *odb) static void check_backend_sorting(git_odb *odb)
{ {
unsigned int i; size_t i, max_i = git_odb_num_backends(odb);
fake_backend *internal;
for (i = 0; i < odb->backends.length; ++i) {
fake_backend *internal =
*((fake_backend **)git_vector_get(&odb->backends, i));
for (i = 0; i < max_i; ++i) {
cl_git_pass(git_odb_get_backend((git_odb_backend **)&internal, odb, i));
cl_assert(internal != NULL); cl_assert(internal != NULL);
cl_assert(internal->position == (int)i); cl_assert_equal_sz(i, internal->position);
} }
} }
......
#include "clar_libgit2.h" #include "clar_libgit2.h"
#include "refdb.h"
#include "repository.h" #include "buffer.h"
#include "posix.h"
#include "path.h"
#include "refs.h"
#include "testdb.h" #include "testdb.h"
#define TEST_REPO_PATH "testrepo" #define TEST_REPO_PATH "testrepo"
static git_repository *repo; static git_repository *repo;
static git_refdb_backend *refdb_backend;
int unlink_ref(void *payload, git_buf *file) int unlink_ref(void *payload, git_buf *file)
{ {
...@@ -26,7 +29,7 @@ int ref_file_foreach(git_repository *repo, int (* cb)(void *payload, git_buf *fi ...@@ -26,7 +29,7 @@ int ref_file_foreach(git_repository *repo, int (* cb)(void *payload, git_buf *fi
const char *repo_path; const char *repo_path;
git_buf repo_refs_dir = GIT_BUF_INIT; git_buf repo_refs_dir = GIT_BUF_INIT;
int error = 0; int error = 0;
repo_path = git_repository_path(repo); repo_path = git_repository_path(repo);
git_buf_joinpath(&repo_refs_dir, repo_path, "HEAD"); git_buf_joinpath(&repo_refs_dir, repo_path, "HEAD");
...@@ -38,7 +41,7 @@ int ref_file_foreach(git_repository *repo, int (* cb)(void *payload, git_buf *fi ...@@ -38,7 +41,7 @@ int ref_file_foreach(git_repository *repo, int (* cb)(void *payload, git_buf *fi
git_buf_joinpath(&repo_refs_dir, git_buf_cstr(&repo_refs_dir), "heads"); git_buf_joinpath(&repo_refs_dir, git_buf_cstr(&repo_refs_dir), "heads");
if (git_path_direach(&repo_refs_dir, cb, NULL) != 0) if (git_path_direach(&repo_refs_dir, cb, NULL) != 0)
return -1; return -1;
git_buf_joinpath(&repo_refs_dir, repo_path, "packed-refs"); git_buf_joinpath(&repo_refs_dir, repo_path, "packed-refs");
if (git_path_exists(git_buf_cstr(&repo_refs_dir)) && if (git_path_exists(git_buf_cstr(&repo_refs_dir)) &&
cb(NULL, &repo_refs_dir) < 0) cb(NULL, &repo_refs_dir) < 0)
...@@ -51,16 +54,16 @@ int ref_file_foreach(git_repository *repo, int (* cb)(void *payload, git_buf *fi ...@@ -51,16 +54,16 @@ int ref_file_foreach(git_repository *repo, int (* cb)(void *payload, git_buf *fi
void test_refdb_inmemory__initialize(void) void test_refdb_inmemory__initialize(void)
{ {
git_refdb *refdb;
git_buf repo_refs_dir = GIT_BUF_INIT; git_buf repo_refs_dir = GIT_BUF_INIT;
git_refdb *refdb;
git_refdb_backend *refdb_backend;
repo = cl_git_sandbox_init(TEST_REPO_PATH); repo = cl_git_sandbox_init(TEST_REPO_PATH);
cl_git_pass(git_repository_refdb(&refdb, repo)); cl_git_pass(git_repository_refdb(&refdb, repo));
cl_git_pass(refdb_backend_test(&refdb_backend, repo)); cl_git_pass(refdb_backend_test(&refdb_backend, repo));
cl_git_pass(git_refdb_set_backend(refdb, refdb_backend)); cl_git_pass(git_refdb_set_backend(refdb, refdb_backend));
ref_file_foreach(repo, unlink_ref); ref_file_foreach(repo, unlink_ref);
git_buf_free(&repo_refs_dir); git_buf_free(&repo_refs_dir);
...@@ -76,10 +79,10 @@ void test_refdb_inmemory__doesnt_write_ref_file(void) ...@@ -76,10 +79,10 @@ void test_refdb_inmemory__doesnt_write_ref_file(void)
{ {
git_reference *ref; git_reference *ref;
git_oid oid; git_oid oid;
cl_git_pass(git_oid_fromstr(&oid, "c47800c7266a2be04c571c04d5a6614691ea99bd")); cl_git_pass(git_oid_fromstr(&oid, "c47800c7266a2be04c571c04d5a6614691ea99bd"));
cl_git_pass(git_reference_create(&ref, repo, GIT_REFS_HEADS_DIR "test1", &oid, 0)); cl_git_pass(git_reference_create(&ref, repo, GIT_REFS_HEADS_DIR "test1", &oid, 0));
ref_file_foreach(repo, empty); ref_file_foreach(repo, empty);
git_reference_free(ref); git_reference_free(ref);
...@@ -89,10 +92,10 @@ void test_refdb_inmemory__read(void) ...@@ -89,10 +92,10 @@ void test_refdb_inmemory__read(void)
{ {
git_reference *write1, *write2, *write3, *read1, *read2, *read3; git_reference *write1, *write2, *write3, *read1, *read2, *read3;
git_oid oid1, oid2, oid3; git_oid oid1, oid2, oid3;
cl_git_pass(git_oid_fromstr(&oid1, "c47800c7266a2be04c571c04d5a6614691ea99bd")); cl_git_pass(git_oid_fromstr(&oid1, "c47800c7266a2be04c571c04d5a6614691ea99bd"));
cl_git_pass(git_reference_create(&write1, repo, GIT_REFS_HEADS_DIR "test1", &oid1, 0)); cl_git_pass(git_reference_create(&write1, repo, GIT_REFS_HEADS_DIR "test1", &oid1, 0));
cl_git_pass(git_oid_fromstr(&oid2, "e90810b8df3e80c413d903f631643c716887138d")); cl_git_pass(git_oid_fromstr(&oid2, "e90810b8df3e80c413d903f631643c716887138d"));
cl_git_pass(git_reference_create(&write2, repo, GIT_REFS_HEADS_DIR "test2", &oid2, 0)); cl_git_pass(git_reference_create(&write2, repo, GIT_REFS_HEADS_DIR "test2", &oid2, 0));
...@@ -139,7 +142,7 @@ int foreach_test(const char *ref_name, void *payload) ...@@ -139,7 +142,7 @@ int foreach_test(const char *ref_name, void *payload)
cl_assert(git_oid_cmp(&expected, git_reference_target(ref)) == 0); cl_assert(git_oid_cmp(&expected, git_reference_target(ref)) == 0);
++(*i); ++(*i);
git_reference_free(ref); git_reference_free(ref);
return 0; return 0;
...@@ -150,19 +153,19 @@ void test_refdb_inmemory__foreach(void) ...@@ -150,19 +153,19 @@ void test_refdb_inmemory__foreach(void)
git_reference *write1, *write2, *write3; git_reference *write1, *write2, *write3;
git_oid oid1, oid2, oid3; git_oid oid1, oid2, oid3;
size_t i = 0; size_t i = 0;
cl_git_pass(git_oid_fromstr(&oid1, "c47800c7266a2be04c571c04d5a6614691ea99bd")); cl_git_pass(git_oid_fromstr(&oid1, "c47800c7266a2be04c571c04d5a6614691ea99bd"));
cl_git_pass(git_reference_create(&write1, repo, GIT_REFS_HEADS_DIR "test1", &oid1, 0)); cl_git_pass(git_reference_create(&write1, repo, GIT_REFS_HEADS_DIR "test1", &oid1, 0));
cl_git_pass(git_oid_fromstr(&oid2, "e90810b8df3e80c413d903f631643c716887138d")); cl_git_pass(git_oid_fromstr(&oid2, "e90810b8df3e80c413d903f631643c716887138d"));
cl_git_pass(git_reference_create(&write2, repo, GIT_REFS_HEADS_DIR "test2", &oid2, 0)); cl_git_pass(git_reference_create(&write2, repo, GIT_REFS_HEADS_DIR "test2", &oid2, 0));
cl_git_pass(git_oid_fromstr(&oid3, "763d71aadf09a7951596c9746c024e7eece7c7af")); cl_git_pass(git_oid_fromstr(&oid3, "763d71aadf09a7951596c9746c024e7eece7c7af"));
cl_git_pass(git_reference_create(&write3, repo, GIT_REFS_HEADS_DIR "test3", &oid3, 0)); cl_git_pass(git_reference_create(&write3, repo, GIT_REFS_HEADS_DIR "test3", &oid3, 0));
cl_git_pass(git_reference_foreach(repo, GIT_REF_LISTALL, foreach_test, &i)); cl_git_pass(git_reference_foreach(repo, GIT_REF_LISTALL, foreach_test, &i));
cl_assert_equal_i(3, (int)i); cl_assert_equal_i(3, (int)i);
git_reference_free(write1); git_reference_free(write1);
git_reference_free(write2); git_reference_free(write2);
git_reference_free(write3); git_reference_free(write3);
...@@ -175,14 +178,14 @@ int delete_test(const char *ref_name, void *payload) ...@@ -175,14 +178,14 @@ int delete_test(const char *ref_name, void *payload)
size_t *i = payload; size_t *i = payload;
cl_git_pass(git_reference_lookup(&ref, repo, ref_name)); cl_git_pass(git_reference_lookup(&ref, repo, ref_name));
cl_git_pass(git_oid_fromstr(&expected, "e90810b8df3e80c413d903f631643c716887138d")); cl_git_pass(git_oid_fromstr(&expected, "e90810b8df3e80c413d903f631643c716887138d"));
cl_assert(git_oid_cmp(&expected, git_reference_target(ref)) == 0); cl_assert(git_oid_cmp(&expected, git_reference_target(ref)) == 0);
++(*i); ++(*i);
git_reference_free(ref); git_reference_free(ref);
return 0; return 0;
} }
...@@ -191,22 +194,22 @@ void test_refdb_inmemory__delete(void) ...@@ -191,22 +194,22 @@ void test_refdb_inmemory__delete(void)
git_reference *write1, *write2, *write3; git_reference *write1, *write2, *write3;
git_oid oid1, oid2, oid3; git_oid oid1, oid2, oid3;
size_t i = 0; size_t i = 0;
cl_git_pass(git_oid_fromstr(&oid1, "c47800c7266a2be04c571c04d5a6614691ea99bd")); cl_git_pass(git_oid_fromstr(&oid1, "c47800c7266a2be04c571c04d5a6614691ea99bd"));
cl_git_pass(git_reference_create(&write1, repo, GIT_REFS_HEADS_DIR "test1", &oid1, 0)); cl_git_pass(git_reference_create(&write1, repo, GIT_REFS_HEADS_DIR "test1", &oid1, 0));
cl_git_pass(git_oid_fromstr(&oid2, "e90810b8df3e80c413d903f631643c716887138d")); cl_git_pass(git_oid_fromstr(&oid2, "e90810b8df3e80c413d903f631643c716887138d"));
cl_git_pass(git_reference_create(&write2, repo, GIT_REFS_HEADS_DIR "test2", &oid2, 0)); cl_git_pass(git_reference_create(&write2, repo, GIT_REFS_HEADS_DIR "test2", &oid2, 0));
cl_git_pass(git_oid_fromstr(&oid3, "763d71aadf09a7951596c9746c024e7eece7c7af")); cl_git_pass(git_oid_fromstr(&oid3, "763d71aadf09a7951596c9746c024e7eece7c7af"));
cl_git_pass(git_reference_create(&write3, repo, GIT_REFS_HEADS_DIR "test3", &oid3, 0)); cl_git_pass(git_reference_create(&write3, repo, GIT_REFS_HEADS_DIR "test3", &oid3, 0));
git_reference_delete(write1); git_reference_delete(write1);
git_reference_free(write1); git_reference_free(write1);
git_reference_delete(write3); git_reference_delete(write3);
git_reference_free(write3); git_reference_free(write3);
cl_git_pass(git_reference_foreach(repo, GIT_REF_LISTALL, delete_test, &i)); cl_git_pass(git_reference_foreach(repo, GIT_REF_LISTALL, delete_test, &i));
cl_assert_equal_i(1, (int)i); cl_assert_equal_i(1, (int)i);
......
#include "common.h"
#include "vector.h" #include "vector.h"
#include "util.h" #include "util.h"
#include <git2/refdb.h> #include "testdb.h"
#include <git2/refdb_backend.h>
#include <git2/errors.h>
#include <git2/repository.h>
typedef struct refdb_test_backend { typedef struct refdb_test_backend {
git_refdb_backend parent; git_refdb_backend parent;
git_repository *repo; git_repository *repo;
git_vector refs; git_vector refs;
} refdb_test_backend; } refdb_test_backend;
...@@ -16,7 +12,7 @@ typedef struct refdb_test_backend { ...@@ -16,7 +12,7 @@ typedef struct refdb_test_backend {
typedef struct refdb_test_entry { typedef struct refdb_test_entry {
char *name; char *name;
git_ref_t type; git_ref_t type;
union { union {
git_oid oid; git_oid oid;
char *symbolic; char *symbolic;
...@@ -37,19 +33,19 @@ static int refdb_test_backend__exists( ...@@ -37,19 +33,19 @@ static int refdb_test_backend__exists(
refdb_test_backend *backend; refdb_test_backend *backend;
refdb_test_entry *entry; refdb_test_entry *entry;
size_t i; size_t i;
assert(_backend); assert(_backend);
backend = (refdb_test_backend *)_backend; backend = (refdb_test_backend *)_backend;
*exists = 0; *exists = 0;
git_vector_foreach(&backend->refs, i, entry) { git_vector_foreach(&backend->refs, i, entry) {
if (strcmp(entry->name, ref_name) == 0) { if (strcmp(entry->name, ref_name) == 0) {
*exists = 1; *exists = 1;
break; break;
} }
} }
return 0; return 0;
} }
...@@ -59,18 +55,18 @@ static int refdb_test_backend__write( ...@@ -59,18 +55,18 @@ static int refdb_test_backend__write(
{ {
refdb_test_backend *backend; refdb_test_backend *backend;
refdb_test_entry *entry; refdb_test_entry *entry;
assert(_backend); assert(_backend);
backend = (refdb_test_backend *)_backend; backend = (refdb_test_backend *)_backend;
entry = git__calloc(1, sizeof(refdb_test_entry)); entry = git__calloc(1, sizeof(refdb_test_entry));
GITERR_CHECK_ALLOC(entry); GITERR_CHECK_ALLOC(entry);
entry->name = git__strdup(git_reference_name(ref)); entry->name = git__strdup(git_reference_name(ref));
GITERR_CHECK_ALLOC(entry->name); GITERR_CHECK_ALLOC(entry->name);
entry->type = git_reference_type(ref); entry->type = git_reference_type(ref);
if (entry->type == GIT_REF_OID) if (entry->type == GIT_REF_OID)
git_oid_cpy(&entry->target.oid, git_reference_target(ref)); git_oid_cpy(&entry->target.oid, git_reference_target(ref));
else { else {
...@@ -79,7 +75,7 @@ static int refdb_test_backend__write( ...@@ -79,7 +75,7 @@ static int refdb_test_backend__write(
} }
git_vector_insert(&backend->refs, entry); git_vector_insert(&backend->refs, entry);
return 0; return 0;
} }
...@@ -94,7 +90,7 @@ static int refdb_test_backend__lookup( ...@@ -94,7 +90,7 @@ static int refdb_test_backend__lookup(
assert(_backend); assert(_backend);
backend = (refdb_test_backend *)_backend; backend = (refdb_test_backend *)_backend;
git_vector_foreach(&backend->refs, i, entry) { git_vector_foreach(&backend->refs, i, entry) {
if (strcmp(entry->name, ref_name) == 0) { if (strcmp(entry->name, ref_name) == 0) {
...@@ -108,7 +104,7 @@ static int refdb_test_backend__lookup( ...@@ -108,7 +104,7 @@ static int refdb_test_backend__lookup(
if (*out == NULL) if (*out == NULL)
return -1; return -1;
return 0; return 0;
} }
} }
...@@ -125,21 +121,21 @@ static int refdb_test_backend__foreach( ...@@ -125,21 +121,21 @@ static int refdb_test_backend__foreach(
refdb_test_backend *backend; refdb_test_backend *backend;
refdb_test_entry *entry; refdb_test_entry *entry;
size_t i; size_t i;
assert(_backend); assert(_backend);
backend = (refdb_test_backend *)_backend; backend = (refdb_test_backend *)_backend;
git_vector_foreach(&backend->refs, i, entry) { git_vector_foreach(&backend->refs, i, entry) {
if (entry->type == GIT_REF_OID && (list_flags & GIT_REF_OID) == 0) if (entry->type == GIT_REF_OID && (list_flags & GIT_REF_OID) == 0)
continue; continue;
if (entry->type == GIT_REF_SYMBOLIC && (list_flags & GIT_REF_SYMBOLIC) == 0) if (entry->type == GIT_REF_SYMBOLIC && (list_flags & GIT_REF_SYMBOLIC) == 0)
continue; continue;
if (callback(entry->name, payload) != 0) if (callback(entry->name, payload) != 0)
return GIT_EUSER; return GIT_EUSER;
} }
return 0; return 0;
} }
...@@ -147,7 +143,7 @@ static void refdb_test_entry_free(refdb_test_entry *entry) ...@@ -147,7 +143,7 @@ static void refdb_test_entry_free(refdb_test_entry *entry)
{ {
if (entry->type == GIT_REF_SYMBOLIC) if (entry->type == GIT_REF_SYMBOLIC)
git__free(entry->target.symbolic); git__free(entry->target.symbolic);
git__free(entry->name); git__free(entry->name);
git__free(entry); git__free(entry);
} }
...@@ -178,14 +174,14 @@ static void refdb_test_backend__free(git_refdb_backend *_backend) ...@@ -178,14 +174,14 @@ static void refdb_test_backend__free(git_refdb_backend *_backend)
refdb_test_backend *backend; refdb_test_backend *backend;
refdb_test_entry *entry; refdb_test_entry *entry;
size_t i; size_t i;
assert(_backend); assert(_backend);
backend = (refdb_test_backend *)_backend; backend = (refdb_test_backend *)_backend;
git_vector_foreach(&backend->refs, i, entry) git_vector_foreach(&backend->refs, i, entry)
refdb_test_entry_free(entry); refdb_test_entry_free(entry);
git_vector_free(&backend->refs); git_vector_free(&backend->refs);
git__free(backend); git__free(backend);
} }
...@@ -197,7 +193,7 @@ int refdb_backend_test( ...@@ -197,7 +193,7 @@ int refdb_backend_test(
backend = git__calloc(1, sizeof(refdb_test_backend)); backend = git__calloc(1, sizeof(refdb_test_backend));
GITERR_CHECK_ALLOC(backend); GITERR_CHECK_ALLOC(backend);
git_vector_init(&backend->refs, 0, ref_name_cmp); git_vector_init(&backend->refs, 0, ref_name_cmp);
backend->repo = repo; backend->repo = repo;
......
#include <git2/errors.h>
#include <git2/repository.h>
#include <git2/refdb.h>
#include <git2/sys/refs.h>
#include <git2/sys/refdb_backend.h>
int refdb_backend_test( int refdb_backend_test(
git_refdb_backend **backend_out, git_refdb_backend **backend_out,
git_repository *repo); git_repository *repo);
#include "clar_libgit2.h" #include "clar_libgit2.h"
#include "git2/sys/repository.h"
#include "buffer.h" #include "buffer.h"
#include "posix.h" #include "posix.h"
#include "util.h" #include "util.h"
......
#include "clar_libgit2.h" #include "clar_libgit2.h"
#include "git2/sys/repository.h"
#include "fileops.h" #include "fileops.h"
#include "ignore.h" #include "ignore.h"
#include "status_helpers.h" #include "status_helpers.h"
...@@ -321,10 +323,10 @@ void test_status_worktree_init__new_staged_file_must_handle_crlf(void) ...@@ -321,10 +323,10 @@ void test_status_worktree_init__new_staged_file_must_handle_crlf(void)
cl_set_cleanup(&cleanup_new_repo, "getting_started"); cl_set_cleanup(&cleanup_new_repo, "getting_started");
cl_git_pass(git_repository_init(&repo, "getting_started", 0)); cl_git_pass(git_repository_init(&repo, "getting_started", 0));
// Ensure that repo has core.autocrlf=true /* Ensure that repo has core.autocrlf=true */
cl_repo_set_bool(repo, "core.autocrlf", true); cl_repo_set_bool(repo, "core.autocrlf", true);
cl_git_mkfile("getting_started/testfile.txt", "content\r\n"); // Content with CRLF cl_git_mkfile("getting_started/testfile.txt", "content\r\n"); /* Content with CRLF */
cl_git_pass(git_repository_index(&index, repo)); cl_git_pass(git_repository_index(&index, repo));
cl_git_pass(git_index_add_bypath(index, "testfile.txt")); cl_git_pass(git_index_add_bypath(index, "testfile.txt"));
......
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