mirror of
https://git.proxmox.com/git/libgit2
synced 2025-06-20 03:51:05 +00:00
Make git_filter_source opaque
This commit is contained in:
parent
85d5481206
commit
570ba25cb0
@ -22,12 +22,29 @@ GIT_BEGIN_DECL
|
|||||||
* A filter source represents a file/blob to be processed
|
* A filter source represents a file/blob to be processed
|
||||||
*/
|
*/
|
||||||
typedef struct git_filter_source git_filter_source;
|
typedef struct git_filter_source git_filter_source;
|
||||||
struct git_filter_source {
|
|
||||||
git_repository *repo;
|
/**
|
||||||
const char *path;
|
* Get the repository that the source data is coming from.
|
||||||
git_oid oid; /* zero if unknown (which is likely) */
|
*/
|
||||||
uint16_t filemode; /* zero if unknown */
|
GIT_EXTERN(git_repository *) git_filter_source_repo(const git_filter_source *src);
|
||||||
};
|
|
||||||
|
/**
|
||||||
|
* Get the path that the source data is coming from.
|
||||||
|
*/
|
||||||
|
GIT_EXTERN(const char *) git_filter_source_path(const git_filter_source *src);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the file mode of the source file
|
||||||
|
* If the mode is unknown, this will return 0
|
||||||
|
*/
|
||||||
|
GIT_EXTERN(uint16_t) git_filter_source_filemode(const git_filter_source *src);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the OID of the source
|
||||||
|
* If the OID is unknown (often the case with GIT_FILTER_CLEAN) then
|
||||||
|
* this will return NULL.
|
||||||
|
*/
|
||||||
|
GIT_EXTERN(const git_oid *) git_filter_source_id(const git_filter_source *src);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback to actually perform the data filtering
|
* Callback to actually perform the data filtering
|
||||||
|
15
src/crlf.c
15
src/crlf.c
@ -107,8 +107,10 @@ static int crlf_load_attributes(
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int has_cr_in_index(git_repository *repo, const char *path)
|
static int has_cr_in_index(const git_filter_source *src)
|
||||||
{
|
{
|
||||||
|
git_repository *repo = git_filter_source_repo(src);
|
||||||
|
const char *path = git_filter_source_path(src);
|
||||||
git_index *index;
|
git_index *index;
|
||||||
const git_index_entry *entry;
|
const git_index_entry *entry;
|
||||||
git_blob *blob;
|
git_blob *blob;
|
||||||
@ -180,7 +182,7 @@ static int crlf_apply_to_odb(
|
|||||||
* If the file in the index has any CR in it, do not convert.
|
* If the file in the index has any CR in it, do not convert.
|
||||||
* This is the new safer autocrlf handling.
|
* This is the new safer autocrlf handling.
|
||||||
*/
|
*/
|
||||||
if (has_cr_in_index(src->repo, src->path))
|
if (has_cr_in_index(src))
|
||||||
return GIT_ENOTFOUND;
|
return GIT_ENOTFOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -290,7 +292,9 @@ static int crlf_check(
|
|||||||
GIT_UNUSED(mode);
|
GIT_UNUSED(mode);
|
||||||
|
|
||||||
/* Load gitattributes for the path */
|
/* Load gitattributes for the path */
|
||||||
if ((error = crlf_load_attributes(&ca, src->repo, src->path)) < 0)
|
error = crlf_load_attributes(
|
||||||
|
&ca, git_filter_source_repo(src), git_filter_source_path(src));
|
||||||
|
if (error < 0)
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -303,8 +307,9 @@ static int crlf_check(
|
|||||||
return GIT_ENOTFOUND;
|
return GIT_ENOTFOUND;
|
||||||
|
|
||||||
if (ca.crlf_action == GIT_CRLF_GUESS) {
|
if (ca.crlf_action == GIT_CRLF_GUESS) {
|
||||||
if ((error = git_repository__cvar(
|
error = git_repository__cvar(
|
||||||
&ca.auto_crlf, src->repo, GIT_CVAR_AUTO_CRLF)) < 0)
|
&ca.auto_crlf, git_filter_source_repo(src), GIT_CVAR_AUTO_CRLF);
|
||||||
|
if (error < 0)
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
if (ca.auto_crlf == GIT_AUTO_CRLF_FALSE)
|
if (ca.auto_crlf == GIT_AUTO_CRLF_FALSE)
|
||||||
|
27
src/filter.c
27
src/filter.c
@ -13,6 +13,13 @@
|
|||||||
#include "git2/config.h"
|
#include "git2/config.h"
|
||||||
#include "blob.h"
|
#include "blob.h"
|
||||||
|
|
||||||
|
struct git_filter_source {
|
||||||
|
git_repository *repo;
|
||||||
|
const char *path;
|
||||||
|
git_oid oid; /* zero if unknown (which is likely) */
|
||||||
|
uint16_t filemode; /* zero if unknown */
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
git_filter *filter;
|
git_filter *filter;
|
||||||
void *payload;
|
void *payload;
|
||||||
@ -32,6 +39,26 @@ typedef struct {
|
|||||||
|
|
||||||
static git_array_t(git_filter_def) filter_registry = GIT_ARRAY_INIT;
|
static git_array_t(git_filter_def) filter_registry = GIT_ARRAY_INIT;
|
||||||
|
|
||||||
|
git_repository *git_filter_source_repo(const git_filter_source *src)
|
||||||
|
{
|
||||||
|
return src->repo;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *git_filter_source_path(const git_filter_source *src)
|
||||||
|
{
|
||||||
|
return src->path;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t git_filter_source_filemode(const git_filter_source *src)
|
||||||
|
{
|
||||||
|
return src->filemode;
|
||||||
|
}
|
||||||
|
|
||||||
|
const git_oid *git_filter_source_id(const git_filter_source *src)
|
||||||
|
{
|
||||||
|
return git_oid_iszero(&src->oid) ? NULL : &src->oid;
|
||||||
|
}
|
||||||
|
|
||||||
static int filter_load_defaults(void)
|
static int filter_load_defaults(void)
|
||||||
{
|
{
|
||||||
if (!git_array_size(filter_registry)) {
|
if (!git_array_size(filter_registry)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user