summaryrefslogtreecommitdiff
path: root/include/git2
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2014-05-06 16:01:49 -0700
committerRussell Belfer <rb@github.com>2014-05-06 16:01:49 -0700
commit5269008cf632efcd6a16f6160ec44244ce442400 (patch)
treead3be5bcf12e9c046fab24fac3063e22b6843d5c /include/git2
parent6e9afb97d14545f9cea292f581de89d610ae8c07 (diff)
downloadlibgit2-5269008cf632efcd6a16f6160ec44244ce442400.tar.gz
Add filter options and ALLOW_UNSAFE
Diff and status do not want core.safecrlf to actually raise an error regardless of the setting, so this extends the filter API with an additional options flags parameter and adds a flag so that filters can be applied with GIT_FILTER_OPT_ALLOW_UNSAFE, indicating that unsafe filter application should be downgraded from a failure to a warning.
Diffstat (limited to 'include/git2')
-rw-r--r--include/git2/filter.h8
-rw-r--r--include/git2/repository.h5
-rw-r--r--include/git2/sys/filter.h12
3 files changed, 22 insertions, 3 deletions
diff --git a/include/git2/filter.h b/include/git2/filter.h
index f96b6766b..7fd9b7e59 100644
--- a/include/git2/filter.h
+++ b/include/git2/filter.h
@@ -35,6 +35,11 @@ typedef enum {
GIT_FILTER_CLEAN = GIT_FILTER_TO_ODB,
} git_filter_mode_t;
+typedef enum {
+ GIT_FILTER_OPT_DEFAULT = 0u,
+ GIT_FILTER_OPT_ALLOW_UNSAFE = (1u << 0),
+} git_filter_opt_t;
+
/**
* A filter that can transform file data
*
@@ -83,7 +88,8 @@ GIT_EXTERN(int) git_filter_list_load(
git_repository *repo,
git_blob *blob, /* can be NULL */
const char *path,
- git_filter_mode_t mode);
+ git_filter_mode_t mode,
+ git_filter_opt_t options);
/**
* Apply filter list to a data buffer.
diff --git a/include/git2/repository.h b/include/git2/repository.h
index e3f687a29..04df25fd3 100644
--- a/include/git2/repository.h
+++ b/include/git2/repository.h
@@ -546,6 +546,10 @@ GIT_EXTERN(int) git_repository_mergehead_foreach(
* hash a file in the repository and you want to apply filtering rules (e.g.
* crlf filters) before generating the SHA, then use this function.
*
+ * Note: if the repository has `core.safecrlf` set to fail and the
+ * filtering triggers that failure, then this function will return an
+ * error and not calculate the hash of the file.
+ *
* @param out Output value of calculated SHA
* @param repo Repository pointer
* @param path Path to file on disk whose contents should be hashed. If the
@@ -555,6 +559,7 @@ GIT_EXTERN(int) git_repository_mergehead_foreach(
* NULL, then the `path` parameter will be used instead. If
* this is passed as the empty string, then no filters will be
* applied when calculating the hash.
+ * @return 0 on success, or an error code
*/
GIT_EXTERN(int) git_repository_hashfile(
git_oid *out,
diff --git a/include/git2/sys/filter.h b/include/git2/sys/filter.h
index 8fe21c9c0..1b21a9d30 100644
--- a/include/git2/sys/filter.h
+++ b/include/git2/sys/filter.h
@@ -55,7 +55,10 @@ GIT_EXTERN(git_filter *) git_filter_lookup(const char *name);
* your own chains of filters.
*/
GIT_EXTERN(int) git_filter_list_new(
- git_filter_list **out, git_repository *repo, git_filter_mode_t mode);
+ git_filter_list **out,
+ git_repository *repo,
+ git_filter_mode_t mode,
+ git_filter_opt_t options);
/**
* Add a filter to a filter list with the given payload.
@@ -115,10 +118,15 @@ GIT_EXTERN(uint16_t) git_filter_source_filemode(const git_filter_source *src);
GIT_EXTERN(const git_oid *) git_filter_source_id(const git_filter_source *src);
/**
- * Get the git_filter_mode_t to be applied
+ * Get the git_filter_mode_t to be used
*/
GIT_EXTERN(git_filter_mode_t) git_filter_source_mode(const git_filter_source *src);
+/**
+ * Get the git_filter_opt_t options to be applied
+ */
+GIT_EXTERN(git_filter_opt_t) git_filter_source_options(const git_filter_source *src);
+
/*
* struct git_filter
*