Skip to content

Commit fba3bf7

Browse files
committed
blob: optionally read attributes from repository
When `GIT_BLOB_FILTER_ATTTRIBUTES_FROM_HEAD` is passed to `git_blob_filter`, read attributes from `gitattributes` files that are checked in to the repository at the HEAD revision. This passes the flag `GIT_FILTER_ATTRIBUTES_FROM_HEAD` to the filter functions.
1 parent f0f27c1 commit fba3bf7

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

include/git2/blob.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ typedef enum {
108108
* system-wide `gitattributes` in `/etc` (or system equivalent).
109109
*/
110110
GIT_BLOB_FILTER_NO_SYSTEM_ATTRIBUTES = (1 << 1),
111+
112+
/**
113+
* When set, filters will be loaded from a `.gitattributes` file
114+
* in the HEAD commit.
115+
*/
116+
GIT_BLOB_FILTER_ATTTRIBUTES_FROM_HEAD = (1 << 2),
111117
} git_blob_filter_flag_t;
112118

113119
/**

src/blob.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,9 @@ int git_blob_filter(
428428
if ((opts.flags & GIT_BLOB_FILTER_NO_SYSTEM_ATTRIBUTES) != 0)
429429
flags |= GIT_FILTER_NO_SYSTEM_ATTRIBUTES;
430430

431+
if ((opts.flags & GIT_BLOB_FILTER_ATTTRIBUTES_FROM_HEAD) != 0)
432+
flags |= GIT_FILTER_ATTRIBUTES_FROM_HEAD;
433+
431434
if (!(error = git_filter_list_load(
432435
&fl, git_blob_owner(blob), blob, path,
433436
GIT_FILTER_TO_WORKTREE, flags))) {

0 commit comments

Comments
 (0)