* [PATCH v3 08/23] git-check-attr: Use git_attr_name()
From: Michael Haggerty @ 2011-08-04 4:36 UTC (permalink / raw)
To: git; +Cc: gitster, Michael Haggerty
In-Reply-To: <1312432593-9841-1-git-send-email-mhagger@alum.mit.edu>
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
builtin/check-attr.c | 13 ++++++-------
1 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/builtin/check-attr.c b/builtin/check-attr.c
index 3016d29..5f04126 100644
--- a/builtin/check-attr.c
+++ b/builtin/check-attr.c
@@ -21,7 +21,7 @@ static const struct option check_attr_options[] = {
};
static void check_attr(int cnt, struct git_attr_check *check,
- const char** name, const char *file)
+ const char *file)
{
int j;
if (git_checkattr(file, cnt, check))
@@ -37,12 +37,11 @@ static void check_attr(int cnt, struct git_attr_check *check,
value = "unspecified";
quote_c_style(file, NULL, stdout, 0);
- printf(": %s: %s\n", name[j], value);
+ printf(": %s: %s\n", git_attr_name(check[j].attr), value);
}
}
-static void check_attr_stdin_paths(int cnt, struct git_attr_check *check,
- const char** name)
+static void check_attr_stdin_paths(int cnt, struct git_attr_check *check)
{
struct strbuf buf, nbuf;
int line_termination = null_term_line ? 0 : '\n';
@@ -56,7 +55,7 @@ static void check_attr_stdin_paths(int cnt, struct git_attr_check *check,
die("line is badly quoted");
strbuf_swap(&buf, &nbuf);
}
- check_attr(cnt, check, name, buf.buf);
+ check_attr(cnt, check, buf.buf);
maybe_flush_or_die(stdout, "attribute to stdout");
}
strbuf_release(&buf);
@@ -113,10 +112,10 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
}
if (stdin_paths)
- check_attr_stdin_paths(cnt, check, argv);
+ check_attr_stdin_paths(cnt, check);
else {
for (i = doubledash; i < argc; i++)
- check_attr(cnt, check, argv, argv[i]);
+ check_attr(cnt, check, argv[i]);
maybe_flush_or_die(stdout, "attribute to stdout");
}
return 0;
--
1.7.6.8.gd2879
^ permalink raw reply related
* [PATCH v3 01/23] doc: Add a link from gitattributes(5) to git-check-attr(1)
From: Michael Haggerty @ 2011-08-04 4:36 UTC (permalink / raw)
To: git; +Cc: gitster, Michael Haggerty
In-Reply-To: <1312432593-9841-1-git-send-email-mhagger@alum.mit.edu>
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
Documentation/gitattributes.txt | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
index 2bbe76b..25e46ae 100644
--- a/Documentation/gitattributes.txt
+++ b/Documentation/gitattributes.txt
@@ -955,6 +955,9 @@ frotz unspecified
----------------------------------------------------------------
+SEE ALSO
+--------
+linkgit:git-check-attr[1].
GIT
---
--
1.7.6.8.gd2879
^ permalink raw reply related
* [PATCH v3 12/23] Remove redundant check
From: Michael Haggerty @ 2011-08-04 4:36 UTC (permalink / raw)
To: git; +Cc: gitster, Michael Haggerty
In-Reply-To: <1312432593-9841-1-git-send-email-mhagger@alum.mit.edu>
bootstrap_attr_stack() also checks whether attr_stack is already set.
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
attr.c | 3 +--
1 files changed, 1 insertions(+), 2 deletions(-)
diff --git a/attr.c b/attr.c
index b8ce158..ab30c81 100644
--- a/attr.c
+++ b/attr.c
@@ -565,8 +565,7 @@ static void prepare_attr_stack(const char *path)
* .gitattributes in deeper directories to shallower ones,
* and finally use the built-in set as the default.
*/
- if (!attr_stack)
- bootstrap_attr_stack();
+ bootstrap_attr_stack();
/*
* Pop the "info" one that is always at the top of the stack.
--
1.7.6.8.gd2879
^ permalink raw reply related
* [PATCH v3 15/23] git-check-attr: Introduce a new variable
From: Michael Haggerty @ 2011-08-04 4:36 UTC (permalink / raw)
To: git; +Cc: gitster, Michael Haggerty
In-Reply-To: <1312432593-9841-1-git-send-email-mhagger@alum.mit.edu>
Avoid reusing variable "doubledash" to mean something other than the
expected "position of a double-dash, if any".
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
builtin/check-attr.c | 13 +++++++------
1 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/builtin/check-attr.c b/builtin/check-attr.c
index 384c5a6..c527078 100644
--- a/builtin/check-attr.c
+++ b/builtin/check-attr.c
@@ -71,7 +71,7 @@ static void check_attr_stdin_paths(int cnt, struct git_attr_check *check)
int cmd_check_attr(int argc, const char **argv, const char *prefix)
{
struct git_attr_check *check;
- int cnt, i, doubledash;
+ int cnt, i, doubledash, filei;
const char *errstr = NULL;
argc = parse_options(argc, argv, prefix, check_attr_options,
@@ -92,14 +92,15 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
/* If there is no double dash, we handle only one attribute */
if (doubledash < 0) {
cnt = 1;
- doubledash = 0;
- } else
+ filei = 1;
+ } else {
cnt = doubledash;
- doubledash++;
+ filei = doubledash + 1;
+ }
if (cnt <= 0)
errstr = "No attribute specified";
- else if (stdin_paths && doubledash < argc)
+ else if (stdin_paths && filei < argc)
errstr = "Can't specify files with --stdin";
if (errstr) {
error("%s", errstr);
@@ -120,7 +121,7 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
if (stdin_paths)
check_attr_stdin_paths(cnt, check);
else {
- for (i = doubledash; i < argc; i++)
+ for (i = filei; i < argc; i++)
check_attr(cnt, check, argv[i]);
maybe_flush_or_die(stdout, "attribute to stdout");
}
--
1.7.6.8.gd2879
^ permalink raw reply related
* [PATCH v3 16/23] git-check-attr: Extract a function error_with_usage()
From: Michael Haggerty @ 2011-08-04 4:36 UTC (permalink / raw)
To: git; +Cc: gitster, Michael Haggerty
In-Reply-To: <1312432593-9841-1-git-send-email-mhagger@alum.mit.edu>
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
builtin/check-attr.c | 9 +++++++--
1 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/builtin/check-attr.c b/builtin/check-attr.c
index c527078..d004222 100644
--- a/builtin/check-attr.c
+++ b/builtin/check-attr.c
@@ -68,6 +68,12 @@ static void check_attr_stdin_paths(int cnt, struct git_attr_check *check)
strbuf_release(&nbuf);
}
+static NORETURN void error_with_usage(const char *msg)
+{
+ error("%s", msg);
+ usage_with_options(check_attr_usage, check_attr_options);
+}
+
int cmd_check_attr(int argc, const char **argv, const char *prefix)
{
struct git_attr_check *check;
@@ -103,8 +109,7 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
else if (stdin_paths && filei < argc)
errstr = "Can't specify files with --stdin";
if (errstr) {
- error("%s", errstr);
- usage_with_options(check_attr_usage, check_attr_options);
+ error_with_usage(errstr);
}
check = xcalloc(cnt, sizeof(*check));
--
1.7.6.8.gd2879
^ permalink raw reply related
* [PATCH v3 17/23] git-check-attr: Handle each error separately
From: Michael Haggerty @ 2011-08-04 4:36 UTC (permalink / raw)
To: git; +Cc: gitster, Michael Haggerty
In-Reply-To: <1312432593-9841-1-git-send-email-mhagger@alum.mit.edu>
This will make the code easier to refactor.
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
builtin/check-attr.c | 11 ++++-------
1 files changed, 4 insertions(+), 7 deletions(-)
diff --git a/builtin/check-attr.c b/builtin/check-attr.c
index d004222..de3fef7 100644
--- a/builtin/check-attr.c
+++ b/builtin/check-attr.c
@@ -78,7 +78,6 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
{
struct git_attr_check *check;
int cnt, i, doubledash, filei;
- const char *errstr = NULL;
argc = parse_options(argc, argv, prefix, check_attr_options,
check_attr_usage, PARSE_OPT_KEEP_DASHDASH);
@@ -105,12 +104,10 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
}
if (cnt <= 0)
- errstr = "No attribute specified";
- else if (stdin_paths && filei < argc)
- errstr = "Can't specify files with --stdin";
- if (errstr) {
- error_with_usage(errstr);
- }
+ error_with_usage("No attribute specified");
+
+ if (stdin_paths && filei < argc)
+ error_with_usage("Can't specify files with --stdin");
check = xcalloc(cnt, sizeof(*check));
for (i = 0; i < cnt; i++) {
--
1.7.6.8.gd2879
^ permalink raw reply related
* [PATCH v3 18/23] git-check-attr: Process command-line args more systematically
From: Michael Haggerty @ 2011-08-04 4:36 UTC (permalink / raw)
To: git; +Cc: gitster, Michael Haggerty
In-Reply-To: <1312432593-9841-1-git-send-email-mhagger@alum.mit.edu>
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
builtin/check-attr.c | 19 ++++++++++++-------
1 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/builtin/check-attr.c b/builtin/check-attr.c
index de3fef7..e9b827f 100644
--- a/builtin/check-attr.c
+++ b/builtin/check-attr.c
@@ -81,8 +81,6 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
argc = parse_options(argc, argv, prefix, check_attr_options,
check_attr_usage, PARSE_OPT_KEEP_DASHDASH);
- if (!argc)
- usage_with_options(check_attr_usage, check_attr_options);
if (read_cache() < 0) {
die("invalid cache");
@@ -94,8 +92,17 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
doubledash = i;
}
- /* If there is no double dash, we handle only one attribute */
- if (doubledash < 0) {
+ /* Check attribute argument(s): */
+ if (doubledash == 0) {
+ error_with_usage("No attribute specified");
+ } else if (doubledash < 0) {
+ /*
+ * There is no double dash; treat the first
+ * argument as an attribute.
+ */
+ if (!argc)
+ error_with_usage("No attribute specified");
+
cnt = 1;
filei = 1;
} else {
@@ -103,9 +110,7 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
filei = doubledash + 1;
}
- if (cnt <= 0)
- error_with_usage("No attribute specified");
-
+ /* Check file argument(s): */
if (stdin_paths && filei < argc)
error_with_usage("Can't specify files with --stdin");
--
1.7.6.8.gd2879
^ permalink raw reply related
* [PATCH v3 21/23] git-check-attr: Drive two tests using the same raw data
From: Michael Haggerty @ 2011-08-04 4:36 UTC (permalink / raw)
To: git; +Cc: gitster, Michael Haggerty
In-Reply-To: <1312432593-9841-1-git-send-email-mhagger@alum.mit.edu>
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
t/t0003-attributes.sh | 59 +++++++++++++++++++-----------------------------
1 files changed, 23 insertions(+), 36 deletions(-)
diff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh
index 8892ba3..a49f8a9 100755
--- a/t/t0003-attributes.sh
+++ b/t/t0003-attributes.sh
@@ -38,7 +38,25 @@ test_expect_success 'setup' '
) >a/b/.gitattributes &&
(
echo "global test=global"
- ) >"$HOME"/global-gitattributes
+ ) >"$HOME"/global-gitattributes &&
+ cat <<EOF >expect-all
+f: test: f
+a/f: test: f
+a/c/f: test: f
+a/g: test: a/g
+a/b/g: test: a/b/g
+b/g: test: unspecified
+a/b/h: test: a/b/h
+a/b/d/g: test: a/b/d/*
+onoff: test: unset
+offon: test: set
+no: notest: set
+no: test: unspecified
+a/b/d/no: notest: set
+a/b/d/no: test: a/b/d/*
+a/b/d/yes: notest: set
+a/b/d/yes: test: unspecified
+EOF
'
@@ -87,47 +105,16 @@ test_expect_success 'core.attributesfile' '
test_expect_success 'attribute test: read paths from stdin' '
- cat <<EOF > expect &&
-f: test: f
-a/f: test: f
-a/c/f: test: f
-a/g: test: a/g
-a/b/g: test: a/b/g
-b/g: test: unspecified
-a/b/h: test: a/b/h
-a/b/d/g: test: a/b/d/*
-onoff: test: unset
-offon: test: set
-no: test: unspecified
-a/b/d/no: test: a/b/d/*
-a/b/d/yes: test: unspecified
-EOF
-
+ grep -v notest < expect-all > expect &&
sed -e "s/:.*//" < expect | git check-attr --stdin test > actual &&
test_cmp expect actual
'
test_expect_success 'attribute test: --all option' '
- cat <<EOF > all &&
-f: test: f
-a/f: test: f
-a/c/f: test: f
-a/g: test: a/g
-a/b/g: test: a/b/g
-b/g: test: unspecified
-a/b/h: test: a/b/h
-a/b/d/g: test: a/b/d/*
-onoff: test: unset
-offon: test: set
-no: notest: set
-a/b/d/no: test: a/b/d/*
-a/b/d/no: notest: set
-a/b/d/yes: notest: set
-EOF
-
- grep -v unspecified < all | sort > expect &&
- sed -e "s/:.*//" < all | uniq | git check-attr --stdin --all | sort > actual &&
+ grep -v unspecified < expect-all | sort > expect &&
+ sed -e "s/:.*//" < expect-all | uniq |
+ git check-attr --stdin --all | sort > actual &&
test_cmp expect actual
'
--
1.7.6.8.gd2879
^ permalink raw reply related
* [PATCH v3 22/23] git-check-attr: Fix command-line handling to match docs
From: Michael Haggerty @ 2011-08-04 4:36 UTC (permalink / raw)
To: git; +Cc: gitster, Michael Haggerty
In-Reply-To: <1312432593-9841-1-git-send-email-mhagger@alum.mit.edu>
According to the git-check-attr synopsis, if the '--stdin' option is
used then no pathnames are expected on the command line. Change the
behavior to match this description; namely, if '--stdin' is used but
not '--', then treat all command-line arguments as attribute names.
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
Documentation/git-check-attr.txt | 7 +++++--
builtin/check-attr.c | 15 +++++++++------
t/t0003-attributes.sh | 1 -
3 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/Documentation/git-check-attr.txt b/Documentation/git-check-attr.txt
index 798e5d5..1f7312a 100644
--- a/Documentation/git-check-attr.txt
+++ b/Documentation/git-check-attr.txt
@@ -33,8 +33,11 @@ OPTIONS
\--::
Interpret all preceding arguments as attributes and all following
- arguments as path names. If not supplied, only the first argument will
- be treated as an attribute.
+ arguments as path names.
+
+If none of `--stdin`, `--all`, or `--` is used, the first argument
+will be treated as an attribute and the rest of the arguments as
+pathnames.
OUTPUT
------
diff --git a/builtin/check-attr.c b/builtin/check-attr.c
index b0d2ebc..f20772a 100644
--- a/builtin/check-attr.c
+++ b/builtin/check-attr.c
@@ -111,15 +111,18 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
} else if (doubledash == 0) {
error_with_usage("No attribute specified");
} else if (doubledash < 0) {
- /*
- * There is no double dash; treat the first
- * argument as an attribute.
- */
if (!argc)
error_with_usage("No attribute specified");
- cnt = 1;
- filei = 1;
+ if (stdin_paths) {
+ /* Treat all arguments as attribute names. */
+ cnt = argc;
+ filei = argc;
+ } else {
+ /* Treat exactly one argument as an attribute name. */
+ cnt = 1;
+ filei = 1;
+ }
} else {
cnt = doubledash;
filei = doubledash + 1;
diff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh
index a49f8a9..5acb2d5 100755
--- a/t/t0003-attributes.sh
+++ b/t/t0003-attributes.sh
@@ -70,7 +70,6 @@ test_expect_success 'command line checks' '
echo "f" | test_must_fail git check-attr --stdin &&
echo "f" | test_must_fail git check-attr --stdin -- f &&
echo "f" | test_must_fail git check-attr --stdin test -- f &&
- echo "f" | test_must_fail git check-attr --stdin test f &&
test_must_fail git check-attr "" -- f
'
--
1.7.6.8.gd2879
^ permalink raw reply related
* [PATCH v3 20/23] git-check-attr: Add an --all option to show all attributes
From: Michael Haggerty @ 2011-08-04 4:36 UTC (permalink / raw)
To: git; +Cc: gitster, Michael Haggerty
In-Reply-To: <1312432593-9841-1-git-send-email-mhagger@alum.mit.edu>
Add new usage patterns
git check-attr [-a | --all] [--] pathname...
git check-attr --stdin [-a | --all] < <list-of-paths>
which display all attributes associated with the specified file(s).
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
Documentation/git-check-attr.txt | 16 ++++++++++-
builtin/check-attr.c | 52 ++++++++++++++++++++++++++-----------
t/t0003-attributes.sh | 24 +++++++++++++++++
3 files changed, 74 insertions(+), 18 deletions(-)
diff --git a/Documentation/git-check-attr.txt b/Documentation/git-check-attr.txt
index 30eca6c..798e5d5 100644
--- a/Documentation/git-check-attr.txt
+++ b/Documentation/git-check-attr.txt
@@ -9,8 +9,8 @@ git-check-attr - Display gitattributes information
SYNOPSIS
--------
[verse]
-'git check-attr' attr... [--] pathname...
-'git check-attr' --stdin [-z] attr... < <list-of-paths>
+'git check-attr' [-a | --all | attr...] [--] pathname...
+'git check-attr' --stdin [-z] [-a | --all | attr...] < <list-of-paths>
DESCRIPTION
-----------
@@ -19,6 +19,11 @@ For every pathname, this command will list if each attribute is 'unspecified',
OPTIONS
-------
+-a, --all::
+ List all attributes that are associated with the specified
+ paths. If this option is used, then 'unspecified' attributes
+ will not be included in the output.
+
--stdin::
Read file names from stdin instead of from the command-line.
@@ -69,6 +74,13 @@ org/example/MyClass.java: diff: java
org/example/MyClass.java: myAttr: set
---------------
+* Listing all attributes for a file:
+---------------
+$ git check-attr --all -- org/example/MyClass.java
+org/example/MyClass.java: diff: java
+org/example/MyClass.java: myAttr: set
+---------------
+
* Listing an attribute for multiple files:
---------------
$ git check-attr myAttr -- org/example/MyClass.java org/example/NoMyAttr.java
diff --git a/builtin/check-attr.c b/builtin/check-attr.c
index 6cf6421..b0d2ebc 100644
--- a/builtin/check-attr.c
+++ b/builtin/check-attr.c
@@ -4,16 +4,18 @@
#include "quote.h"
#include "parse-options.h"
+static int all_attrs;
static int stdin_paths;
static const char * const check_attr_usage[] = {
-"git check-attr attr... [--] pathname...",
-"git check-attr --stdin attr... < <list-of-paths>",
+"git check-attr [-a | --all | attr...] [--] pathname...",
+"git check-attr --stdin [-a | --all | attr...] < <list-of-paths>",
NULL
};
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 , "stdin", &stdin_paths, "read file names from stdin"),
OPT_BOOLEAN('z', NULL, &null_term_line,
"input paths are terminated by a null character"),
@@ -42,9 +44,16 @@ static void output_attr(int cnt, struct git_attr_check *check,
static void check_attr(int cnt, struct git_attr_check *check,
const char *file)
{
- if (git_checkattr(file, cnt, check))
- die("git_checkattr died");
- output_attr(cnt, check, file);
+ if (check != NULL) {
+ if (git_checkattr(file, cnt, check))
+ die("git_checkattr died");
+ output_attr(cnt, check, file);
+ } else {
+ if (git_all_attrs(file, &cnt, &check))
+ die("git_all_attrs died");
+ output_attr(cnt, check, file);
+ free(check);
+ }
}
static void check_attr_stdin_paths(int cnt, struct git_attr_check *check)
@@ -92,8 +101,14 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
doubledash = i;
}
- /* Check attribute argument(s): */
- if (doubledash == 0) {
+ /* Process --all and/or attribute arguments: */
+ if (all_attrs) {
+ if (doubledash >= 1)
+ error_with_usage("Attributes and --all both specified");
+
+ cnt = 0;
+ filei = doubledash + 1;
+ } else if (doubledash == 0) {
error_with_usage("No attribute specified");
} else if (doubledash < 0) {
/*
@@ -119,15 +134,20 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
error_with_usage("No file specified");
}
- check = xcalloc(cnt, sizeof(*check));
- for (i = 0; i < cnt; i++) {
- const char *name;
- struct git_attr *a;
- name = argv[i];
- a = git_attr(name);
- if (!a)
- return error("%s: not a valid attribute name", name);
- check[i].attr = a;
+ if (all_attrs) {
+ check = NULL;
+ } else {
+ check = xcalloc(cnt, sizeof(*check));
+ for (i = 0; i < cnt; i++) {
+ const char *name;
+ struct git_attr *a;
+ name = argv[i];
+ a = git_attr(name);
+ if (!a)
+ return error("%s: not a valid attribute name",
+ name);
+ check[i].attr = a;
+ }
}
if (stdin_paths)
diff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh
index 2254005..8892ba3 100755
--- a/t/t0003-attributes.sh
+++ b/t/t0003-attributes.sh
@@ -107,6 +107,30 @@ EOF
test_cmp expect actual
'
+test_expect_success 'attribute test: --all option' '
+
+ cat <<EOF > all &&
+f: test: f
+a/f: test: f
+a/c/f: test: f
+a/g: test: a/g
+a/b/g: test: a/b/g
+b/g: test: unspecified
+a/b/h: test: a/b/h
+a/b/d/g: test: a/b/d/*
+onoff: test: unset
+offon: test: set
+no: notest: set
+a/b/d/no: test: a/b/d/*
+a/b/d/no: notest: set
+a/b/d/yes: notest: set
+EOF
+
+ grep -v unspecified < all | sort > expect &&
+ sed -e "s/:.*//" < all | uniq | git check-attr --stdin --all | sort > actual &&
+ test_cmp expect actual
+'
+
test_expect_success 'root subdir attribute test' '
attr_check a/i a/i &&
--
1.7.6.8.gd2879
^ permalink raw reply related
* [PATCH v3 19/23] git-check-attr: Error out if no pathnames are specified
From: Michael Haggerty @ 2011-08-04 4:36 UTC (permalink / raw)
To: git; +Cc: gitster, Michael Haggerty
In-Reply-To: <1312432593-9841-1-git-send-email-mhagger@alum.mit.edu>
If no pathnames are passed as command-line arguments and the --stdin
option is not specified, fail with the error message "No file
specified". Add tests of this behavior.
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
builtin/check-attr.c | 9 +++++++--
t/t0003-attributes.sh | 2 ++
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/builtin/check-attr.c b/builtin/check-attr.c
index e9b827f..6cf6421 100644
--- a/builtin/check-attr.c
+++ b/builtin/check-attr.c
@@ -111,8 +111,13 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
}
/* Check file argument(s): */
- if (stdin_paths && filei < argc)
- error_with_usage("Can't specify files with --stdin");
+ if (stdin_paths) {
+ if (filei < argc)
+ error_with_usage("Can't specify files with --stdin");
+ } else {
+ if (filei >= argc)
+ error_with_usage("No file specified");
+ }
check = xcalloc(cnt, sizeof(*check));
for (i = 0; i < cnt; i++) {
diff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh
index f1debeb..2254005 100755
--- a/t/t0003-attributes.sh
+++ b/t/t0003-attributes.sh
@@ -46,6 +46,8 @@ test_expect_success 'command line checks' '
test_must_fail git check-attr &&
test_must_fail git check-attr -- &&
+ test_must_fail git check-attr test &&
+ test_must_fail git check-attr test -- &&
test_must_fail git check-attr -- f &&
echo "f" | test_must_fail git check-attr --stdin &&
echo "f" | test_must_fail git check-attr --stdin -- f &&
--
1.7.6.8.gd2879
^ permalink raw reply related
* [PATCH v3 13/23] Allow querying all attributes on a file
From: Michael Haggerty @ 2011-08-04 4:36 UTC (permalink / raw)
To: git; +Cc: gitster, Michael Haggerty
In-Reply-To: <1312432593-9841-1-git-send-email-mhagger@alum.mit.edu>
Add a function, git_all_attrs(), that reports on all attributes that
are set on a path.
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
Documentation/technical/api-gitattributes.txt | 46 +++++++++++++++++-------
attr.c | 28 +++++++++++++++
attr.h | 9 +++++
3 files changed, 69 insertions(+), 14 deletions(-)
diff --git a/Documentation/technical/api-gitattributes.txt b/Documentation/technical/api-gitattributes.txt
index ab3a84d..3bd2f57 100644
--- a/Documentation/technical/api-gitattributes.txt
+++ b/Documentation/technical/api-gitattributes.txt
@@ -22,19 +22,6 @@ Data Structure
to `git_checkattr()` function, and receives the results.
-Calling Sequence
-----------------
-
-* Prepare an array of `struct git_attr_check` to define the list of
- attributes you would want to check. To populate this array, you would
- need to define necessary attributes by calling `git_attr()` function.
-
-* Call git_checkattr() to check the attributes for the path.
-
-* Inspect `git_attr_check` structure to see how each of the attribute in
- the array is defined for the path.
-
-
Attribute Values
----------------
@@ -58,6 +45,19 @@ If none of the above returns true, `.value` member points at a string
value of the attribute for the path.
+Querying Specific Attributes
+----------------------------
+
+* Prepare an array of `struct git_attr_check` to define the list of
+ attributes you would want to check. To populate this array, you would
+ need to define necessary attributes by calling `git_attr()` function.
+
+* Call `git_checkattr()` to check the attributes for the path.
+
+* Inspect `git_attr_check` structure to see how each of the attribute in
+ the array is defined for the path.
+
+
Example
-------
@@ -109,4 +109,22 @@ static void setup_check(void)
}
------------
-(JC)
+
+Querying All Attributes
+-----------------------
+
+To get the values of all attributes associated with a file:
+
+* Call `git_all_attrs()`, which returns an array of `git_attr_check`
+ structures.
+
+* Iterate over the `git_attr_check` array to examine the attribute
+ names and values. The name of the attribute described by a
+ `git_attr_check` object can be retrieved via
+ `git_attr_name(check[i].attr)`. (Please note that no items will be
+ returned for unset attributes, so `ATTR_UNSET()` will return false
+ for all returned `git_array_check` objects.)
+
+* Free the `git_array_check` array.
+
+
diff --git a/attr.c b/attr.c
index ab30c81..658112e 100644
--- a/attr.c
+++ b/attr.c
@@ -747,6 +747,34 @@ int git_checkattr(const char *path, int num, struct git_attr_check *check)
return 0;
}
+int git_all_attrs(const char *path, int *num, struct git_attr_check **check)
+{
+ int i, count, j;
+
+ collect_all_attrs(path);
+
+ /* Count the number of attributes that are set. */
+ count = 0;
+ for (i = 0; i < attr_nr; i++) {
+ const char *value = check_all_attr[i].value;
+ if (value != ATTR__UNSET && value != ATTR__UNKNOWN)
+ ++count;
+ }
+ *num = count;
+ *check = xmalloc(sizeof(**check) * count);
+ j = 0;
+ for (i = 0; i < attr_nr; i++) {
+ const char *value = check_all_attr[i].value;
+ if (value != ATTR__UNSET && value != ATTR__UNKNOWN) {
+ (*check)[j].attr = check_all_attr[i].attr;
+ (*check)[j].value = value;
+ ++j;
+ }
+ }
+
+ return 0;
+}
+
void git_attr_set_direction(enum git_attr_direction new, struct index_state *istate)
{
enum git_attr_direction old = direction;
diff --git a/attr.h b/attr.h
index d4f875a..9e22893 100644
--- a/attr.h
+++ b/attr.h
@@ -38,6 +38,15 @@ char *git_attr_name(struct git_attr *);
int git_checkattr(const char *path, int, struct git_attr_check *);
+/*
+ * Retrieve all attributes that apply to the specified path. *num
+ * will be set the the number of attributes on the path; **check will
+ * be set to point at a newly-allocated array of git_attr_check
+ * objects describing the attributes and their values. *check must be
+ * free()ed by the caller.
+ */
+int git_all_attrs(const char *path, int *num, struct git_attr_check **check);
+
enum git_attr_direction {
GIT_ATTR_CHECKIN,
GIT_ATTR_CHECKOUT,
--
1.7.6.8.gd2879
^ permalink raw reply related
* [PATCH v3 23/23] Rename git_checkattr() to git_check_attr()
From: Michael Haggerty @ 2011-08-04 4:36 UTC (permalink / raw)
To: git; +Cc: gitster, Michael Haggerty
In-Reply-To: <1312432593-9841-1-git-send-email-mhagger@alum.mit.edu>
Suggested by: Junio Hamano <gitster@pobox.com>
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
Documentation/technical/api-gitattributes.txt | 8 ++++----
archive.c | 2 +-
attr.c | 2 +-
attr.h | 4 ++--
builtin/check-attr.c | 4 ++--
builtin/pack-objects.c | 2 +-
convert.c | 2 +-
ll-merge.c | 4 ++--
userdiff.c | 2 +-
ws.c | 2 +-
10 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/Documentation/technical/api-gitattributes.txt b/Documentation/technical/api-gitattributes.txt
index 3bd2f57..5a1403f 100644
--- a/Documentation/technical/api-gitattributes.txt
+++ b/Documentation/technical/api-gitattributes.txt
@@ -19,7 +19,7 @@ Data Structure
`struct git_attr_check`::
This structure represents a set of attributes to check in a call
- to `git_checkattr()` function, and receives the results.
+ to `git_check_attr()` function, and receives the results.
Attribute Values
@@ -52,7 +52,7 @@ Querying Specific Attributes
attributes you would want to check. To populate this array, you would
need to define necessary attributes by calling `git_attr()` function.
-* Call `git_checkattr()` to check the attributes for the path.
+* Call `git_check_attr()` to check the attributes for the path.
* Inspect `git_attr_check` structure to see how each of the attribute in
the array is defined for the path.
@@ -78,13 +78,13 @@ static void setup_check(void)
}
------------
-. Call `git_checkattr()` with the prepared array of `struct git_attr_check`:
+. Call `git_check_attr()` with the prepared array of `struct git_attr_check`:
------------
const char *path;
setup_check();
- git_checkattr(path, ARRAY_SIZE(check), check);
+ git_check_attr(path, ARRAY_SIZE(check), check);
------------
. Act on `.value` member of the result, left in `check[]`:
diff --git a/archive.c b/archive.c
index 2a7a28e..3fd7f47 100644
--- a/archive.c
+++ b/archive.c
@@ -123,7 +123,7 @@ static int write_archive_entry(const unsigned char *sha1, const char *base,
path_without_prefix = path.buf + args->baselen;
setup_archive_check(check);
- if (!git_checkattr(path_without_prefix, ARRAY_SIZE(check), check)) {
+ if (!git_check_attr(path_without_prefix, ARRAY_SIZE(check), check)) {
if (ATTR_TRUE(check[0].value))
return 0;
convert = ATTR_TRUE(check[1].value);
diff --git a/attr.c b/attr.c
index 658112e..da29c8e 100644
--- a/attr.c
+++ b/attr.c
@@ -731,7 +731,7 @@ static void collect_all_attrs(const char *path)
rem = fill(path, pathlen, stk, rem);
}
-int git_checkattr(const char *path, int num, struct git_attr_check *check)
+int git_check_attr(const char *path, int num, struct git_attr_check *check)
{
int i;
diff --git a/attr.h b/attr.h
index 9e22893..eb8ca0d 100644
--- a/attr.h
+++ b/attr.h
@@ -20,7 +20,7 @@ extern const char git_attr__false[];
#define ATTR_UNSET(v) ((v) == NULL)
/*
- * Send one or more git_attr_check to git_checkattr(), and
+ * Send one or more git_attr_check to git_check_attr(), and
* each 'value' member tells what its value is.
* Unset one is returned as NULL.
*/
@@ -36,7 +36,7 @@ struct git_attr_check {
*/
char *git_attr_name(struct git_attr *);
-int git_checkattr(const char *path, int, struct git_attr_check *);
+int git_check_attr(const char *path, int, struct git_attr_check *);
/*
* Retrieve all attributes that apply to the specified path. *num
diff --git a/builtin/check-attr.c b/builtin/check-attr.c
index f20772a..6b16368 100644
--- a/builtin/check-attr.c
+++ b/builtin/check-attr.c
@@ -45,8 +45,8 @@ static void check_attr(int cnt, struct git_attr_check *check,
const char *file)
{
if (check != NULL) {
- if (git_checkattr(file, cnt, check))
- die("git_checkattr died");
+ if (git_check_attr(file, cnt, check))
+ die("git_check_attr died");
output_attr(cnt, check, file);
} else {
if (git_all_attrs(file, &cnt, &check))
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 84e6daf..ac8bed8 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -634,7 +634,7 @@ static int no_try_delta(const char *path)
struct git_attr_check check[1];
setup_delta_attr_check(check);
- if (git_checkattr(path, ARRAY_SIZE(check), check))
+ if (git_check_attr(path, ARRAY_SIZE(check), check))
return 0;
if (ATTR_FALSE(check->value))
return 1;
diff --git a/convert.c b/convert.c
index 85939c2..416bf83 100644
--- a/convert.c
+++ b/convert.c
@@ -727,7 +727,7 @@ static void convert_attrs(struct conv_attrs *ca, const char *path)
git_config(read_convert_config, NULL);
}
- if (!git_checkattr(path, NUM_CONV_ATTRS, ccheck)) {
+ if (!git_check_attr(path, NUM_CONV_ATTRS, ccheck)) {
ca->crlf_action = git_path_check_crlf(path, ccheck + 4);
if (ca->crlf_action == CRLF_GUESS)
ca->crlf_action = git_path_check_crlf(path, ccheck + 0);
diff --git a/ll-merge.c b/ll-merge.c
index 6ce512e..da59738 100644
--- a/ll-merge.c
+++ b/ll-merge.c
@@ -330,7 +330,7 @@ static int git_path_check_merge(const char *path, struct git_attr_check check[2]
check[0].attr = git_attr("merge");
check[1].attr = git_attr("conflict-marker-size");
}
- return git_checkattr(path, 2, check);
+ return git_check_attr(path, 2, check);
}
static void normalize_file(mmfile_t *mm, const char *path)
@@ -387,7 +387,7 @@ int ll_merge_marker_size(const char *path)
if (!check.attr)
check.attr = git_attr("conflict-marker-size");
- if (!git_checkattr(path, 1, &check) && check.value) {
+ if (!git_check_attr(path, 1, &check) && check.value) {
marker_size = atoi(check.value);
if (marker_size <= 0)
marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
diff --git a/userdiff.c b/userdiff.c
index 01d3a8b..bf553ad 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -270,7 +270,7 @@ struct userdiff_driver *userdiff_find_by_path(const char *path)
if (!path)
return NULL;
- if (git_checkattr(path, 1, &check))
+ if (git_check_attr(path, 1, &check))
return NULL;
if (ATTR_TRUE(check.value))
diff --git a/ws.c b/ws.c
index 9fb9b14..b498d75 100644
--- a/ws.c
+++ b/ws.c
@@ -88,7 +88,7 @@ unsigned whitespace_rule(const char *pathname)
struct git_attr_check attr_whitespace_rule;
setup_whitespace_attr_check(&attr_whitespace_rule);
- if (!git_checkattr(pathname, 1, &attr_whitespace_rule)) {
+ if (!git_check_attr(pathname, 1, &attr_whitespace_rule)) {
const char *value;
value = attr_whitespace_rule.value;
--
1.7.6.8.gd2879
^ permalink raw reply related
* [PATCH v3 14/23] git-check-attr: Extract a function output_attr()
From: Michael Haggerty @ 2011-08-04 4:36 UTC (permalink / raw)
To: git; +Cc: gitster, Michael Haggerty
In-Reply-To: <1312432593-9841-1-git-send-email-mhagger@alum.mit.edu>
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
builtin/check-attr.c | 12 +++++++++---
1 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/builtin/check-attr.c b/builtin/check-attr.c
index 5f04126..384c5a6 100644
--- a/builtin/check-attr.c
+++ b/builtin/check-attr.c
@@ -20,12 +20,10 @@ static const struct option check_attr_options[] = {
OPT_END()
};
-static void check_attr(int cnt, struct git_attr_check *check,
+static void output_attr(int cnt, struct git_attr_check *check,
const char *file)
{
int j;
- if (git_checkattr(file, cnt, check))
- die("git_checkattr died");
for (j = 0; j < cnt; j++) {
const char *value = check[j].value;
@@ -41,6 +39,14 @@ static void check_attr(int cnt, struct git_attr_check *check,
}
}
+static void check_attr(int cnt, struct git_attr_check *check,
+ const char *file)
+{
+ if (git_checkattr(file, cnt, check))
+ die("git_checkattr died");
+ output_attr(cnt, check, file);
+}
+
static void check_attr_stdin_paths(int cnt, struct git_attr_check *check)
{
struct strbuf buf, nbuf;
--
1.7.6.8.gd2879
^ permalink raw reply related
* [PATCH v3 11/23] Remove redundant call to bootstrap_attr_stack()
From: Michael Haggerty @ 2011-08-04 4:36 UTC (permalink / raw)
To: git; +Cc: gitster, Michael Haggerty
In-Reply-To: <1312432593-9841-1-git-send-email-mhagger@alum.mit.edu>
prepare_attr_stack() does the same thing.
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
attr.c | 1 -
1 files changed, 0 insertions(+), 1 deletions(-)
diff --git a/attr.c b/attr.c
index bc589f0..b8ce158 100644
--- a/attr.c
+++ b/attr.c
@@ -722,7 +722,6 @@ static void collect_all_attrs(const char *path)
struct attr_stack *stk;
int i, pathlen, rem;
- bootstrap_attr_stack();
prepare_attr_stack(path);
for (i = 0; i < attr_nr; i++)
check_all_attr[i].value = ATTR__UNKNOWN;
--
1.7.6.8.gd2879
^ permalink raw reply related
* [PATCH v3 10/23] Extract a function collect_all_attrs()
From: Michael Haggerty @ 2011-08-04 4:36 UTC (permalink / raw)
To: git; +Cc: gitster, Michael Haggerty
In-Reply-To: <1312432593-9841-1-git-send-email-mhagger@alum.mit.edu>
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
attr.c | 17 ++++++++++++++---
1 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/attr.c b/attr.c
index 7f0f390..bc589f0 100644
--- a/attr.c
+++ b/attr.c
@@ -713,20 +713,31 @@ static int macroexpand_one(int attr_nr, int rem)
return rem;
}
-int git_checkattr(const char *path, int num, struct git_attr_check *check)
+/*
+ * Collect all attributes for path into the array pointed to by
+ * check_all_attr.
+ */
+static void collect_all_attrs(const char *path)
{
struct attr_stack *stk;
- int pathlen, i, rem;
+ int i, pathlen, rem;
bootstrap_attr_stack();
+ prepare_attr_stack(path);
for (i = 0; i < attr_nr; i++)
check_all_attr[i].value = ATTR__UNKNOWN;
pathlen = strlen(path);
- prepare_attr_stack(path);
rem = attr_nr;
for (stk = attr_stack; 0 < rem && stk; stk = stk->prev)
rem = fill(path, pathlen, stk, rem);
+}
+
+int git_checkattr(const char *path, int num, struct git_attr_check *check)
+{
+ int i;
+
+ collect_all_attrs(path);
for (i = 0; i < num; i++) {
const char *value = check_all_attr[check[i].attr->attr_nr].value;
--
1.7.6.8.gd2879
^ permalink raw reply related
* [PATCH v2 0/6] git-check-attr should work for relative paths
From: Michael Haggerty @ 2011-08-04 4:47 UTC (permalink / raw)
To: git; +Cc: gitster, Michael Haggerty
This is a reroll of the earlier RFC. It must be applied on top of
"Add --all option to git-check-attr" v3.
This re-roll differs in the following ways from the RFC:
* Adjusted for changes between the "--all" patch series v2 -> v3.
* Fixed some C problems found by Junio.
Currently, git-check-attr gets confused if it is passed certain types
of unnormalized paths or is invoked from a non-top-level directory.
For example, using the test repo created by t0003-attributes.sh,
inquiring about a path that starts with "./" causes git-check-attr to
emit a spurious warning:
$ git check-attr test ./f
[attr]notest !test
not allowed: ./.gitattributes:1
./f: test: f
$ git check-attr test ./a/i
[attr]notest !test
not allowed: ./.gitattributes:1
./a/i: test: a/i
In these cases it seems to find the right values, even including the
application of macros from the top-level .gitattributes file. (My
guess is that it is loading the top-level .gitattributes file
twice--once as a top-level file, and once believing that it is in a
subdirectory.)
Invoking git-check-attr from a subdirectory using a relative path
gives incorrect answers; for example:
$ (cd a; git check-attr test i )
i: test: unspecified
(On the other hand, if invoked using the full path of a file, it
"works":
$ (cd a; git check-attr test a/i )
a/i: test: a/i
.) I think that this behavior is confusing and inconsistent with
other git commands. It is also inconsistent with the behavior of
.gitignore, which works from subdirectories.
The patches in this series add tests demonstrating the problem,
propose a possible solution, and add a couple of subcommands to
test-path-utils.
The changes to test-path-utils helped me figure out how the
corresponding functions work (comments? we don't need no stinkin'
comments) but they are not used anywhere. Take 'em or leave 'em.
Michael Haggerty (6):
git-check-attr: test that no output is written to stderr
git-check-attr: Demonstrate problems with unnormalized paths
git-check-attr: Demonstrate problems with relative paths
git-check-attr: Normalize paths
test-path-utils: Add subcommand "absolute_path"
test-path-utils: Add subcommand "prefix_path"
builtin/check-attr.c | 20 ++++++++++++--------
t/t0003-attributes.sh | 29 ++++++++++++++++++++++++++---
test-path-utils.c | 22 ++++++++++++++++++++++
3 files changed, 60 insertions(+), 11 deletions(-)
--
1.7.6.8.gd2879
^ permalink raw reply
* [PATCH v2 1/6] git-check-attr: test that no output is written to stderr
From: Michael Haggerty @ 2011-08-04 4:47 UTC (permalink / raw)
To: git; +Cc: gitster, Michael Haggerty
In-Reply-To: <1312433268-11385-1-git-send-email-mhagger@alum.mit.edu>
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
t/t0003-attributes.sh | 5 +++--
1 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh
index 5acb2d5..4f2fbc0 100755
--- a/t/t0003-attributes.sh
+++ b/t/t0003-attributes.sh
@@ -9,9 +9,10 @@ attr_check () {
path="$1"
expect="$2"
- git check-attr test -- "$path" >actual &&
+ git check-attr test -- "$path" >actual 2>err &&
echo "$path: test: $2" >expect &&
- test_cmp expect actual
+ test_cmp expect actual &&
+ test_line_count = 0 err
}
--
1.7.6.8.gd2879
^ permalink raw reply related
* [PATCH v2 2/6] git-check-attr: Demonstrate problems with unnormalized paths
From: Michael Haggerty @ 2011-08-04 4:47 UTC (permalink / raw)
To: git; +Cc: gitster, Michael Haggerty
In-Reply-To: <1312433268-11385-1-git-send-email-mhagger@alum.mit.edu>
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
t/t0003-attributes.sh | 9 +++++++++
1 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh
index 4f2fbc0..43957ea 100755
--- a/t/t0003-attributes.sh
+++ b/t/t0003-attributes.sh
@@ -93,6 +93,15 @@ test_expect_success 'attribute test' '
'
+test_expect_failure 'unnormalized paths' '
+
+ attr_check ./f f &&
+ attr_check ./a/g a/g &&
+ attr_check a/./g a/g &&
+ attr_check a/c/../b/g a/b/g
+
+'
+
test_expect_success 'core.attributesfile' '
attr_check global unspecified &&
git config core.attributesfile "$HOME/global-gitattributes" &&
--
1.7.6.8.gd2879
^ permalink raw reply related
* [PATCH v2 3/6] git-check-attr: Demonstrate problems with relative paths
From: Michael Haggerty @ 2011-08-04 4:47 UTC (permalink / raw)
To: git; +Cc: gitster, Michael Haggerty
In-Reply-To: <1312433268-11385-1-git-send-email-mhagger@alum.mit.edu>
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
t/t0003-attributes.sh | 15 ++++++++++++++-
1 files changed, 14 insertions(+), 1 deletions(-)
diff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh
index 43957ea..f6cf77d 100755
--- a/t/t0003-attributes.sh
+++ b/t/t0003-attributes.sh
@@ -19,7 +19,7 @@ attr_check () {
test_expect_success 'setup' '
- mkdir -p a/b/d a/c &&
+ mkdir -p a/b/d a/c b &&
(
echo "[attr]notest !test"
echo "f test=f"
@@ -102,6 +102,19 @@ test_expect_failure 'unnormalized paths' '
'
+test_expect_failure 'relative paths' '
+
+ (cd a && attr_check ../f f) &&
+ (cd a && attr_check f f) &&
+ (cd a && attr_check i a/i) &&
+ (cd a && attr_check g a/g) &&
+ (cd a && attr_check b/g a/b/g) &&
+ (cd b && attr_check ../a/f f) &&
+ (cd b && attr_check ../a/g a/g) &&
+ (cd b && attr_check ../a/b/g a/b/g)
+
+'
+
test_expect_success 'core.attributesfile' '
attr_check global unspecified &&
git config core.attributesfile "$HOME/global-gitattributes" &&
--
1.7.6.8.gd2879
^ permalink raw reply related
* [PATCH v2 6/6] test-path-utils: Add subcommand "prefix_path"
From: Michael Haggerty @ 2011-08-04 4:47 UTC (permalink / raw)
To: git; +Cc: gitster, Michael Haggerty
In-Reply-To: <1312433268-11385-1-git-send-email-mhagger@alum.mit.edu>
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
test-path-utils.c | 13 +++++++++++++
1 files changed, 13 insertions(+), 0 deletions(-)
diff --git a/test-path-utils.c b/test-path-utils.c
index a410e30..3bc20e9 100644
--- a/test-path-utils.c
+++ b/test-path-utils.c
@@ -35,6 +35,19 @@ int main(int argc, char **argv)
return 0;
}
+ if (argc >= 4 && !strcmp(argv[1], "prefix_path")) {
+ char *prefix = argv[2];
+ int prefix_len = strlen(prefix);
+ int nongit_ok;
+ setup_git_directory_gently(&nongit_ok);
+ while (argc > 3) {
+ puts(prefix_path(prefix, prefix_len, argv[3]));
+ argc--;
+ argv++;
+ }
+ return 0;
+ }
+
if (argc == 4 && !strcmp(argv[1], "strip_path_suffix")) {
char *prefix = strip_path_suffix(argv[2], argv[3]);
printf("%s\n", prefix ? prefix : "(null)");
--
1.7.6.8.gd2879
^ permalink raw reply related
* [PATCH v2 4/6] git-check-attr: Normalize paths
From: Michael Haggerty @ 2011-08-04 4:47 UTC (permalink / raw)
To: git; +Cc: gitster, Michael Haggerty
In-Reply-To: <1312433268-11385-1-git-send-email-mhagger@alum.mit.edu>
Normalize the path arguments (relative to the working tree root, if
applicable) before looking up their attributes. This requires passing
the prefix down the call chain.
This fixes two test cases for different reasons:
* "unnormalized paths" is fixed because the .gitattribute-file-seeking
code is not confused into reading the top-level file twice.
* "relative paths" is fixed because the canonical pathnames are passed
to get_check_attr() or get_all_attrs(), allowing them to match the
pathname patterns as expected.
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
builtin/check-attr.c | 20 ++++++++++++--------
t/t0003-attributes.sh | 4 ++--
2 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/builtin/check-attr.c b/builtin/check-attr.c
index 6b16368..708988a 100644
--- a/builtin/check-attr.c
+++ b/builtin/check-attr.c
@@ -41,22 +41,26 @@ static void output_attr(int cnt, struct git_attr_check *check,
}
}
-static void check_attr(int cnt, struct git_attr_check *check,
- const char *file)
+static void check_attr(const char *prefix, int cnt,
+ struct git_attr_check *check, const char *file)
{
+ char *full_path =
+ prefix_path(prefix, prefix ? strlen(prefix) : 0, file);
if (check != NULL) {
- if (git_check_attr(file, cnt, check))
+ if (git_check_attr(full_path, cnt, check))
die("git_check_attr died");
output_attr(cnt, check, file);
} else {
- if (git_all_attrs(file, &cnt, &check))
+ if (git_all_attrs(full_path, &cnt, &check))
die("git_all_attrs died");
output_attr(cnt, check, file);
free(check);
}
+ free(full_path);
}
-static void check_attr_stdin_paths(int cnt, struct git_attr_check *check)
+static void check_attr_stdin_paths(const char *prefix, int cnt,
+ struct git_attr_check *check)
{
struct strbuf buf, nbuf;
int line_termination = null_term_line ? 0 : '\n';
@@ -70,7 +74,7 @@ static void check_attr_stdin_paths(int cnt, struct git_attr_check *check)
die("line is badly quoted");
strbuf_swap(&buf, &nbuf);
}
- check_attr(cnt, check, buf.buf);
+ check_attr(prefix, cnt, check, buf.buf);
maybe_flush_or_die(stdout, "attribute to stdout");
}
strbuf_release(&buf);
@@ -154,10 +158,10 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
}
if (stdin_paths)
- check_attr_stdin_paths(cnt, check);
+ check_attr_stdin_paths(prefix, cnt, check);
else {
for (i = filei; i < argc; i++)
- check_attr(cnt, check, argv[i]);
+ check_attr(prefix, cnt, check, argv[i]);
maybe_flush_or_die(stdout, "attribute to stdout");
}
return 0;
diff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh
index f6cf77d..ae2f1da 100755
--- a/t/t0003-attributes.sh
+++ b/t/t0003-attributes.sh
@@ -93,7 +93,7 @@ test_expect_success 'attribute test' '
'
-test_expect_failure 'unnormalized paths' '
+test_expect_success 'unnormalized paths' '
attr_check ./f f &&
attr_check ./a/g a/g &&
@@ -102,7 +102,7 @@ test_expect_failure 'unnormalized paths' '
'
-test_expect_failure 'relative paths' '
+test_expect_success 'relative paths' '
(cd a && attr_check ../f f) &&
(cd a && attr_check f f) &&
--
1.7.6.8.gd2879
^ permalink raw reply related
* [PATCH v2 5/6] test-path-utils: Add subcommand "absolute_path"
From: Michael Haggerty @ 2011-08-04 4:47 UTC (permalink / raw)
To: git; +Cc: gitster, Michael Haggerty
In-Reply-To: <1312433268-11385-1-git-send-email-mhagger@alum.mit.edu>
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
test-path-utils.c | 9 +++++++++
1 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/test-path-utils.c b/test-path-utils.c
index e767159..a410e30 100644
--- a/test-path-utils.c
+++ b/test-path-utils.c
@@ -20,6 +20,15 @@ int main(int argc, char **argv)
return 0;
}
+ if (argc >= 2 && !strcmp(argv[1], "absolute_path")) {
+ while (argc > 2) {
+ puts(absolute_path(argv[2]));
+ argc--;
+ argv++;
+ }
+ return 0;
+ }
+
if (argc == 4 && !strcmp(argv[1], "longest_ancestor_length")) {
int len = longest_ancestor_length(argv[2], argv[3]);
printf("%d\n", len);
--
1.7.6.8.gd2879
^ permalink raw reply related
* Re: [PATCH 17/18] revert: Introduce --continue to continue the operation
From: Christian Couder @ 2011-08-04 4:57 UTC (permalink / raw)
To: Ramkumar Ramachandra
Cc: Junio C Hamano, Git List, Jonathan Nieder, Daniel Barkalow,
Jeff King
In-Reply-To: <1312222025-28453-18-git-send-email-artagnon@gmail.com>
On Monday 01 August 2011 20:07:04 Ramkumar Ramachandra wrote:
>
> +test_expect_success '--continue complains when there are unresolved
> conflicts' '
> + pristine_detach initial &&
> + test_must_fail git cherry-pick base..picked &&
> + test_must_fail git cherry-pick --continue
> +'
When I try to manually run the above test I get:
-----------------------------------
$ pristine_detach initial
Warning: you are leaving 1 commit behind, not connected to
any of your branches:
30b20f1 unrelatedpick
HEAD is now at df2a63d... initial
$
$ git cherry-pick base..picked
[detached HEAD 30b20f1] unrelatedpick
Author: A U Thor <author@example.com>
1 files changed, 1 insertions(+), 1 deletions(-)
Auto-merging foo
CONFLICT (content): Merge conflict in foo
error: could not apply fdc0b12... picked
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'
$
$ git cherry-pick --continue
fatal: No cherry-pick in progress
-----------------------------------
So it complains because there is no cherry-pick in progress, not because there
are unresolved conflicts.
Thanks,
Christian.
^ permalink raw reply
* gitweb highligh generate illegal char when the content had utf-8 chars
From: zzs @ 2011-08-04 5:31 UTC (permalink / raw)
To: git
When my C file had some utf-8 comments, gitweb highlight generate
illegal chars.
So I hacked gitweb.cgi, like this:
---------------------------
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index dab89f2..48def38 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -6465,7 +6465,7 @@ sub git_blob {
$nr++;
$line = untabify($line);
printf qq!<div class="pre"><a id="l%i" href="%s#l%i" class="linenr">%4i</a> %s</div>\n!,
- $nr, esc_attr(href(-replay => 1)), $nr, $nr, $syntax ? $line : esc_html($line, -nbsp=>1);
+ $nr, esc_attr(href(-replay => 1)), $nr, $nr, $syntax ? to_utf8($line) : esc_html($line, -nbsp=>1);
}
}
close $fd
---------------------------
And it works.
But I wonder is this the rigtht solution.
Anybody help me?
--
Best Regards
zzs
^ permalink raw reply related
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox