class Agate::FilterList

Overview

A loaded filter list that can be applied to data, files, or blobs.

Filters transform file content between the working directory and the object database (e.g., line-ending conversion, ident expansion).

# Load filters for a path (smudge direction = checkout)
filters = FilterList.load(repo, "src/main.cr", FilterMode::ToWorktree)

# Check if a specific filter will run
filters.contains?("crlf") # => true/false

# Apply to a buffer
filtered = filters.apply("line1\nline2\n")

# Apply to a file on disk
filtered = filters.apply_to_file(repo, "src/main.cr")

# Apply to a blob
filtered = filters.apply_to_blob(blob)

Defined in:

agate/filter.cr

Class Method Summary

Instance Method Summary

Class Method Detail

def self.load(repo : Repository, path : String, mode : FilterMode = FilterMode::ToWorktree, blob : Blob | Nil = nil, flags : FilterFlags = FilterFlags::None) : FilterList | Nil #

Loads the filter list for a given path and mode. Returns a FilterList, or nil if no filters are needed.

  • repo: the repository
  • path: relative path of the file (doesn't need to exist)
  • mode: filtering direction (ToWorktree or ToODB)
  • blob: the blob being filtered (optional, for optimisation)
  • flags: combination of FilterFlags

[View source]

Instance Method Detail

def apply(data : String) : String #

Applies the filter list to a data buffer and returns the result.


[View source]
def apply(data : Bytes) : Bytes #

Applies the filter list to a data buffer and returns the result.


[View source]
def apply_to_blob(blob : Blob) : String #

Applies the filter list to a blob and returns the result.


[View source]
def apply_to_file(repo : Repository, path : String) : String #

Applies the filter list to a file on disk and returns the result.


[View source]
def contains?(name : String) : Bool #

Returns true if the named filter is in this list. Built-in filters are "crlf" and "ident".


[View source]