From 5099a42730ecb2a33152826a623d545f60fea77e Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 20 Jun 2018 14:10:02 +0100 Subject: [PATCH] dgit: gitattributes: Defuse working-tree-encoding * Add -working-tree-encoding to $negate_harmful_gitattrs. * Add new arrangements for updating an existing dgit-defuse-attrs macro definition: - is_gitattrs: say whether the macro is up to date - setup_gitattrs: update an existing out-of-date macro - minor message changes - document the new behaviour One consequence is that we have had to breach the promise about how to stop future dgit setup-new-tree runs messing with this: it is now necessary to disapply the macro, rather than redefine it. Closes:#901900. Signed-off-by: Ian Jackson --- Debian/Dgit.pm | 4 +++- dgit | 22 +++++++++++++++++----- dgit.1 | 11 ++++++++++- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/Debian/Dgit.pm b/Debian/Dgit.pm index 960f505a..aec5a239 100644 --- a/Debian/Dgit.pm +++ b/Debian/Dgit.pm @@ -101,7 +101,9 @@ sub NOCOMMITCHECK () { return 0x8; } our $debugprefix; our $debuglevel = 0; -our $negate_harmful_gitattrs = "-text -eol -crlf -ident -filter"; +our $negate_harmful_gitattrs = + "-text -eol -crlf -ident -filter -working-tree-encoding"; + # ^ when updating this, alter the regexp in dgit:is_gitattrs_setup our $forkcheck_mainprocess; diff --git a/dgit b/dgit index e7a69041..94f915ef 100755 --- a/dgit +++ b/dgit @@ -3396,15 +3396,23 @@ sub open_main_gitattrs () { our $gitattrs_ourmacro_re = qr{^\[attr\]dgit-defuse-attrs\s}; sub is_gitattrs_setup () { + # return values: + # trueish + # 1: gitattributes set up and should be left alone + # falseish + # 0: there is a dgit-defuse-attrs but it needs fixing + # undef: there is none my $gai = open_main_gitattrs(); return 0 unless $gai; while (<$gai>) { next unless m{$gitattrs_ourmacro_re}; - return 1; + return 1 if m{\s-working-tree-encoding\s}; + printdebug "is_gitattrs_setup: found old macro\n"; + return 0; } $gai->error and die $!; printdebug "is_gitattrs_setup: found nothing\n"; - return 0; + return undef; } sub setup_gitattrs (;$) { @@ -3414,7 +3422,7 @@ sub setup_gitattrs (;$) { my $already = is_gitattrs_setup(); if ($already) { progress < $af.new" or die $!; - print GAO <) { + if (m{$gitattrs_ourmacro_re}) { + die unless defined $already; + $_ = $new; + } chomp; print GAO $_, "\n" or die $!; } @@ -3466,7 +3478,7 @@ sub check_gitattrs ($$) { # oh dear, found one print STDERR <