From a4e7ac2715ea7077ccedb190a783c64c06a9c539 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Mon, 16 Jan 2017 01:04:25 +0000 Subject: dgit: gitattributes: Provide setup_gitattrs (internal function) This is the idempotent function which adds the appropriate runes to .git/info/attributes. No callers yet. Signed-off-by: Ian Jackson --- dgit | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'dgit') diff --git a/dgit b/dgit index dbfe1ac..ede7010 100755 --- a/dgit +++ b/dgit @@ -143,6 +143,7 @@ our %opts_cfg_insertpos = map { } keys %opts_opt_map; sub parseopts_late_defaults(); +sub setup_gitattrs(;$); our $keyid; @@ -3315,6 +3316,53 @@ sub ensure_setup_existing_tree () { set_local_git_config $k, 'true'; } +sub open_gitattrs () { + my $gai = new IO::File ".git/info/attributes" + or $!==ENOENT + or die "open .git/info/attributes: $!"; + return $gai; +} + +sub is_gitattrs_setup () { + my $gai = open_gitattrs(); + return 0 unless $gai; + while (<$gai>) { + return 1 if m{^\[attr\]dgit-defuse-attrs\s}; + } + $gai->error and die $!; + return 0; +} + +sub setup_gitattrs (;$) { + my ($always) = @_; + return unless $always || access_cfg_bool(1, 'setup-gitattributes'); + + if (is_gitattrs_setup()) { + progress < $af.new" or die $!; + print GAO <) { + chomp; + print GAO $_, "\n" or die $!; + } + $gai->error and die $!; + } + close GAO or die $!; + rename "$af.new", "$af" or die "install $af: $!"; +} + sub setup_new_tree () { setup_mergechangelogs(); setup_useremail(); -- cgit v1.2.3