mbox series

[0/2] check-attr: add support to work with revisions

Message ID 20221206103736.53909-1-karthik.188@gmail.com (mailing list archive)
Headers show
Series check-attr: add support to work with revisions | expand

Message

karthik nayak Dec. 6, 2022, 10:37 a.m. UTC
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 revision 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 `-r|--revisions` to git-check-attr(1) which
allows us to read gitattributes from the specified revision.

Karthik Nayak (2):
  t0003: move setup for `--all` into new block
  attr: add flag `-r|--revisions` to work with revisions

 archive.c              |   2 +-
 attr.c                 | 120 ++++++++++++++++++++++++++++-------------
 attr.h                 |   7 ++-
 builtin/check-attr.c   |  25 ++++-----
 builtin/pack-objects.c |   2 +-
 convert.c              |   2 +-
 ll-merge.c             |   4 +-
 pathspec.c             |   2 +-
 t/t0003-attributes.sh  |  63 ++++++++++++++++++++--
 userdiff.c             |   2 +-
 ws.c                   |   2 +-
 11 files changed, 170 insertions(+), 61 deletions(-)

Comments

Philip Oakley Dec. 6, 2022, 11:20 a.m. UTC | #1
Hi Karthik ,

On 06/12/2022 10:37, Karthik Nayak wrote:
> 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 revision 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 `-r|--revisions` to git-check-attr(1) which
> allows us to read gitattributes from the specified revision.

Won't this also need a man page update? I don't see any changes to
git/Documentation/git-check-attr.txt.

Philip

>
> Karthik Nayak (2):
>   t0003: move setup for `--all` into new block
>   attr: add flag `-r|--revisions` to work with revisions
>
>  archive.c              |   2 +-
>  attr.c                 | 120 ++++++++++++++++++++++++++++-------------
>  attr.h                 |   7 ++-
>  builtin/check-attr.c   |  25 ++++-----
>  builtin/pack-objects.c |   2 +-
>  convert.c              |   2 +-
>  ll-merge.c             |   4 +-
>  pathspec.c             |   2 +-
>  t/t0003-attributes.sh  |  63 ++++++++++++++++++++--
>  userdiff.c             |   2 +-
>  ws.c                   |   2 +-
>  11 files changed, 170 insertions(+), 61 deletions(-)
>
karthik nayak Dec. 6, 2022, 1 p.m. UTC | #2
Hey Philip,

On Tue, Dec 6, 2022 at 12:20 PM Philip Oakley <philipoakley@iee.email> wrote:
>
> Won't this also need a man page update? I don't see any changes to
> git/Documentation/git-check-attr.txt.
>

You're right, I totally missed that, will add it to the v2 of the
series. Thanks!

- Karthik
Taylor Blau Dec. 7, 2022, 1:09 a.m. UTC | #3
On Tue, Dec 06, 2022 at 11:37:34AM +0100, Karthik Nayak wrote:
> This series aims to add a new flag `-r|--revisions` to git-check-attr(1) which
> allows us to read gitattributes from the specified revision.

I haven't looked at the patches below yet, so take my $.02 with a grain
of salt, but I have definitely wished for something like this in the
past.

When scripting around to figure out which files at a given revision are
affected by a given attribute, I will often have to resort to writing
something like this when working in a bare repository:

  for repo in $LIST_OF_REPOS
  do
    export GIT_DIR="$repo"

    index="$(mktemp ...)"
		git read-tree --index-output="$index" HEAD 2>/dev/null || continue

    git ls-tree -rz --name-only HEAD |
    GIT_INDEX_FILE="$index" git check-attr --cached --stdin -z $attr |
    ruby -e '
      print $stdin.readlines.join.split("\0").
        each_slice(3).
        select { |path, _, val| val != "unspecified" && val != "unset" }.
        map(&:first).join("\0")
    '
  done

Which is just kind of gross.

I had at one point when writing the above script wished for a '--blob'
source option to check-attr. That might be sensible, but I think being
able to read from an arbitrary revision (looking at all of the relevant
.gitattributes file(s) recursively throughout the tree) is even more
useful, since it allows you to accurately construct the attributes state
in its entirety.

Anyway, my point is that I think that this is a useful feature, and one
that I (and I suspect other users, too) have wished for frequently in
the past.

Thanks,
Taylor
brian m. carlson Dec. 7, 2022, 2:11 a.m. UTC | #4
On 2022-12-07 at 01:09:09, Taylor Blau wrote:
> Anyway, my point is that I think that this is a useful feature, and one
> that I (and I suspect other users, too) have wished for frequently in
> the past.

I fully agree.  This would have come in useful for me many times, and I
can tell you as one of the maintainers of Git LFS that this will be
enormously useful to many users of that tool as well.  I'm glad to see
this series come by.