def get_boolean(self, section, name, default=None):
"""Retrieve a configuration setting as boolean.
- :param section: Tuple with section name and optional subsection namee
+ :param section: Tuple with section name and optional subsection name
:param name: Name of the setting, including section and possible
subsection.
:return: Contents of the setting
return intermediary.replace(LF, CRLF)
+def get_checkout_filter(core_eol, core_autocrlf, git_attributes):
+ """ Returns the correct checkout filter based on the passed arguments
+ """
+ # TODO this function should process the git_attributes for the path and if
+ # the text attribute is not defined, fallback on the
+ # get_checkout_filter_autocrlf function with the autocrlf value
+ return get_checkout_filter_autocrlf(core_autocrlf)
+
+
+def get_checkin_filter(core_eol, core_autocrlf, git_attributes):
+ """ Returns the correct checkin filter based on the passed arguments
+ """
+ # TODO this function should process the git_attributes for the path and if
+ # the text attribute is not defined, fallback on the
+ # get_checkin_filter_autocrlf function with the autocrlf value
+ return get_checkin_filter_autocrlf(core_autocrlf)
+
+
def get_checkout_filter_autocrlf(core_autocrlf):
""" Returns the correct checkout filter base on autocrlf value
on configuration, gitattributes, path and operation (checkin or checkout)
"""
- def __init__(self, config_stack, gitattributes, read_filter, write_filter):
+ def __init__(self, config_stack, gitattributes):
self.config_stack = config_stack
self.gitattributes = gitattributes
- # TODO compute them based on passed values
- self.fallback_read_filter = read_filter
- self.fallback_write_filter = write_filter
+ # Compute which filters we needs based on parameters
+ try:
+ core_eol = config_stack.get("core", "eol")
+ except KeyError:
+ core_eol = "native"
+
+ try:
+ core_autocrlf = config_stack.get("core", "autocrlf").lower()
+ except KeyError:
+ core_autocrlf = False
+
+ self.fallback_read_filter = get_checkout_filter(
+ core_eol, core_autocrlf, self.gitattributes
+ )
+ self.fallback_write_filter = get_checkin_filter(
+ core_eol, core_autocrlf, self.gitattributes
+ )
def checkin_normalize(self, blob, tree_path):
""" Normalize a blob during a checkin operation
self.hooks['commit-msg'] = CommitMsgShellHook(self.controldir())
self.hooks['post-commit'] = PostCommitShellHook(self.controldir())
- # Line ending convert filters
- # TODO: Set them based on configuration
- self.read_filter = None
- self.write_filter = None
-
def _write_reflog(self, ref, old_sha, new_sha, committer, timestamp,
timezone, message):
from .reflog import format_reflog_line
"""
# TODO Parse the git attributes files
git_attributes = {}
- return BlobNormalizer(self.get_config_stack(), git_attributes, self.read_filter, self.write_filter)
+ return BlobNormalizer(self.get_config_stack(), git_attributes)
class MemoryRepo(BaseRepo):
from dulwich import porcelain
from dulwich.diff_tree import tree_changes
-from dulwich.line_ending import convert_crlf_to_lf
from dulwich.objects import (
Blob,
Tag,
f.write(b'line1\r\nline2')
# TODO: It should be set automatically by looking at the configuration
- self.repo.write_filter = convert_crlf_to_lf
+ c = self.repo.get_config()
+ c.set("core", "autocrlf", True)
+ c.write_to_path()
results = porcelain.status(self.repo)
self.assertDictEqual(