Teach '--with-tree' option to check-attr
PATCH 1/1 Teach '--with-tree' option to check-attr
Quoted 2 lines · Jakub Narebski
Nb. the ability to read gitattributes from given commit would be useful also for gitweb (the
encodinggitattribute, etc.).
---
2011/9/22 Jakub Narebski <[email protected]>:
Quoted 11 lines
Unfortunately it doesn't seem to be there mechanism to query about state of gitattributes at given commit.
There is a slight problem from the UI point of view of git-check-attr, namely that there are _three_ pieces of information: a place to read .gitattributes from (working tree, index, commit), list of attributes to check (or --all) and list of files (list of paths). You can use "--" to separate _two_ pieces of information.
Nb. the ability to read gitattributes from given commit would be useful also for gitweb (the
encodinggitattribute, etc.).
How's this? Builds on top of js/check-attr-cached.
Documentation/git-check-attr.txt | 4 ++++ builtin/check-attr.c | 33 ++++++++++++++++++++++++++++++++- t/t0003-attributes.sh | 7 +++++++ 3 files changed, 43 insertions(+), 1 deletions(-)
Documentation/git-check-attr.txt +4 -0
@@ -27,6 +27,10 @@ OPTIONS --cached:: Consider `.gitattributes` in the index only, ignoring the working tree. +--with-tree=<tree-ish>:: + Consider .gitattributes in <tree-ish> only, ignoring the working tree + and index. + --stdin:: Read file names from stdin instead of from the command-line.
builtin/check-attr.c +32 -1
@@ -3,10 +3,13 @@#include "attr.h" #include "quote.h" #include "parse-options.h" +#include "tree-walk.h" +#include "unpack-trees.h" static int all_attrs;static int cached_attrs;static int stdin_paths; +static const char *with_tree;static const char *const check_attr_usage[] = {"git check-attr [-a | --all | attr...] [--] pathname..." ,"git check-attr --stdin [-a | --all | attr...] < <list-of-paths>" ,
@@ -18,6 +21,7 @@ static int null_term_line;static const struct option check_attr_options[] = {OPT_BOOLEAN ('a' ,"all" , &all_attrs,"report all attributes set on file" ),OPT_BOOLEAN (0 ,"cached" , &cached_attrs,"use .gitattributes only from the index" ), +OPT_STRING (0 ,"with-tree" , &with_tree,"tree-ish" ,"use .gitattributes only from <tree-ish>" ),OPT_BOOLEAN (0 ,"stdin" , &stdin_paths,"read file names from stdin" ),OPT_BOOLEAN ('z' ,NULL , &null_term_line,"input paths are terminated by a null character" ),
@@ -101,8 +105,35 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)die ("invalid cache" ); } -if (cached_attrs) +if (cached_attrs && with_tree) +error_with_usage ("Cannot use --cached and --with-tree together" ); + +if (cached_attrs) {git_attr_set_direction (GIT_ATTR_INDEX ,NULL ); + }else if (with_tree) { +unsigned char sha1[20 ]; +struct tree *tree; +struct unpack_trees_options opts; +struct tree_desc t; + +if (get_sha1 (with_tree, sha1)) +die ("Not a valid object name" ); + + tree =parse_tree_indirect (sha1); +if (tree ==NULL ) +die ("Not a tree object" ); + +memset (&opts,0 ,sizeof (opts)); + opts.index_only =1 ; + opts.head_idx =-1 ; + opts.src_index = &the_index; + opts.dst_index = &the_index; + opts.fn = oneway_merge; +init_tree_desc (&t, tree->buffer, tree->size); +if (unpack_trees (1 , &t, &opts)) +return -1 ; +git_attr_set_direction (GIT_ATTR_INDEX , &the_index); + } doubledash =-1 ;for (i =0 ; doubledash <0 && i < argc; i++) {
t/t0003-attributes.sh +7 -0
@@ -140,6 +140,7 @@ test_expect_success 'root subdir attribute test' ' ' test_expect_success 'setup bare' ' + git commit -m ".gitattributes for testing --with-tree below" && git clone --bare . bare.git && cd bare.git '
@@ -163,6 +164,12 @@ test_expect_success 'bare repository: check that --cached honors index' ' test_cmp ../specified-all actual ' +test_expect_success 'bare repository: check --with-tree' ' + git check-attr --with-tree=HEAD --stdin --all < ../stdin-all | + sort > actual && + test_cmp ../specified-all actual +' + test_expect_success 'bare repository: test info/attributes' ' ( echo "f test=f"
Signature · 1 line
1.7.7.rc2.5.g12a2f