Subject: [PATCH v6 0/2] check-attr: add support to work with tree-ish

From: Karthik Nayak <[email-masked]>
Date: Thu, 12 Jan 2023 12:00:29 +0100

v1: https://lore.kernel.org/git/[email-masked]/
v2: https://lore.kernel.org/git/CAOLa=ZSsFGBw3ta1jWN8cmUch2ca=[email-masked]/T/#t
v3: https://lore.kernel.org/git/[email-masked]/
v4: https://lore.kernel.org/git/[email-masked]
v5: https://lore.kernel.org/git/[email-masked]/

Given a pathname, git-check-attr(1) will list the attributes which apply to that
pathname by reading all relevant gitattributes files. Currently there is no way
to specify a tree-ish to read the gitattributes from.

This is specifically useful in bare repositories wherein the gitattributes are
only present in the git working tree but not available directly on the
filesystem.

This series aims to add a new flag `--source` to git-check-attr(1) which
allows us to read gitattributes from the specified tree-ish.

Changes since v5:
- Changed the documentation and helper code to say 'tree-ish' instead of 'tree'
- Fixed broken tests because of missing `&&`

Range-diff against v5:

1:  6224754179 = 1:  6224754179 t0003: move setup for `--all` into new block
2:  d835d989ad ! 2:  57f5957127 attr: add flag `--source` to work with tree-ish
    @@ Documentation/git-check-attr.txt: git-check-attr - Display gitattributes informa
      [verse]
     -'git check-attr' [-a | --all | <attr>...] [--] <pathname>...
     -'git check-attr' --stdin [-z] [-a | --all | <attr>...]
    -+'git check-attr' [--source <tree>] [-a | --all | <attr>...] [--] <pathname>...
    -+'git check-attr' --stdin [-z] [--source <tree>] [-a | --all | <attr>...]
    ++'git check-attr' [--source <tree-ish>] [-a | --all | <attr>...] [--] <pathname>...
    ++'git check-attr' --stdin [-z] [--source <tree-ish>] [-a | --all | <attr>...]
      
      DESCRIPTION
      -----------
    @@ Documentation/git-check-attr.txt: OPTIONS
      	If `--stdin` is also given, input paths are separated
      	with a NUL character instead of a linefeed character.
      
    -+--source=<tree>::
    -+	Check attributes against the specified tree-ish. Paths provided as part
    -+	of the revision will be treated as the root directory. It is common to
    ++--source=<tree-ish>::
    ++	Check attributes against the specified tree-ish. It is common to
     +	specify the source tree by naming a commit, branch or tag associated
     +	with it.
     +
    @@ attr.c: void git_check_attr(struct index_state *istate,
      		const char *name = check->all_attrs[i].attr->name;
     
      ## attr.h ##
    +@@
    + #ifndef ATTR_H
    + #define ATTR_H
    + 
    ++#include "hash.h"
    ++
    + /**
    +  * gitattributes mechanism gives a uniform way to associate various attributes
    +  * to set of paths.
     @@ attr.h: void attr_check_free(struct attr_check *check);
      const char *git_attr_name(const struct git_attr *);
      
    @@ builtin/check-attr.c
      static const char * const check_attr_usage[] = {
     -N_("git check-attr [-a | --all | <attr>...] [--] <pathname>..."),
     -N_("git check-attr --stdin [-z] [-a | --all | <attr>...]"),
    -+N_("git check-attr [--source <tree>] [-a | --all | <attr>...] [--] <pathname>..."),
    -+N_("git check-attr --stdin [-z] [--source <tree>] [-a | --all | <attr>...]"),
    ++N_("git check-attr [--source <tree-ish>] [-a | --all | <attr>...] [--] <pathname>..."),
    ++N_("git check-attr --stdin [-z] [--source <tree-ish>] [-a | --all | <attr>...]"),
      NULL
      };
      
    @@ t/t0003-attributes.sh: attr_check_quote () {
      
     +	git $git_opts check-attr --source $source test -- "$path" >actual 2>err &&
     +	echo "$path: test: $expect" >expect &&
    -+	test_cmp expect actual
    ++	test_cmp expect actual &&
     +	test_must_be_empty err
      }
      
    @@ t/t0003-attributes.sh: test_expect_success 'setup' '
      
     +test_expect_success 'setup branches' '
     +	mkdir -p foo/bar &&
    -+	test_commit --printf "add .gitattributes" foo/bar/.gitattribute \
    ++	test_commit --printf "add .gitattributes" foo/bar/.gitattributes \
     +		"f test=f\na/i test=n\n" tag-1 &&
    -+
    -+	mkdir -p foo/bar &&
    -+	test_commit --printf "add .gitattributes" foo/bar/.gitattribute \
    -+		"g test=g\na/i test=m\n" tag-2
    ++	test_commit --printf "add .gitattributes" foo/bar/.gitattributes \
    ++		"g test=g\na/i test=m\n" tag-2 &&
    ++	rm foo/bar/.gitattributes
     +'
     +
      test_expect_success 'command line checks' '

Karthik Nayak (2):
  t0003: move setup for `--all` into new block
  attr: add flag `--source` to work with tree-ish

 Documentation/git-check-attr.txt |  9 ++-
 archive.c                        |  2 +-
 attr.c                           | 97 +++++++++++++++++++++++---------
 attr.h                           |  7 ++-
 builtin/check-attr.c             | 35 +++++++-----
 builtin/pack-objects.c           |  2 +-
 convert.c                        |  2 +-
 ll-merge.c                       |  4 +-
 pathspec.c                       |  2 +-
 t/t0003-attributes.sh            | 48 +++++++++++++++-
 userdiff.c                       |  2 +-
 ws.c                             |  2 +-
 12 files changed, 157 insertions(+), 55 deletions(-)

-- 
2.39.0