Commit 3eadfecd by Russell Belfer

start implementing diff driver registry

parent 2f77d8f1
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
#include "map.h" #include "map.h"
#include "buf_text.h" #include "buf_text.h"
GIT__USE_STRMAP;
typedef enum { typedef enum {
DIFF_DRIVER_AUTO = 0, DIFF_DRIVER_AUTO = 0,
DIFF_DRIVER_FALSE = 1, DIFF_DRIVER_FALSE = 1,
...@@ -33,7 +35,7 @@ enum { ...@@ -33,7 +35,7 @@ enum {
struct git_diff_driver { struct git_diff_driver {
git_diff_driver_t type; git_diff_driver_t type;
git_strarray fn_patterns; git_strarray fn_patterns;
int binary; int binary; /* 0 => treat as text, 1 => treat as binary, -1 => auto */
}; };
struct git_diff_driver_registry { struct git_diff_driver_registry {
...@@ -49,17 +51,45 @@ static git_diff_driver global_drivers[3] = { ...@@ -49,17 +51,45 @@ static git_diff_driver global_drivers[3] = {
git_diff_driver_registry *git_diff_driver_registry_new() git_diff_driver_registry *git_diff_driver_registry_new()
{ {
return git__calloc(1, sizeof(git_diff_driver_registry)); git_diff_driver_registry *reg =
git__calloc(1, sizeof(git_diff_driver_registry));
if (!reg)
return NULL;
if (git_pool_init(&reg->strings, 1, 0) < 0 ||
(reg->drivers = git_strmap_alloc()) == NULL)
{
git_diff_driver_registry_free(reg);
return NULL;
}
return reg;
} }
void git_diff_driver_registry_free(git_diff_driver_registry *reg) void git_diff_driver_registry_free(git_diff_driver_registry *reg)
{ {
if (!reg)
return;
git_strmap_free(reg->drivers);
git_pool_clear(&reg->strings);
git__free(reg); git__free(reg);
} }
static int git_diff_driver_load(
git_diff_driver **out, git_repository *repo, const char *name)
{
GIT_UNUSED(out);
GIT_UNUSED(repo);
GIT_UNUSED(name);
return GIT_ENOTFOUND;
}
int git_diff_driver_lookup( int git_diff_driver_lookup(
git_diff_driver **out, git_repository *repo, const char *path) git_diff_driver **out, git_repository *repo, const char *path)
{ {
int error = 0;
const char *value; const char *value;
assert(out); assert(out);
...@@ -67,8 +97,8 @@ int git_diff_driver_lookup( ...@@ -67,8 +97,8 @@ int git_diff_driver_lookup(
if (!repo || !path || !strlen(path)) if (!repo || !path || !strlen(path))
goto use_auto; goto use_auto;
if (git_attr_get(&value, repo, 0, path, "diff") < 0) if ((error = git_attr_get(&value, repo, 0, path, "diff")) < 0)
return -1; return error;
if (GIT_ATTR_FALSE(value)) { if (GIT_ATTR_FALSE(value)) {
*out = &global_drivers[DIFF_DRIVER_FALSE]; *out = &global_drivers[DIFF_DRIVER_FALSE];
...@@ -81,6 +111,12 @@ int git_diff_driver_lookup( ...@@ -81,6 +111,12 @@ int git_diff_driver_lookup(
} }
/* otherwise look for driver information in config and build driver */ /* otherwise look for driver information in config and build driver */
if ((error = git_diff_driver_load(out, repo, value)) < 0) {
if (error != GIT_ENOTFOUND)
return error;
else
giterr_clear();
}
use_auto: use_auto:
*out = &global_drivers[DIFF_DRIVER_AUTO]; *out = &global_drivers[DIFF_DRIVER_AUTO];
......
...@@ -111,7 +111,9 @@ void git_repository_free(git_repository *repo) ...@@ -111,7 +111,9 @@ void git_repository_free(git_repository *repo)
git_cache_free(&repo->objects); git_cache_free(&repo->objects);
git_submodule_config_free(repo); git_submodule_config_free(repo);
git_diff_driver_registry_free(repo->diff_drivers); git_diff_driver_registry_free(repo->diff_drivers);
repo->diff_drivers = NULL;
git__free(repo->path_repository); git__free(repo->path_repository);
git__free(repo->workdir); git__free(repo->workdir);
......
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