Re: What's cooking in git.git (Mar 2014, #07; Fri, 28)

2014-03-30 Thread Junio C Hamano
Michael Haggerty  writes:

> On 03/28/2014 11:21 PM, Junio C Hamano wrote:
>> Here are the topics that have been cooking.  Commits prefixed with
>> '-' are only in 'pu' (proposed updates) while commits prefixed with
>> '+' are in 'next'.
>
> Junio,
>
> Have you overlooked my ref-transactions series [1], or just not gotten
> to it yet?

Mixture of 20% of "too busy" and 80% procrastination, trusting that
an important and interesting topic will get a few rounds of reviews
under competent sets of eyes before I get to it ;-)

> If you would like a version of the series that already addresses Brad
> King's comments, you can get it from my GitHub fork [2], the
> "ref-transactions" branch.  I'd be happy to post a v3 to the list if you
> prefer, but the only changes since v2 were to a commit message and a
> comment so it seems like overkill.

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3] MSVC: fix t0040-parse-options crash

2014-03-30 Thread Andreas Schwab
Junio C Hamano  writes:

> As OPT_SET_PTR() is about setting the pointer value to intptr_t defval,
> a follow-up patch on top of this fix (see attached) may not be a bad
> thing to have, but that patch alone will not fix this issue without
> dropping the unneeded and unwanted cast to unsigned long.

Wouldn't it make sense to change defval into a union to avoid the cast?
(The intptr_t type may be too narrow for other values to be put there.)

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 3/3] test-lib: '--run' to run only specific tests

2014-03-30 Thread Eric Sunshine
On Fri, Mar 28, 2014 at 3:05 AM, Ilya Bobyr  wrote:
> On 3/27/2014 8:36 PM, Eric Sunshine wrote:
>> On Thu, Mar 27, 2014 at 6:32 AM, Ilya Bobyr  wrote:
>>> Allow better control of the set of tests that will be executed for a
>>> single test suite.  Mostly useful while debugging or developing as it
>>> allows to focus on a specific test.
>>>
>>> Signed-off-by: Ilya Bobyr 
>>> ---
>>>  No changes from the previous version.
>>>
>>>  t/README |   65 ++-
>>>  t/t-basic.sh |  233 
>>> ++
>>>  t/test-lib.sh|   85 
>>>  3 files changed, 379 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/t/README b/t/README
>>> index 6b93aca..c911f89 100644
>>> --- a/t/README
>>> +++ b/t/README
>>> @@ -100,6 +100,10 @@ appropriately before running "make".
>>> This causes additional long-running tests to be run (where
>>> available), for more exhaustive testing.
>>>
>>> +-r,--run=::
>> Perhaps  or something similar would be closer to the truth.
>
> I think your naming is better.  I will include it in the next version.
>
>>> +   This causes only specific tests to be included or excluded.  See
>> This is phrased somewhat oddly, as if you had already been talking
>> about tests being included or excluded, and that this option merely
>> changes that selection. Perhaps something like:
>>
>> Run only the subset of tests indicated by .
>
> Will use that sentence as well :)
>
>>> +   section "Skipping Tests" below for "" syntax.
>>> +
>>>  --valgrind=::
>>> Execute all Git binaries under valgrind tool  and exit
>>> with status 126 on errors (just like regular tests, this will
>>> @@ -187,10 +191,63 @@ and either can match the "t[0-9]{4}" part to skip the 
>>> whole
>>>  test, or t[0-9]{4} followed by ".$number" to say which
>>>  particular test to skip.
>>>
>>> -Note that some tests in the existing test suite rely on previous
>>> -test item, so you cannot arbitrarily disable one and expect the
>>> -remainder of test to check what the test originally was intended
>>> -to check.
>>> +For an individual test suite --run could be used to specify that
>>> +only some tests should be run or that some tests should be
>>> +excluded from a run.
>>> +
>>> +--run argument is a list of patterns with optional prefixes that
>> "The argument for --run is a list...
>
> I think it could be either.  But I am not a native speaker.
> So, I will use your version :)
>
>>> +are matched against test numbers within the current test suite.
>>> +Supported pattern:
>>> +
>>> + - A number matches a test with that number.
>>> +
>>> + - sh metacharacters such as '*', '?' and '[]' match as usual in
>>> +   shell.
>>> +
>>> + - A number prefixed with '<', '<=', '>', or '>=' matches all
>>> +   tests 'before', 'before or including', 'after', or 'after or
>>> +   including' the specified one.
>> I think you want "and" rather than "or": "before and including",
>> "after and including".
>
> I was thinking about an analogy to the corresponding mathematical
> operations here.  In mathematics, '<=' is called "less than or
> equal to"[1].
>
> If you are thinking about test numbers you can say that you
> include a test if it has a number before or equal to the given
> one.  The sentence is "A number prefixed with <= matches all
> tests [with numbers] before or including the specified [number]."

In English, it is idiomatic to say "less than or equal" for '<=', and
"greater than or equal" for '>='. "before or including" and "after or
including" are not used and sound odd. They also sound rather odd when
"or" is replaced with "and". Using the idiomatic forms should be fine.

> Maybe if I change "one" to "number" it would be a bit less
> ambiguous.  Or even include all the omitted words.

Changing "all tests" to "all test numbers" and using the idiomatic forms gives:

A number prefixed with '<', '<=', '>', or '>=' matches,
respectively, all test numbers less than, less than or equal,
greater than, or greater than or equal to the specified one.

which isn't bad, though a bit verbose.

> I would not mind a completely different way to say it, but I am
> not yet sure that if I replace "or" with "and" it would make it
> a lot better.

Since the relational operators are fairly self-explanatory, you could
drop the prose explanation, though that might make it too cryptic:

A number prefixed with '<', '<=', '>', or '>=' matches test
numbers meeting the specified relation.

> [1] https://en.wikipedia.org/wiki/Inequality_%28mathematics%29
>
>>> +Optional prefixes are:
>>> +
>>> + - '+' or no prefix: test(s) matching the pattern are included in
>>> +   the run.
>>> +
>>> + - '-' or '!': test(s) matching the pattern are exluded from the
>>> +   run.
>> I've been playing with --run, and I find that test selection is not
>> especially intuitive. For instance, ">=16 !>24 !20" is easier to
>> reason about when written instead with ranges,

[WIP/PATCH] status/commit: always show staged submodules regardless of ignore config

2014-03-30 Thread Jens Lehmann
Currently setting submodule..ignore and/or diff.ignoreSubmodules to
"all" suppresses all output of submodule changes for the diff family,
status and commit. For status and commit this is really confusing, as it
even when the user chooses to record a new commit for an ignored submodule
by adding it manually this change won't show up under the to-be-committed
changes. To add insult to injury, a later "git commit" will error out with
"nothing to commit" when only ignored submodules are staged.

Fix that by making wt_status always print staged submodule changes, no
matter what ignore settings are configured. The only exception is when the
user explicitly uses the "--ignore-submodules=all" command line option, in
that case the submodule output is still suppressed. This also makes "git
commit" work again when only modifications of ignored submodules are
staged, as that command uses the "commitable" member of the wt_status
struct to determine if staged changes are present.

Change t7508 to reflect this new behavior. Also mention it in the
documentation of the ignore config options.

Signed-off-by: Jens Lehmann 
---


Am 28.03.2014 17:47, schrieb Jens Lehmann:
> Am 28.03.2014 00:36, schrieb Ronald Weiss:
>> And also, I'd like to know git folks' opinion on whether it's OK that
>> git commit with ignore=all in .gitmodules ignores submodules even when
>> they are explicitely staged with git add.
> 
> No, they should be visible in status and commit when the user chose
> to add them. I see if I can hack something up (as I've been bitten
> myself by that recently ;-).

Ok, here we go! As we discussed the same issue last November I
added the people involved back then to the CC.

I still need to fix an issue with this patch: committing a single
ignored submodule sometimes exits with an error code (even though
the commit succeeds), I'm still looking into that and will provide
a test for commit too.

After this we need at least two other patches:

- git gui should show staged ignored submodules

- gitk should show staged ignored submodules

(It'd be great if someone else would tackle these two, just let me
know if you want to to avoid duplicated work)

Did I forget a git command that shows what is to be staged?


 Documentation/config.txt |  8 ++--
 Documentation/gitmodules.txt |  4 +++-
 t/t7508-status.sh| 29 +++--
 wt-status.c  | 12 +++-
 4 files changed, 47 insertions(+), 6 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 73c8973..0a2e9ad 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -2279,7 +2279,9 @@ status.submodulesummary::
--summary-limit option of linkgit:git-submodule[1]). Please note
that the summary output command will be suppressed for all
submodules when `diff.ignoreSubmodules` is set to 'all' or only
-   for those submodules where `submodule..ignore=all`. To
+   for those submodules where `submodule..ignore=all`. The only
+   exception to that rule is that status and commit will always show
+   submodule changes that have been staged. To
also view the summary for ignored submodules you can either use
the --ignore-submodules=dirty command line option or the 'git
submodule summary' command, which shows a similar output but does
@@ -2310,7 +2312,9 @@ submodule..fetchRecurseSubmodules::
 submodule..ignore::
Defines under what circumstances "git status" and the diff family show
a submodule as modified. When set to "all", it will never be considered
-   modified, "dirty" will ignore all changes to the submodules work tree 
and
+   modified (but will nonetheless show up in the output of status and
++  commit when they have been staged), "dirty" will ignore all changes
+   to the submodules work tree and
takes only differences between the HEAD of the submodule and the commit
recorded in the superproject into account. "untracked" will additionally
let submodules with modified tracked files in their work tree show up.
diff --git a/Documentation/gitmodules.txt b/Documentation/gitmodules.txt
index f539e3f..f684963 100644
--- a/Documentation/gitmodules.txt
+++ b/Documentation/gitmodules.txt
@@ -71,7 +71,9 @@ submodule..fetchRecurseSubmodules::
 submodule..ignore::
Defines under what circumstances "git status" and the diff family show
a submodule as modified. When set to "all", it will never be considered
-   modified, "dirty" will ignore all changes to the submodules work tree 
and
+   modified (but will nonetheless show up in the output of status and
+   commit when they have been staged), "dirty" will ignore all changes
+   to the submodules work tree and
takes only differences between the HEAD of the submodule and the commit
recorded in the superproject into account. "untracked" will additionally
let submodules with mo

Re: [PATCH v2 1/3] patch-id: make it stable against hunk reordering

2014-03-30 Thread Michael S. Tsirkin
On Fri, Mar 28, 2014 at 12:20:13PM -0700, Junio C Hamano wrote:
> "Michael S. Tsirkin"  writes:
> 
> > Patch id changes if you reorder hunks in a diff.
> > As the result is functionally equivalent, this is surprising to many
> > people.
> > In particular, reordering hunks is helpful to make patches
> > more readable (e.g. API header diff before implementation diff).
> > In git, it is often done e.g. using the "-O " option,
> > so supporting it better has value.
> >
> > Hunks within file can be reordered manually provided
> > the same pathname can appear more than once in the input.
> >
> > Change patch-id behaviour making it stable against
> > hunk reodering:
> > - prepend header to each hunk (if not there)
> > Note: POSIX requires patch to be robust against hunk reordering
> > provided each diff hunk has a header:
> > http://pubs.opengroup.org/onlinepubs/7908799/xcu/patch.html
> > If the patch file contains more than one patch, patch will 
> > attempt to
> > apply each of them as if they came from separate patch files. 
> > (In this
> > case the name of the patch file must be determinable for each 
> > diff
> > listing.)
> >
> > - calculate SHA1 hash for each hunk separately
> > - sum all hashes to get patch id
> >
> > Add a new flag --unstable to get the historical behaviour.
> >
> > Add --stable which is a nop, for symmetry.
> >
> > Signed-off-by: Michael S. Tsirkin 
> > ---
> >
> > Changes from v1: documented motivation for supporting
> > hunk reordering (and not just file reordering).
> > No code changes.
> >
> > Junio, you didn't respond so I'm not sure whether I convinced
> > you that supporting hunk reordering within file has value.
> > So I kept this functionality around for now, if
> > you think I should drop this, please let me know explicitly.
> > Thanks, and sorry about being dense!
> 
> The motivation I read from the exchange was that:
> 
>  (1) we definitely want to support a mode that is stable with use of
>  "diff -O" (i.e. reordering patches per paths);
> 
>  (2) supporting a patch with swapped "hunks" does not have any
>  practical value.  When you have a patch to the same file F with
>  two hunks starting at lines 20 and 40, manually reordering
>  hunks to create a patch that shows the hunk that starts at line
>  40 and then the other hunk that starts at line 20 is not a
>  useful exercise;

I agree, especially since the resulting patch can't be applied with
either patch or git apply.

>  (3) but supporting a patch that touches the same path more than
>  once is in line with what "patch" and "git apply" after
>  7a07841c (git-apply: handle a patch that touches the same path
>  more than once better, 2008-06-27) do.
> 
> In other words, the goal of this change would be to give the same id
> for all these three:
> 
> (A) straight-forward:
> 
> diff --git a/foo.c b/foo.c
> --- a/foo.c
> +++ b/foo.c
> @@ -20,1 +20,1 @@
> 
> -foo
> +bar
> 
> @@ -40,1 +40,1 @@
> 
> -frotz
> +xyzzy
> 
> (B) as two patches concatenated together:
> 
> diff --git a/foo.c b/foo.c
> --- a/foo.c
> +++ b/foo.c
> @@ -20,1 +20,1 @@
> 
> -foo
> +bar
> 
> diff --git a/foo.c b/foo.c
> --- a/foo.c
> +++ b/foo.c
> @@ -40,1 +40,1 @@
> 
> -frotz
> +xyzzy
> 
> (C) the same as (B) but with a swapped order:
> 
> diff --git a/foo.c b/foo.c
> --- a/foo.c
> +++ b/foo.c
> @@ -40,1 +40,1 @@
> 
> -frotz
> +xyzzy
> diff --git a/foo.c b/foo.c
> --- a/foo.c
> +++ b/foo.c
> @@ -20,1 +20,1 @@
> 
> -foo
> +bar
> 
> Am I reading you correctly?

Absolutely.

> If that is the case, I think I can buy such a change.  It appears to
> me that in addition to changing the way the bytes form multiple
> hunks are hashed, it would need to hash the file-level headers
> together with each hunk when processing input (A) in order to make
> the output consistent with the output for the latter two.

Exactly. This is what this change attempts to do:
+   if (hunks) {
+   flush_one_hunk(result, &ctx);
+   memcpy(&ctx, &header_ctx,
+  sizeof ctx);
+   } else {
+   /* Save ctx for next hunk.  */
+   memcpy(&header_ctx, &ctx,
+  sizeof ctx);
+   }

I'll add more code comments to clarify the logic here.

> Alternatively, you could hash the header for the same path only once
> when processing input like (B) or (C) and mi

[PATCH v4 0/3] Take four on fixing OPT_SET_PTR issues

2014-03-30 Thread Marat Radchenko
Patches summary:
1. Fix initial issue (incorrect cast causing crash on 64-bit MSVC)
2. Improve OPT_SET_PTR to prevent same errors in future
3. Purge OPT_SET_PTR away since nobody uses it

*Optional* patch №3 is separated from №1 and №2 so that if someone someday
decides to return OPT_SET_PTR back by reverting №3, it will be returned
in a sane state.

Decision of (not) merging №3 is left as an exercise to the reader due to
my insufficient knowledge of accepted practices in Git project.

Marat Radchenko (3):
  MSVC: fix t0040-parse-options crash
  parse-options: add cast to correct pointer type to OPT_SET_PTR
  parse-options: remove unused OPT_SET_PTR

 Documentation/technical/api-parse-options.txt | 4 
 parse-options.c   | 5 -
 parse-options.h   | 5 +
 t/t0040-parse-options.sh  | 7 +++
 test-parse-options.c  | 2 --
 5 files changed, 4 insertions(+), 19 deletions(-)

-- 
1.9.0

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 1/3] MSVC: fix t0040-parse-options crash

2014-03-30 Thread Marat Radchenko
On 64-bit MSVC, pointers are 64 bit but `long` is only 32.
Thus, casting string to `unsigned long`, which is redundand on other
platforms, throws away important bits and when later cast to `intptr_t`
results in corrupt pointer.

This patch fixes test-parse-options by replacing harming cast with
correct one.

Signed-off-by: Marat Radchenko 
---
 test-parse-options.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/test-parse-options.c b/test-parse-options.c
index 434e8b8..6f6c656 100644
--- a/test-parse-options.c
+++ b/test-parse-options.c
@@ -60,7 +60,7 @@ int main(int argc, char **argv)
OPT_STRING('o', NULL, &string, "str", "get another string"),
OPT_NOOP_NOARG(0, "obsolete"),
OPT_SET_PTR(0, "default-string", &string,
-   "set string to default", (unsigned long)"default"),
+   "set string to default", (intptr_t)"default"),
OPT_STRING_LIST(0, "list", &list, "str", "add str to list"),
OPT_GROUP("Magic arguments"),
OPT_ARGUMENT("quux", "means --quux"),
-- 
1.9.0

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 2/3] parse-options: add cast to correct pointer type to OPT_SET_PTR

2014-03-30 Thread Marat Radchenko
Do not force users of OPT_SET_PTR to cast pointer to correct
underlying pointer type by integrating cast into OPT_SET_PTR macro.

Cast is required to prevent 'initialization makes integer from pointer
without a cast' compiler warning.
---
 parse-options.h  | 2 +-
 test-parse-options.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/parse-options.h b/parse-options.h
index 8fa02dc..54099d9 100644
--- a/parse-options.h
+++ b/parse-options.h
@@ -129,7 +129,7 @@ struct option {
 #define OPT_HIDDEN_BOOL(s, l, v, h) { OPTION_SET_INT, (s), (l), (v), NULL, \
  (h), PARSE_OPT_NOARG | PARSE_OPT_HIDDEN, 
NULL, 1}
 #define OPT_SET_PTR(s, l, v, h, p)  { OPTION_SET_PTR, (s), (l), (v), NULL, \
- (h), PARSE_OPT_NOARG, NULL, (p) }
+ (h), PARSE_OPT_NOARG, NULL, (intptr_t)(p) 
}
 #define OPT_CMDMODE(s, l, v, h, i) { OPTION_CMDMODE, (s), (l), (v), NULL, \
  (h), PARSE_OPT_NOARG|PARSE_OPT_NONEG, 
NULL, (i) }
 #define OPT_INTEGER(s, l, v, h) { OPTION_INTEGER, (s), (l), (v), N_("n"), 
(h) }
diff --git a/test-parse-options.c b/test-parse-options.c
index 6f6c656..10da63e 100644
--- a/test-parse-options.c
+++ b/test-parse-options.c
@@ -60,7 +60,7 @@ int main(int argc, char **argv)
OPT_STRING('o', NULL, &string, "str", "get another string"),
OPT_NOOP_NOARG(0, "obsolete"),
OPT_SET_PTR(0, "default-string", &string,
-   "set string to default", (intptr_t)"default"),
+   "set string to default", "default"),
OPT_STRING_LIST(0, "list", &list, "str", "add str to list"),
OPT_GROUP("Magic arguments"),
OPT_ARGUMENT("quux", "means --quux"),
-- 
1.9.0

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 3/3] parse-options: remove unused OPT_SET_PTR

2014-03-30 Thread Marat Radchenko
OPT_SET_PTR was never used since its creation in 2007 (commit
db7244bd5be12e389badb9cec621dbbcfa11f59a).
---
 Documentation/technical/api-parse-options.txt | 4 
 parse-options.c   | 5 -
 parse-options.h   | 5 +
 t/t0040-parse-options.sh  | 7 +++
 test-parse-options.c  | 2 --
 5 files changed, 4 insertions(+), 19 deletions(-)

diff --git a/Documentation/technical/api-parse-options.txt 
b/Documentation/technical/api-parse-options.txt
index be50cf4..1f2db31 100644
--- a/Documentation/technical/api-parse-options.txt
+++ b/Documentation/technical/api-parse-options.txt
@@ -160,10 +160,6 @@ There are some macros to easily define options:
`int_var` is set to `integer` with `--option`, and
reset to zero with `--no-option`.
 
-`OPT_SET_PTR(short, long, &ptr_var, description, ptr)`::
-   Introduce a boolean option.
-   If used, set `ptr_var` to `ptr`.
-
 `OPT_STRING(short, long, &str_var, arg_str, description)`::
Introduce an option with string argument.
The string argument is put into `str_var`.
diff --git a/parse-options.c b/parse-options.c
index c81d3a0..b536896 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -127,10 +127,6 @@ static int get_value(struct parse_opt_ctx_t *p,
*(int *)opt->value = opt->defval;
return 0;
 
-   case OPTION_SET_PTR:
-   *(void **)opt->value = unset ? NULL : (void *)opt->defval;
-   return 0;
-
case OPTION_STRING:
if (unset)
*(const char **)opt->value = NULL;
@@ -367,7 +363,6 @@ static void parse_options_check(const struct option *opts)
case OPTION_BIT:
case OPTION_NEGBIT:
case OPTION_SET_INT:
-   case OPTION_SET_PTR:
case OPTION_NUMBER:
if ((opts->flags & PARSE_OPT_OPTARG) ||
!(opts->flags & PARSE_OPT_NOARG))
diff --git a/parse-options.h b/parse-options.h
index 54099d9..3189676 100644
--- a/parse-options.h
+++ b/parse-options.h
@@ -12,7 +12,6 @@ enum parse_opt_type {
OPTION_NEGBIT,
OPTION_COUNTUP,
OPTION_SET_INT,
-   OPTION_SET_PTR,
OPTION_CMDMODE,
/* options with arguments (usually) */
OPTION_STRING,
@@ -96,7 +95,7 @@ typedef int parse_opt_ll_cb(struct parse_opt_ctx_t *ctx,
  *
  * `defval`::
  *   default value to fill (*->value) with for PARSE_OPT_OPTARG.
- *   OPTION_{BIT,SET_INT,SET_PTR} store the {mask,integer,pointer} to put in
+ *   OPTION_{BIT,SET_INT} store the {mask,integer,pointer} to put in
  *   the value when met.
  *   CALLBACKS can use it like they want.
  */
@@ -128,8 +127,6 @@ struct option {
 #define OPT_BOOL(s, l, v, h)OPT_SET_INT(s, l, v, h, 1)
 #define OPT_HIDDEN_BOOL(s, l, v, h) { OPTION_SET_INT, (s), (l), (v), NULL, \
  (h), PARSE_OPT_NOARG | PARSE_OPT_HIDDEN, 
NULL, 1}
-#define OPT_SET_PTR(s, l, v, h, p)  { OPTION_SET_PTR, (s), (l), (v), NULL, \
- (h), PARSE_OPT_NOARG, NULL, (intptr_t)(p) 
}
 #define OPT_CMDMODE(s, l, v, h, i) { OPTION_CMDMODE, (s), (l), (v), NULL, \
  (h), PARSE_OPT_NOARG|PARSE_OPT_NONEG, 
NULL, (i) }
 #define OPT_INTEGER(s, l, v, h) { OPTION_INTEGER, (s), (l), (v), N_("n"), 
(h) }
diff --git a/t/t0040-parse-options.sh b/t/t0040-parse-options.sh
index 65606df..4476548 100755
--- a/t/t0040-parse-options.sh
+++ b/t/t0040-parse-options.sh
@@ -30,7 +30,6 @@ String options
 --string2get another string
 --st  get another string (pervert ordering)
 -o   get another string
---default-string  set string to default
 --list   add str to list
 
 Magic arguments
@@ -293,7 +292,7 @@ cat > expect < output 2> output.err &&
test_must_be_empty output.err &&
test_cmp expect output
diff --git a/test-parse-options.c b/test-parse-options.c
index 10da63e..5dabce6 100644
--- a/test-parse-options.c
+++ b/test-parse-options.c
@@ -59,8 +59,6 @@ int main(int argc, char **argv)
OPT_STRING(0, "st", &string, "st", "get another string (pervert 
ordering)"),
OPT_STRING('o', NULL, &string, "str", "get another string"),
OPT_NOOP_NOARG(0, "obsolete"),
-   OPT_SET_PTR(0, "default-string", &string,
-   "set string to default", "default"),
OPT_STRING_LIST(0, "list", &list, "str", "add str to list"),
OPT_GROUP("Magic arguments"),
OPT_ARGUMENT("quux", "means --quux"),
-- 
1.9.0

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[BUG] 'pread' : macro redefinition

2014-03-30 Thread Marat Radchenko
Stefan Zager  chromium.org> writes:

> 
> This adds a Windows implementation of pread.
> diff --git a/compat/mingw.h b/compat/mingw.h
> index 08b83fe..377ba50 100644
> --- a/compat/mingw.h
> +++ b/compat/mingw.h
> +ssize_t mingw_pread(int fd, void *buf, size_t count, off64_t offset);
> +#define pread mingw_pread

This result in tons of following warnings in MSVC=1 build:

git-compat-util.h(401) : warning C4005: 'pread' : macro redefinition
mingw.h(181) : see previous definition of 'pread'


--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 00/18] git-ls

2014-03-30 Thread Nguyễn Thái Ngọc Duy
All comments by Eric are fixed in v3. -F is added. And the command
name is now list-files, not ls. 'ls' is saved for the user to make
an alias with better default options.

Nguyễn Thái Ngọc Duy (18):
  ls_colors.c: add $LS_COLORS parsing code
  ls_colors.c: parse color.ls.* from config file
  ls_colors.c: add a function to color a file name
  ls_colors.c: highlight submodules like directories
  ls-files: buffer full item in strbuf before printing
  ls-files: add --color to highlight file names
  ls-files: add --column
  ls-files: support --max-depth
  Add git-list-files, a user friendly version of ls-files and more
  list-files: -u does not imply showing stages
  list-files: add -R/--recursive short for --max-depth=-1
  list-files: add -1 short for --no-column
  list-files: add -t back
  list-files: sort output and remove duplicates
  list-files: do not show duplicate cached entries
  list-files: show directories as well as files
  list-files: add -F/--classify
  list-files -F: show submodules with the new indicator '&'

 .gitignore |   1 +
 Documentation/config.txt   |  22 ++
 Documentation/git-list-files.txt (new) |  99 +++
 Documentation/git-ls-files.txt |  20 ++
 Makefile   |   2 +
 builtin/ls-files.c | 358 ++--
 color.h|  10 +
 command-list.txt   |   1 +
 git.c  |   1 +
 ls_colors.c (new)  | 496 +
 10 files changed, 980 insertions(+), 30 deletions(-)
 create mode 100644 Documentation/git-list-files.txt
 create mode 100644 ls_colors.c

-- 
1.9.1.345.ga1a145c

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 01/18] ls_colors.c: add $LS_COLORS parsing code

2014-03-30 Thread Nguyễn Thái Ngọc Duy
Reusing color settings from $LS_COLORS could give a native look and
feel on file coloring.

This code is basically from coreutils.git [1], rewritten to fit Git.

As this is from GNU ls, the environment variable CLICOLOR is not
tested. It is to be decided later whether we should ignore $LS_COLORS
if $CLICOLOR is not set on Mac or FreeBSD.

[1] commit 7326d1f1a67edf21947ae98194f98c38b6e9e527 file
src/ls.c. This is the last GPL-2 commit before coreutils turns to
GPL-3.

Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 Makefile  |   1 +
 color.h   |   8 ++
 ls_colors.c (new) | 398 ++
 3 files changed, 407 insertions(+)
 create mode 100644 ls_colors.c

diff --git a/Makefile b/Makefile
index f818eec..f6a6e14 100644
--- a/Makefile
+++ b/Makefile
@@ -819,6 +819,7 @@ LIB_OBJS += list-objects.o
 LIB_OBJS += ll-merge.o
 LIB_OBJS += lockfile.o
 LIB_OBJS += log-tree.o
+LIB_OBJS += ls_colors.o
 LIB_OBJS += mailmap.o
 LIB_OBJS += match-trees.o
 LIB_OBJS += merge.o
diff --git a/color.h b/color.h
index 9a8495b..640fc48 100644
--- a/color.h
+++ b/color.h
@@ -45,6 +45,12 @@ struct strbuf;
 #define GIT_COLOR_BG_MAGENTA   "\033[45m"
 #define GIT_COLOR_BG_CYAN  "\033[46m"
 
+#define GIT_COLOR_WHITE_ON_RED"\033[37;41m"
+#define GIT_COLOR_WHITE_ON_BLUE   "\033[37;44m"
+#define GIT_COLOR_BLACK_ON_YELLOW "\033[30;43m"
+#define GIT_COLOR_BLUE_ON_GREEN   "\033[34;42m"
+#define GIT_COLOR_BLACK_ON_GREEN  "\033[30;42m"
+
 /* A special value meaning "no color selected" */
 #define GIT_COLOR_NIL "NIL"
 
@@ -87,4 +93,6 @@ void color_print_strbuf(FILE *fp, const char *color, const 
struct strbuf *sb);
 
 int color_is_nil(const char *color);
 
+void parse_ls_color(void);
+
 #endif /* COLOR_H */
diff --git a/ls_colors.c b/ls_colors.c
new file mode 100644
index 000..eb944f4
--- /dev/null
+++ b/ls_colors.c
@@ -0,0 +1,398 @@
+#include "cache.h"
+#include "color.h"
+
+enum color_ls {
+   LS_LC,  /* left, unused */
+   LS_RC,  /* right, unused */
+   LS_EC,  /* end color, unused */
+   LS_RS,  /* reset */
+   LS_NO,  /* normal */
+   LS_FL,  /* file, default */
+   LS_DI,  /* directory */
+   LS_LN,  /* symlink */
+
+   LS_PI,  /* pipe */
+   LS_SO,  /* socket */
+   LS_BD,  /* block device */
+   LS_CD,  /* char device */
+   LS_MI,  /* missing file */
+   LS_OR,  /* orphaned symlink */
+   LS_EX,  /* executable */
+   LS_DO,  /* Solaris door */
+
+   LS_SU,  /* setuid */
+   LS_SG,  /* setgid */
+   LS_ST,  /* sticky */
+   LS_OW,  /* other-writable */
+   LS_TW,  /* ow with sticky */
+   LS_CA,  /* cap */
+   LS_MH,  /* multi hardlink */
+   LS_CL,  /* clear end of line */
+
+   MAX_LS
+};
+
+static char ls_colors[MAX_LS][COLOR_MAXLEN] = {
+   "",
+   "",
+   "",
+   GIT_COLOR_RESET,
+   GIT_COLOR_NORMAL,
+   GIT_COLOR_NORMAL,
+   GIT_COLOR_BOLD_BLUE,
+   GIT_COLOR_BOLD_CYAN,
+
+   GIT_COLOR_YELLOW,
+   GIT_COLOR_BOLD_MAGENTA,
+   GIT_COLOR_BOLD_YELLOW,
+   GIT_COLOR_BOLD_YELLOW,
+   GIT_COLOR_NORMAL,
+   GIT_COLOR_NORMAL,
+   GIT_COLOR_BOLD_GREEN,
+   GIT_COLOR_BOLD_MAGENTA,
+
+   GIT_COLOR_WHITE_ON_RED,
+   GIT_COLOR_BLACK_ON_YELLOW,
+   GIT_COLOR_WHITE_ON_BLUE,
+   GIT_COLOR_BLUE_ON_GREEN,
+   GIT_COLOR_BLACK_ON_GREEN,
+   "",
+   "",
+   ""
+};
+
+static const char *const indicator_name[] = {
+   "lc", "rc", "ec", "rs", "no", "fi", "di", "ln",
+   "pi", "so", "bd", "cd", "mi", "or", "ex", "do",
+   "su", "sg", "st", "ow", "tw", "ca", "mh", "cl",
+   NULL
+};
+
+struct bin_str {
+   size_t len; /* Number of bytes */
+   const char *string; /* Pointer to the same */
+};
+
+struct color_ext_type {
+   struct bin_str ext; /* The extension we're looking for */
+   struct bin_str seq; /* The sequence to output when we do */
+   struct color_ext_type *next;/* Next in list */
+};
+
+static struct color_ext_type *color_ext_list = NULL;
+
+/*
+ * When true, in a color listing, color each symlink name according to the
+ * type of file it points to.  Otherwise, color them according to the `ln'
+ * directive in LS_COLORS.  Dangling (orphan) symlinks are treated specially,
+ * regardless.  This is set when `ln=target' appears in LS_COLORS.
+ */
+static int color_symlink_as_referent;
+
+/*
+ * Parse a string as part of the LS_COLORS variable; this may involve
+ * decoding all kinds of escape characters.  If equal

[PATCH v3 04/18] ls_colors.c: highlight submodules like directories

2014-03-30 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 Documentation/config.txt | 3 ++-
 ls_colors.c  | 8 +++-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 3fb754e..6bca55e 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -913,7 +913,8 @@ color.ls.::
Use customized color for file name colorization. If not set
and the environment variable LS_COLORS is set, color settings
from $LS_COLORS are used. `` can be `normal`, `file`,
-   `directory`, `symlink`, `fifo`, `socket`, `block`, `char`,
+   `directory`, `submodule`,
+   `symlink`, `fifo`, `socket`, `block`, `char`,
`missing`, `orphan`, `executable`, `door`, `setuid`, `setgid`,
`sticky`, `otherwritable`, `stickyotherwritable`, `cap`,
`multihardlink`. The values of these variables may be
diff --git a/ls_colors.c b/ls_colors.c
index 1125329..0cc4e9b 100644
--- a/ls_colors.c
+++ b/ls_colors.c
@@ -29,6 +29,8 @@ enum color_ls {
LS_MH,  /* multi hardlink */
LS_CL,  /* clear end of line */
 
+   LS_SUBMODULE,
+
MAX_LS
 };
 
@@ -58,7 +60,8 @@ static char ls_colors[MAX_LS][COLOR_MAXLEN] = {
GIT_COLOR_BLACK_ON_GREEN,
"",
"",
-   ""
+   "",
+   GIT_COLOR_BOLD_BLUE
 };
 
 static const char *const indicator_name[] = {
@@ -73,6 +76,7 @@ static const char* const config_name[] = {
"fifo", "socket", "block", "char", "missing", "orphan", "executable",
"door", "setuid", "setgid", "sticky", "otherwritable",
"stickyotherwritable", "cap", "multihardlink", "",
+   "submodule",
NULL
 };
 
@@ -448,6 +452,8 @@ void color_filename(struct strbuf *sb, const char *name,
type = LS_DI;
} else if (S_ISLNK (mode))
type = (!linkok && *ls_colors[LS_OR]) ? LS_OR : LS_LN;
+   else if (S_ISGITLINK(mode))
+   type = LS_SUBMODULE;
else if (S_ISFIFO (mode))
type = LS_PI;
else if (S_ISSOCK (mode))
-- 
1.9.1.345.ga1a145c

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 03/18] ls_colors.c: add a function to color a file name

2014-03-30 Thread Nguyễn Thái Ngọc Duy
The new function is based on print_color_indicator() from commit
7326d1f1a67edf21947ae98194f98c38b6e9e527 in coreutils.git.

Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 color.h |  2 ++
 ls_colors.c | 66 +
 2 files changed, 68 insertions(+)

diff --git a/color.h b/color.h
index 640fc48..398369a 100644
--- a/color.h
+++ b/color.h
@@ -94,5 +94,7 @@ void color_print_strbuf(FILE *fp, const char *color, const 
struct strbuf *sb);
 int color_is_nil(const char *color);
 
 void parse_ls_color(void);
+void color_filename(struct strbuf *sb, const char *name,
+   const char *display_name, mode_t mode, int linkok);
 
 #endif /* COLOR_H */
diff --git a/ls_colors.c b/ls_colors.c
index cef5a92..1125329 100644
--- a/ls_colors.c
+++ b/ls_colors.c
@@ -422,3 +422,69 @@ void parse_ls_color(void)
color_symlink_as_referent = 1;
git_config(ls_colors_config, NULL);
 }
+
+void color_filename(struct strbuf *sb, const char *name,
+   const char *display_name, mode_t mode, int linkok)
+{
+   int type;
+   struct color_ext_type *ext; /* Color extension */
+
+   if (S_ISREG (mode)) {
+   type = LS_FL;
+   if ((mode & S_ISUID) != 0)
+   type = LS_SU;
+   else if ((mode & S_ISGID) != 0)
+   type = LS_SG;
+   else if ((mode & (S_IXUSR | S_IXGRP | S_IXOTH)) != 0)
+   type = LS_EX;
+   } else if (S_ISDIR (mode)) {
+   if ((mode & S_ISVTX) && (mode & S_IWOTH))
+   type = LS_TW;
+   else if ((mode & S_IWOTH) != 0)
+   type = LS_OW;
+   else if ((mode & S_ISVTX) != 0)
+   type = LS_ST;
+   else
+   type = LS_DI;
+   } else if (S_ISLNK (mode))
+   type = (!linkok && *ls_colors[LS_OR]) ? LS_OR : LS_LN;
+   else if (S_ISFIFO (mode))
+   type = LS_PI;
+   else if (S_ISSOCK (mode))
+   type = LS_SO;
+   else if (S_ISBLK (mode))
+   type = LS_BD;
+   else if (S_ISCHR (mode))
+   type = LS_CD;
+#ifdef S_ISDOOR
+   else if (S_ISDOOR (mode))
+   type = LS_DO;
+#endif
+   else
+   /* Classify a file of some other type as C_ORPHAN.  */
+   type = LS_OR;
+
+   /* Check the file's suffix only if still classified as C_FILE.  */
+   ext = NULL;
+   if (type == LS_FL) {
+   /* Test if NAME has a recognized suffix.  */
+   size_t len = strlen(name);
+   const char *p = name + len; /* Pointer to final \0. 
 */
+   for (ext = color_ext_list; ext != NULL; ext = ext->next) {
+   if (ext->ext.len <= len &&
+   !strncmp(p - ext->ext.len, ext->ext.string, 
ext->ext.len))
+   break;
+   }
+   }
+
+   if (display_name)
+   name = display_name;
+   if (ext)
+   strbuf_addf(sb, "\033[%.*sm%s%s",
+   (int)ext->seq.len, ext->seq.string,
+   name, GIT_COLOR_RESET);
+   else if (*ls_colors[type])
+   strbuf_addf(sb, "%s%s%s", ls_colors[type], name, 
GIT_COLOR_RESET);
+   else
+   strbuf_addstr(sb, name);
+}
-- 
1.9.1.345.ga1a145c

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 05/18] ls-files: buffer full item in strbuf before printing

2014-03-30 Thread Nguyễn Thái Ngọc Duy
Buffering so that we can manipulate the strings (e.g. coloring)
further before finally printing them.

Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 builtin/ls-files.c | 48 +++-
 1 file changed, 35 insertions(+), 13 deletions(-)

diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 47c3880..6e30592 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -47,18 +47,30 @@ static const char *tag_modified = "";
 static const char *tag_skip_worktree = "";
 static const char *tag_resolve_undo = "";
 
-static void write_name(const char *name)
+static void write_name(struct strbuf *sb, const char *name)
 {
/*
 * With "--full-name", prefix_len=0; this caller needs to pass
 * an empty string in that case (a NULL is good for "").
 */
-   write_name_quoted_relative(name, prefix_len ? prefix : NULL,
-  stdout, line_terminator);
+   const char *real_prefix = prefix_len ? prefix : NULL;
+   if (!line_terminator) {
+   struct strbuf sb2 = STRBUF_INIT;
+   strbuf_addstr(sb, relative_path(name, real_prefix, &sb2));
+   strbuf_release(&sb2);
+   } else
+   quote_path_relative(name, real_prefix, sb);
+   strbuf_addch(sb, line_terminator);
+}
+
+static void strbuf_fputs(struct strbuf *sb, FILE *fp)
+{
+   fwrite(sb->buf, sb->len, 1, fp);
 }
 
 static void show_dir_entry(const char *tag, struct dir_entry *ent)
 {
+   static struct strbuf sb = STRBUF_INIT;
int len = max_prefix_len;
 
if (len >= ent->len)
@@ -67,8 +79,10 @@ static void show_dir_entry(const char *tag, struct dir_entry 
*ent)
if (!dir_path_match(ent, &pathspec, len, ps_matched))
return;
 
-   fputs(tag, stdout);
-   write_name(ent->name);
+   strbuf_reset(&sb);
+   strbuf_addstr(&sb, tag);
+   write_name(&sb, ent->name);
+   strbuf_fputs(&sb, stdout);
 }
 
 static void show_other_files(struct dir_struct *dir)
@@ -134,6 +148,7 @@ static void show_killed_files(struct dir_struct *dir)
 
 static void show_ce_entry(const char *tag, const struct cache_entry *ce)
 {
+   static struct strbuf sb = STRBUF_INIT;
int len = max_prefix_len;
 
if (len >= ce_namelen(ce))
@@ -161,16 +176,18 @@ static void show_ce_entry(const char *tag, const struct 
cache_entry *ce)
tag = alttag;
}
 
+   strbuf_reset(&sb);
if (!show_stage) {
-   fputs(tag, stdout);
+   strbuf_addstr(&sb, tag);
} else {
-   printf("%s%06o %s %d\t",
-  tag,
-  ce->ce_mode,
-  find_unique_abbrev(ce->sha1,abbrev),
-  ce_stage(ce));
+   strbuf_addf(&sb, "%s%06o %s %d\t",
+   tag,
+   ce->ce_mode,
+   find_unique_abbrev(ce->sha1,abbrev),
+   ce_stage(ce));
}
-   write_name(ce->name);
+   write_name(&sb, ce->name);
+   strbuf_fputs(&sb, stdout);
if (debug_mode) {
const struct stat_data *sd = &ce->ce_stat_data;
 
@@ -206,7 +223,12 @@ static void show_ru_info(void)
printf("%s%06o %s %d\t", tag_resolve_undo, ui->mode[i],
   find_unique_abbrev(ui->sha1[i], abbrev),
   i + 1);
-   write_name(path);
+   /*
+* With "--full-name", prefix_len=0; this caller needs 
to pass
+* an empty string in that case (a NULL is good for "").
+*/
+   write_name_quoted_relative(path, prefix_len ? prefix : 
NULL,
+  stdout, line_terminator);
}
}
 }
-- 
1.9.1.345.ga1a145c

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 07/18] ls-files: add --column

2014-03-30 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 Documentation/git-ls-files.txt |  6 ++
 builtin/ls-files.c | 28 
 2 files changed, 34 insertions(+)

diff --git a/Documentation/git-ls-files.txt b/Documentation/git-ls-files.txt
index f006fc1..a5a30c2 100644
--- a/Documentation/git-ls-files.txt
+++ b/Documentation/git-ls-files.txt
@@ -154,6 +154,12 @@ a space) at the start of each line:
`--color=never`. `--color` is equivalent to
`--color=auto`.
 
+--column[=]::
+--no-column::
+   Display files in columns. See configuration variable column.ui
+   for option syntax. `--column` and `--no-column` without options
+   are equivalent to 'always' and 'never' respectively.
+
 \--::
Do not interpret any more arguments as options.
 
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 2857b38..a481c37 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -15,6 +15,7 @@
 #include "string-list.h"
 #include "pathspec.h"
 #include "color.h"
+#include "column.h"
 
 static int abbrev;
 static int show_deleted;
@@ -29,6 +30,7 @@ static int show_valid_bit;
 static int line_terminator = '\n';
 static int debug_mode;
 static int use_color;
+static unsigned int colopts;
 
 static const char *prefix;
 static int max_prefix_len;
@@ -39,6 +41,7 @@ static char *ps_matched;
 static const char *with_tree;
 static int exc_given;
 static int exclude_args;
+static struct string_list output = STRING_LIST_INIT_NODUP;
 
 static const char *tag_cached = "";
 static const char *tag_unmerged = "";
@@ -66,6 +69,10 @@ static void write_name(struct strbuf *sb, const char *name)
 
 static void strbuf_fputs(struct strbuf *sb, FILE *fp)
 {
+   if (column_active(colopts)) {
+   string_list_append(&output, strbuf_detach(sb, NULL));
+   return;
+   }
fwrite(sb->buf, sb->len, 1, fp);
 }
 
@@ -552,6 +559,7 @@ int cmd_ls_files(int argc, const char **argv, const char 
*cmd_prefix)
OPT_STRING(0, "with-tree", &with_tree, N_("tree-ish"),
N_("pretend that paths removed since  are 
still present")),
OPT__COLOR(&use_color, N_("show color")),
+   OPT_COLUMN(0, "column", &colopts, N_("show files in columns")),
OPT__ABBREV(&abbrev),
OPT_BOOL(0, "debug", &debug_mode, N_("show debugging data")),
OPT_END()
@@ -596,6 +604,18 @@ int cmd_ls_files(int argc, const char **argv, const char 
*cmd_prefix)
if (dir.exclude_per_dir)
exc_given = 1;
 
+   finalize_colopts(&colopts, -1);
+   if (explicitly_enable_column(colopts)) {
+   if (!line_terminator)
+   die(_("--column and -z are incompatible"));
+   if (show_resolve_undo)
+   die(_("--column and --resolve-undo are incompatible"));
+   if (debug_mode)
+   die(_("--column and --debug are incompatible"));
+   }
+   if (column_active(colopts))
+   line_terminator = 0;
+
if (require_work_tree && !is_inside_work_tree())
setup_work_tree();
 
@@ -638,6 +658,14 @@ int cmd_ls_files(int argc, const char **argv, const char 
*cmd_prefix)
if (show_resolve_undo)
show_ru_info();
 
+   if (column_active(colopts)) {
+   struct column_options copts;
+   memset(&copts, 0, sizeof(copts));
+   copts.padding = 2;
+   print_columns(&output, colopts, &copts);
+   string_list_clear(&output, 0);
+   }
+
if (ps_matched) {
int bad;
bad = report_path_error(ps_matched, &pathspec, prefix);
-- 
1.9.1.345.ga1a145c

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 02/18] ls_colors.c: parse color.ls.* from config file

2014-03-30 Thread Nguyễn Thái Ngọc Duy
This is the second (and preferred) source for color information. This
will override $LS_COLORS.

Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 Documentation/config.txt | 11 +++
 ls_colors.c  | 26 ++
 2 files changed, 37 insertions(+)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 73c8973..3fb754e 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -909,6 +909,17 @@ color.status.::
to red). The values of these variables may be specified as in
color.branch..
 
+color.ls.::
+   Use customized color for file name colorization. If not set
+   and the environment variable LS_COLORS is set, color settings
+   from $LS_COLORS are used. `` can be `normal`, `file`,
+   `directory`, `symlink`, `fifo`, `socket`, `block`, `char`,
+   `missing`, `orphan`, `executable`, `door`, `setuid`, `setgid`,
+   `sticky`, `otherwritable`, `stickyotherwritable`, `cap`,
+   `multihardlink`. The values of these variables may be
+   specified as in color.branch..
+
+
 color.ui::
This variable determines the default value for variables such
as `color.diff` and `color.grep` that control the use of color
diff --git a/ls_colors.c b/ls_colors.c
index eb944f4..cef5a92 100644
--- a/ls_colors.c
+++ b/ls_colors.c
@@ -68,6 +68,14 @@ static const char *const indicator_name[] = {
NULL
 };
 
+static const char* const config_name[] = {
+   "", "", "", "", "normal", "file", "directory", "symlink",
+   "fifo", "socket", "block", "char", "missing", "orphan", "executable",
+   "door", "setuid", "setgid", "sticky", "otherwritable",
+   "stickyotherwritable", "cap", "multihardlink", "",
+   NULL
+};
+
 struct bin_str {
size_t len; /* Number of bytes */
const char *string; /* Pointer to the same */
@@ -285,6 +293,23 @@ static int get_funky_string(char **dest, const char **src, 
int equals_end,
return state != ST_ERROR;
 }
 
+static int ls_colors_config(const char *var, const char *value, void *cb)
+{
+   int slot;
+   if (!starts_with(var, "color.ls."))
+   return 0;
+   var += 9;
+   for (slot = 0; config_name[slot]; slot++)
+   if (!strcasecmp(var, config_name[slot]))
+   break;
+   if (!config_name[slot])
+   return 0;
+   if (!value)
+   return config_error_nonbool(var);
+   color_parse(value, var, ls_colors[slot]);
+   return 0;
+}
+
 void parse_ls_color(void)
 {
const char *p;  /* Pointer to character being parsed */
@@ -395,4 +420,5 @@ void parse_ls_color(void)
 
if (!strcmp(ls_colors[LS_LN], "target"))
color_symlink_as_referent = 1;
+   git_config(ls_colors_config, NULL);
 }
-- 
1.9.1.345.ga1a145c

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 06/18] ls-files: add --color to highlight file names

2014-03-30 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 Documentation/git-ls-files.txt |  7 +++
 builtin/ls-files.c | 38 +++---
 2 files changed, 42 insertions(+), 3 deletions(-)

diff --git a/Documentation/git-ls-files.txt b/Documentation/git-ls-files.txt
index c0856a6..f006fc1 100644
--- a/Documentation/git-ls-files.txt
+++ b/Documentation/git-ls-files.txt
@@ -147,6 +147,13 @@ a space) at the start of each line:
possible for manual inspection; the exact format may change at
any time.
 
+--color[=]::
+--no-color::
+   Color file names. The value must be `always`, `never`, or
+   `auto`. `--no-color` is equivalent to
+   `--color=never`. `--color` is equivalent to
+   `--color=auto`.
+
 \--::
Do not interpret any more arguments as options.
 
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 6e30592..2857b38 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -14,6 +14,7 @@
 #include "resolve-undo.h"
 #include "string-list.h"
 #include "pathspec.h"
+#include "color.h"
 
 static int abbrev;
 static int show_deleted;
@@ -27,6 +28,7 @@ static int show_killed;
 static int show_valid_bit;
 static int line_terminator = '\n';
 static int debug_mode;
+static int use_color;
 
 static const char *prefix;
 static int max_prefix_len;
@@ -60,7 +62,6 @@ static void write_name(struct strbuf *sb, const char *name)
strbuf_release(&sb2);
} else
quote_path_relative(name, real_prefix, sb);
-   strbuf_addch(sb, line_terminator);
 }
 
 static void strbuf_fputs(struct strbuf *sb, FILE *fp)
@@ -68,6 +69,21 @@ static void strbuf_fputs(struct strbuf *sb, FILE *fp)
fwrite(sb->buf, sb->len, 1, fp);
 }
 
+static void write_dir_entry(struct strbuf *sb, const struct dir_entry *ent)
+{
+   struct strbuf quoted = STRBUF_INIT;
+   struct stat st;
+   if (stat(ent->name, &st))
+   st.st_mode = 0;
+   write_name("ed, ent->name);
+   if (want_color(use_color))
+   color_filename(sb, ent->name, quoted.buf, st.st_mode, 1);
+   else
+   strbuf_addbuf(sb, "ed);
+   strbuf_addch(sb, line_terminator);
+   strbuf_release("ed);
+}
+
 static void show_dir_entry(const char *tag, struct dir_entry *ent)
 {
static struct strbuf sb = STRBUF_INIT;
@@ -81,7 +97,7 @@ static void show_dir_entry(const char *tag, struct dir_entry 
*ent)
 
strbuf_reset(&sb);
strbuf_addstr(&sb, tag);
-   write_name(&sb, ent->name);
+   write_dir_entry(&sb, ent);
strbuf_fputs(&sb, stdout);
 }
 
@@ -146,6 +162,18 @@ static void show_killed_files(struct dir_struct *dir)
}
 }
 
+static void write_ce_name(struct strbuf *sb, const struct cache_entry *ce)
+{
+   struct strbuf quoted = STRBUF_INIT;
+   write_name("ed, ce->name);
+   if (want_color(use_color))
+   color_filename(sb, ce->name, quoted.buf, ce->ce_mode, 1);
+   else
+   strbuf_addbuf(sb, "ed);
+   strbuf_addch(sb, line_terminator);
+   strbuf_release("ed);
+}
+
 static void show_ce_entry(const char *tag, const struct cache_entry *ce)
 {
static struct strbuf sb = STRBUF_INIT;
@@ -186,7 +214,7 @@ static void show_ce_entry(const char *tag, const struct 
cache_entry *ce)
find_unique_abbrev(ce->sha1,abbrev),
ce_stage(ce));
}
-   write_name(&sb, ce->name);
+   write_ce_name(&sb, ce);
strbuf_fputs(&sb, stdout);
if (debug_mode) {
const struct stat_data *sd = &ce->ce_stat_data;
@@ -523,6 +551,7 @@ int cmd_ls_files(int argc, const char **argv, const char 
*cmd_prefix)
N_("if any  is not in the index, treat this as an 
error")),
OPT_STRING(0, "with-tree", &with_tree, N_("tree-ish"),
N_("pretend that paths removed since  are 
still present")),
+   OPT__COLOR(&use_color, N_("show color")),
OPT__ABBREV(&abbrev),
OPT_BOOL(0, "debug", &debug_mode, N_("show debugging data")),
OPT_END()
@@ -570,6 +599,9 @@ int cmd_ls_files(int argc, const char **argv, const char 
*cmd_prefix)
if (require_work_tree && !is_inside_work_tree())
setup_work_tree();
 
+   if (want_color(use_color))
+   parse_ls_color();
+
parse_pathspec(&pathspec, 0,
   PATHSPEC_PREFER_CWD |
   PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP,
-- 
1.9.1.345.ga1a145c

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 10/18] list-files: -u does not imply showing stages

2014-03-30 Thread Nguyễn Thái Ngọc Duy
Showing full index entry information is something for ls-files
only. The users of "git list-files" may just want to know what entries
are not unmerged.

Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 builtin/ls-files.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 0ae07b0..addbcce 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -656,7 +656,7 @@ int cmd_ls_files(int argc, const char **argv, const char 
*cmd_prefix)
}
if (show_modified || show_others || show_deleted || (dir.flags & 
DIR_SHOW_IGNORED) || show_killed)
require_work_tree = 1;
-   if (show_unmerged)
+   if (show_unmerged && !porcelain)
/*
 * There's no point in showing unmerged unless
 * you also show the stage information.
-- 
1.9.1.345.ga1a145c

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 09/18] Add git-list-files, a user friendly version of ls-files and more

2014-03-30 Thread Nguyễn Thái Ngọc Duy
This is more user friendly version of ls-files:

* it's automatically colored and columnized
* it refreshes the index like all porcelain commands
* it defaults to non-recursive behavior like ls
* :(glob) is on by default so '*.c' means a.c but not a/b.c, use
  '**/*.c' for that.
* auto pager

The name 'ls' is not taken. It is left for the user to make an alias
with better default options.

Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 .gitignore |  1 +
 Documentation/config.txt   | 10 +
 Documentation/git-list-files.txt (new) | 80 ++
 Makefile   |  1 +
 builtin/ls-files.c | 69 +++--
 command-list.txt   |  1 +
 git.c  |  1 +
 7 files changed, 159 insertions(+), 4 deletions(-)
 create mode 100644 Documentation/git-list-files.txt

diff --git a/.gitignore b/.gitignore
index dc600f9..faeac5d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -75,6 +75,7 @@
 /git-init
 /git-init-db
 /git-instaweb
+/git-list-files
 /git-log
 /git-ls-files
 /git-ls-remote
diff --git a/Documentation/config.txt b/Documentation/config.txt
index 6bca55e..e07e8bc 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -909,6 +909,12 @@ color.status.::
to red). The values of these variables may be specified as in
color.branch..
 
+color.list-files::
+   A boolean to enable/disable color in the output of
+   linkgit:git-list-files[1]. May be set to `always`, `false` (or
+   `never`) or `auto` (or `true`), in which case colors are used
+   only when the output is to a terminal. Defaults to false.
+
 color.ls.::
Use customized color for file name colorization. If not set
and the environment variable LS_COLORS is set, color settings
@@ -981,6 +987,10 @@ column.clean::
Specify the layout when list items in `git clean -i`, which always
shows files and directories in columns. See `column.ui` for details.
 
+column.list-files::
+   Specify whether to output tag listing in `git list-files` in columns.
+   See `column.ui` for details.
+
 column.status::
Specify whether to output untracked files in `git status` in columns.
See `column.ui` for details.
diff --git a/Documentation/git-list-files.txt b/Documentation/git-list-files.txt
new file mode 100644
index 000..3039e1e
--- /dev/null
+++ b/Documentation/git-list-files.txt
@@ -0,0 +1,80 @@
+git-list-files(1)
+===
+
+NAME
+
+git-list-files - List files
+
+SYNOPSIS
+
+[verse]
+'git list-files [options] [...]
+
+DESCRIPTION
+---
+List files (by default in current working directory) that are in the
+index. Depending on the chosen options, maybe only modified files in
+working tree are shown, or untracked files...
+
+OPTIONS
+---
+-c::
+--cached::
+   Show cached files (default)
+
+-d::
+--deleted::
+   Show cached files that are deleted on working directory
+
+-m::
+--modified::
+   Show cached files that have modification on working directory
+
+-o::
+--others::
+   Show untracked files (and only unignored ones unless -i is
+   specified)
+
+-i::
+--ignored::
+   Show only ignored files. When showing files in the index,
+   print only those matched by an exclude pattern. When showing
+   "other" files, show only those matched by an exclude pattern.
+
+-u::
+--unmerged::
+   Show unmerged files
+
+--color[=]::
+--no-color::
+   Color file names. The value must be `always`, `never`, or
+   `auto`. `--no-color` is equivalent to
+   `--color=never`. `--color` is equivalent to
+   `--color=auto`. See configuration variable `color.list-files`
+   for the default settings.
+
+--column[=]::
+--no-column::
+   Display files in columns. See configuration variable column.ui
+   for option syntax. `--column` and `--no-column` without options
+   are equivalent to 'always' and 'never' respectively.
+
+--max-depth=::
+   For each  given on command line, descend at most 
+   levels of directories. A negative value means no limit.
+   This option is ignored if  contains active wildcards.
+   In other words if "a*" matches a directory named "a*",
+   "*" is matched literally so --max-depth is still effective.
+   The default is `--max-depth=0`.
+
+::
+   Files to show. :(glob) magic is enabled and recursion disabled
+   by default.
+
+SEE ALSO
+
+linkgit:git-ls-files[1]
+
+GIT
+---
+Part of the linkgit:git[1] suite
diff --git a/Makefile b/Makefile
index f6a6e14..6104e05 100644
--- a/Makefile
+++ b/Makefile
@@ -584,6 +584,7 @@ BUILT_INS += git-cherry-pick$X
 BUILT_INS += git-format-patch$X
 BUILT_INS += git-fsck-objects$X
 BUILT_INS += git-init$X
+BUILT_INS += git-list-files$X
 BUILT_INS += git-merge-subtree$X
 BUILT_INS += git-show$X
 BUILT_INS += git-stage$X
diff --git a/builtin/ls-fi

[PATCH v3 08/18] ls-files: support --max-depth

2014-03-30 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 Documentation/git-ls-files.txt | 7 +++
 builtin/ls-files.c | 7 +++
 2 files changed, 14 insertions(+)

diff --git a/Documentation/git-ls-files.txt b/Documentation/git-ls-files.txt
index a5a30c2..ad621b5 100644
--- a/Documentation/git-ls-files.txt
+++ b/Documentation/git-ls-files.txt
@@ -160,6 +160,13 @@ a space) at the start of each line:
for option syntax. `--column` and `--no-column` without options
are equivalent to 'always' and 'never' respectively.
 
+--max-depth=::
+   For each  given on command line, descend at most 
+   levels of directories. A negative value means no limit (default).
+   This option is ignored if  contains active wildcards.
+   In other words if "a*" matches a directory named "a*",
+   "*" is matched literally so --max-depth is still effective.
+
 \--::
Do not interpret any more arguments as options.
 
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index a481c37..130bed0 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -503,6 +503,7 @@ static int option_parse_exclude_standard(const struct 
option *opt,
 int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
 {
int require_work_tree = 0, show_tag = 0, i;
+   int max_depth = -1;
const char *max_prefix;
struct dir_struct dir;
struct exclude_list *el;
@@ -560,6 +561,9 @@ int cmd_ls_files(int argc, const char **argv, const char 
*cmd_prefix)
N_("pretend that paths removed since  are 
still present")),
OPT__COLOR(&use_color, N_("show color")),
OPT_COLUMN(0, "column", &colopts, N_("show files in columns")),
+   { OPTION_INTEGER, 0, "max-depth", &max_depth, N_("depth"),
+   N_("descend at most  levels"), PARSE_OPT_NONEG,
+   NULL, 1 },
OPT__ABBREV(&abbrev),
OPT_BOOL(0, "debug", &debug_mode, N_("show debugging data")),
OPT_END()
@@ -624,8 +628,11 @@ int cmd_ls_files(int argc, const char **argv, const char 
*cmd_prefix)
 
parse_pathspec(&pathspec, 0,
   PATHSPEC_PREFER_CWD |
+  (max_depth != -1 ? PATHSPEC_MAXDEPTH_VALID : 0) |
   PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP,
   prefix, argv);
+   pathspec.max_depth = max_depth;
+   pathspec.recursive = 1;
 
/* Find common prefix for all pathspec's */
max_prefix = common_prefix(&pathspec);
-- 
1.9.1.345.ga1a145c

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 11/18] list-files: add -R/--recursive short for --max-depth=-1

2014-03-30 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 Documentation/git-list-files.txt | 4 
 builtin/ls-files.c   | 2 ++
 2 files changed, 6 insertions(+)

diff --git a/Documentation/git-list-files.txt b/Documentation/git-list-files.txt
index 3039e1e..5dccbbc 100644
--- a/Documentation/git-list-files.txt
+++ b/Documentation/git-list-files.txt
@@ -45,6 +45,10 @@ OPTIONS
 --unmerged::
Show unmerged files
 
+-R::
+--recursive::
+   Equivalent of `--max-depth=-1` (infinite recursion).
+
 --color[=]::
 --no-color::
Color file names. The value must be `always`, `never`, or
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index addbcce..656b632 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -594,6 +594,8 @@ int cmd_ls_files(int argc, const char **argv, const char 
*cmd_prefix)
N_("show cached files that have modification on working 
directory")),
OPT_BOOL('o', "others", &show_others,
N_("show untracked files")),
+   OPT_SET_INT('R', "recursive", &max_depth,
+   N_("shortcut for --max-depth=-1"), -1),
OPT_BIT('i', "ignored", &dir.flags,
N_("show ignored files"),
DIR_SHOW_IGNORED),
-- 
1.9.1.345.ga1a145c

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 13/18] list-files: add -t back

2014-03-30 Thread Nguyễn Thái Ngọc Duy
Tag "H" (cached) is not shown though because it's usually the majority
and becomes noise. Not showing it makes the other tags stand out. -t
is on by default if more than one file category is selected.

Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 Documentation/git-list-files.txt |  6 ++
 builtin/ls-files.c   | 27 +--
 2 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/Documentation/git-list-files.txt b/Documentation/git-list-files.txt
index 725a236..0ef616b 100644
--- a/Documentation/git-list-files.txt
+++ b/Documentation/git-list-files.txt
@@ -45,6 +45,12 @@ OPTIONS
 --unmerged::
Show unmerged files
 
+-t::
+--[no-]tag::
+   Show a tag to indicate file type. Automatically turned on with
+   multiple file selections. See linkgit::git-ls-files[1] option
+   `-t` for more information.
+
 -R::
 --recursive::
Equivalent of `--max-depth=-1` (infinite recursion).
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index db0ee6b..14dfd2a 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -596,6 +596,8 @@ int cmd_ls_files(int argc, const char **argv, const char 
*cmd_prefix)
N_("show untracked files")),
OPT_SET_INT('R', "recursive", &max_depth,
N_("shortcut for --max-depth=-1"), -1),
+   OPT_BOOL('t', "tag", &show_tag,
+   N_("identify the file status with tags")),
OPT_BIT('i', "ignored", &dir.flags,
N_("show ignored files"),
DIR_SHOW_IGNORED),
@@ -636,6 +638,7 @@ int cmd_ls_files(int argc, const char **argv, const char 
*cmd_prefix)
setup_standard_excludes(&dir);
use_color = -1;
max_depth = 0;
+   show_tag = -1;
git_config(git_ls_config, NULL);
} else
git_config(git_default_config, NULL);
@@ -648,16 +651,6 @@ int cmd_ls_files(int argc, const char **argv, const char 
*cmd_prefix)
for (i = 0; i < exclude_list.nr; i++) {
add_exclude(exclude_list.items[i].string, "", 0, el, 
--exclude_args);
}
-   if (show_tag || show_valid_bit) {
-   tag_cached = "H ";
-   tag_unmerged = "M ";
-   tag_removed = "R ";
-   tag_modified = "C ";
-   tag_other = "? ";
-   tag_killed = "K ";
-   tag_skip_worktree = "S ";
-   tag_resolve_undo = "U ";
-   }
if (show_modified || show_others || show_deleted || (dir.flags & 
DIR_SHOW_IGNORED) || show_killed)
require_work_tree = 1;
if (show_unmerged && !porcelain)
@@ -711,6 +704,20 @@ int cmd_ls_files(int argc, const char **argv, const char 
*cmd_prefix)
  show_killed || show_modified || show_resolve_undo))
show_cached = 1;
 
+   if (show_tag == -1)
+   show_tag = (show_cached + show_deleted + show_others +
+   show_unmerged + show_killed + show_modified) > 1;
+   if (show_tag || show_valid_bit) {
+   tag_cached = porcelain ? "  " : "H ";
+   tag_unmerged = "M ";
+   tag_removed = "R ";
+   tag_modified = "C ";
+   tag_other = "? ";
+   tag_killed = "K ";
+   tag_skip_worktree = "S ";
+   tag_resolve_undo = "U ";
+   }
+
if (max_prefix)
prune_cache(max_prefix);
if (with_tree) {
-- 
1.9.1.345.ga1a145c

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 12/18] list-files: add -1 short for --no-column

2014-03-30 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 Documentation/git-list-files.txt | 3 +++
 builtin/ls-files.c   | 2 ++
 2 files changed, 5 insertions(+)

diff --git a/Documentation/git-list-files.txt b/Documentation/git-list-files.txt
index 5dccbbc..725a236 100644
--- a/Documentation/git-list-files.txt
+++ b/Documentation/git-list-files.txt
@@ -49,6 +49,9 @@ OPTIONS
 --recursive::
Equivalent of `--max-depth=-1` (infinite recursion).
 
+-1::
+   Equivalent of --no-column.
+
 --color[=]::
 --no-color::
Color file names. The value must be `always`, `never`, or
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 656b632..db0ee6b 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -603,6 +603,8 @@ int cmd_ls_files(int argc, const char **argv, const char 
*cmd_prefix)
N_("show unmerged files")),
OPT__COLOR(&use_color, N_("show color")),
OPT_COLUMN(0, "column", &colopts, N_("show files in columns")),
+   OPT_SET_INT('1', NULL, &colopts,
+   N_("shortcut for --no-column"), COL_PARSEOPT),
{ OPTION_INTEGER, 0, "max-depth", &max_depth, N_("depth"),
N_("descend at most  levels"), PARSE_OPT_NONEG,
NULL, 1 },
-- 
1.9.1.345.ga1a145c

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 15/18] list-files: do not show duplicate cached entries

2014-03-30 Thread Nguyễn Thái Ngọc Duy
With the current show_files() "list-files -tcm" will show

  foo.c
M foo.c

The first item is redundant. If "foo.c" is modified, we know it's in
the cache. Introduce show_files_compact to do that because ls-files is
plumbing and scripts may already depend on current display behavior.

Another difference in show_files_compact() is it does not show
skip-worktree (aka outside sparse checkout) entries anymore, which
makes sense in porcelain context.

Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 builtin/ls-files.c | 52 +++-
 1 file changed, 51 insertions(+), 1 deletion(-)

diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index ff2377f..9a8f687 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -333,6 +333,53 @@ static void show_files(struct dir_struct *dir)
}
 }
 
+static void show_files_compact(struct dir_struct *dir)
+{
+   int i;
+
+   /* For cached/deleted files we don't need to even do the readdir */
+   if (show_others || show_killed) {
+   if (!show_others)
+   dir->flags |= DIR_COLLECT_KILLED_ONLY;
+   fill_directory(dir, &pathspec);
+   if (show_others)
+   show_other_files(dir);
+   if (show_killed)
+   show_killed_files(dir);
+   }
+   if (!(show_cached || show_stage || show_deleted || show_modified))
+   return;
+   for (i = 0; i < active_nr; i++) {
+   const struct cache_entry *ce = active_cache[i];
+   struct stat st;
+   int err, shown = 0;
+   if ((dir->flags & DIR_SHOW_IGNORED) &&
+   !ce_excluded(dir, ce))
+   continue;
+   if (show_unmerged && !ce_stage(ce))
+   continue;
+   if (ce->ce_flags & CE_UPDATE)
+   continue;
+   if (ce_skip_worktree(ce))
+   continue;
+   err = lstat(ce->name, &st);
+   if (show_deleted && err) {
+   show_ce_entry(tag_removed, ce);
+   shown = 1;
+   }
+   if (show_modified && (err || ce_modified(ce, &st, 0))) {
+   show_ce_entry(tag_modified, ce);
+   shown = 1;
+   }
+   if (ce_stage(ce)) {
+   show_ce_entry(tag_unmerged, ce);
+   shown = 1;
+   }
+   if (!shown && show_cached)
+   show_ce_entry(tag_cached, ce);
+   }
+}
+
 /*
  * Prune the index to only contain stuff starting with "prefix"
  */
@@ -743,7 +790,10 @@ int cmd_ls_files(int argc, const char **argv, const char 
*cmd_prefix)
refresh_index(&the_index, REFRESH_QUIET, &pathspec, NULL, NULL);
setup_pager();
}
-   show_files(&dir);
+   if (porcelain)
+   show_files_compact(&dir);
+   else
+   show_files(&dir);
if (show_resolve_undo)
show_ru_info();
 
-- 
1.9.1.345.ga1a145c

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 17/18] list-files: add -F/--classify

2014-03-30 Thread Nguyễn Thái Ngọc Duy
This appends an indicator after the file name if it's executable, a
directory and so on, like in GNU ls. In fact append_indicator() is a
rewrite from get_type_indicator() in coreutils.git commit
7326d1f1a67edf21947ae98194f98c38b6e9e527.

Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 Documentation/git-list-files.txt |  6 ++
 builtin/ls-files.c   | 31 +++
 2 files changed, 37 insertions(+)

diff --git a/Documentation/git-list-files.txt b/Documentation/git-list-files.txt
index 0ef616b..22084eb 100644
--- a/Documentation/git-list-files.txt
+++ b/Documentation/git-list-files.txt
@@ -51,6 +51,12 @@ OPTIONS
multiple file selections. See linkgit::git-ls-files[1] option
`-t` for more information.
 
+-F::
+--classify::
+   Append indicator (one of `*/=>@|`, which is executable,
+   directory, socket, Solaris door, symlink, or fifo
+   respectively) to entries.
+
 -R::
 --recursive::
Equivalent of `--max-depth=-1` (infinite recursion).
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 9dc1c39..2d475f0 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -29,6 +29,7 @@ static int show_killed;
 static int show_valid_bit;
 static int show_tag;
 static int show_dirs;
+static int show_indicator;
 static int line_terminator = '\n';
 static int debug_mode;
 static int use_color;
@@ -77,6 +78,28 @@ static void write_name(struct strbuf *sb, const char *name)
quote_path_relative(name, real_prefix, sb);
 }
 
+static void append_indicator(struct strbuf *sb, mode_t mode)
+{
+   char c = 0;
+   if (S_ISREG(mode)) {
+   if (mode & (S_IXUSR | S_IXGRP | S_IXOTH))
+   c = '*';
+   } else if (S_ISDIR(mode))
+   c = '/';
+   else if (S_ISLNK(mode))
+   c = '@';
+   else if (S_ISFIFO(mode))
+   c = '|';
+   else if (S_ISSOCK(mode))
+   c = '=';
+#ifdef S_ISDOOR
+   else if (S_ISDOOR(mode))
+   c = '>';
+#endif
+   if (c)
+   strbuf_addch(sb, c);
+}
+
 static void strbuf_fputs(struct strbuf *sb, const char *full_name, FILE *fp)
 {
if (column_active(colopts) || porcelain) {
@@ -99,6 +122,8 @@ static void write_dir_entry(struct strbuf *sb, const struct 
dir_entry *ent)
color_filename(sb, ent->name, quoted.buf, st.st_mode, 1);
else
strbuf_addbuf(sb, "ed);
+   if (show_indicator && st.st_mode)
+   append_indicator(sb, st.st_mode);
strbuf_addch(sb, line_terminator);
strbuf_release("ed);
 }
@@ -189,6 +214,8 @@ static void write_ce_name(struct strbuf *sb, const struct 
cache_entry *ce)
color_filename(sb, ce->name, quoted.buf, ce->ce_mode, 1);
else
strbuf_addbuf(sb, "ed);
+   if (show_indicator)
+   append_indicator(sb, ce->ce_mode);
strbuf_addch(sb, line_terminator);
strbuf_release("ed);
 }
@@ -366,6 +393,8 @@ static void show_directories(const struct cache_entry *ce)
}
if (show_tag)
strbuf_insert(&sb2, 0, tag_cached, strlen(tag_cached));
+   if (show_indicator)
+   append_indicator(&sb2, S_IFDIR);
last_directory = strbuf_detach(&sb, NULL);
strbuf_fputs(&sb2, last_directory, NULL);
strbuf_release(&sb2);
@@ -701,6 +730,8 @@ int cmd_ls_files(int argc, const char **argv, const char 
*cmd_prefix)
DIR_SHOW_IGNORED),
OPT_BOOL('u', "unmerged", &show_unmerged,
N_("show unmerged files")),
+   OPT_BOOL('F', "classify", &show_indicator,
+N_("append indicator (one of */=>@|) to entries")),
OPT__COLOR(&use_color, N_("show color")),
OPT_COLUMN(0, "column", &colopts, N_("show files in columns")),
OPT_SET_INT('1', NULL, &colopts,
-- 
1.9.1.345.ga1a145c

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


git@vger.kernel.org

2014-03-30 Thread Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 Documentation/git-list-files.txt | 4 ++--
 builtin/ls-files.c   | 2 ++
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/Documentation/git-list-files.txt b/Documentation/git-list-files.txt
index 22084eb..c57129b 100644
--- a/Documentation/git-list-files.txt
+++ b/Documentation/git-list-files.txt
@@ -53,8 +53,8 @@ OPTIONS
 
 -F::
 --classify::
-   Append indicator (one of `*/=>@|`, which is executable,
-   directory, socket, Solaris door, symlink, or fifo
+   Append indicator (one of `*/=>@|&`, which is executable,
+   directory, socket, Solaris door, symlink, fifo, or submodule
respectively) to entries.
 
 -R::
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 2d475f0..f3e34db 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -92,6 +92,8 @@ static void append_indicator(struct strbuf *sb, mode_t mode)
c = '|';
else if (S_ISSOCK(mode))
c = '=';
+   else if (S_ISGITLINK(mode))
+   c = '&';
 #ifdef S_ISDOOR
else if (S_ISDOOR(mode))
c = '>';
-- 
1.9.1.345.ga1a145c

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 14/18] list-files: sort output and remove duplicates

2014-03-30 Thread Nguyễn Thái Ngọc Duy
When you mix different file types, with ls-files you may get separate
listing. For example, "ls-files -cm" will show file "abc" twice: one
as part of cached list, one of modified list. With "ls" (and this
patch) they will be in a single sorted list (easier for the eye).

Duplicate entries are also removed. Note that display content is
compared, so if you have "-t" on, or you color file types differently,
you will get duplicate textual entries. This is good imo.

Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 builtin/ls-files.c | 36 
 1 file changed, 24 insertions(+), 12 deletions(-)

diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 14dfd2a..ff2377f 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -53,6 +53,13 @@ static const char *tag_modified = "";
 static const char *tag_skip_worktree = "";
 static const char *tag_resolve_undo = "";
 
+static int compare_output(const void *a_, const void *b_)
+{
+   const struct string_list_item *a = a_;
+   const struct string_list_item *b = b_;
+   return strcmp(a->util, b->util);
+}
+
 static void write_name(struct strbuf *sb, const char *name)
 {
/*
@@ -68,10 +75,12 @@ static void write_name(struct strbuf *sb, const char *name)
quote_path_relative(name, real_prefix, sb);
 }
 
-static void strbuf_fputs(struct strbuf *sb, FILE *fp)
+static void strbuf_fputs(struct strbuf *sb, const char *full_name, FILE *fp)
 {
-   if (column_active(colopts)) {
-   string_list_append(&output, strbuf_detach(sb, NULL));
+   if (column_active(colopts) || porcelain) {
+   struct string_list_item *it;
+   it = string_list_append(&output, strbuf_detach(sb, NULL));
+   it->util = (void*)full_name;
return;
}
fwrite(sb->buf, sb->len, 1, fp);
@@ -106,7 +115,7 @@ static void show_dir_entry(const char *tag, struct 
dir_entry *ent)
strbuf_reset(&sb);
strbuf_addstr(&sb, tag);
write_dir_entry(&sb, ent);
-   strbuf_fputs(&sb, stdout);
+   strbuf_fputs(&sb, ent->name, stdout);
 }
 
 static void show_other_files(struct dir_struct *dir)
@@ -223,7 +232,7 @@ static void show_ce_entry(const char *tag, const struct 
cache_entry *ce)
ce_stage(ce));
}
write_ce_name(&sb, ce);
-   strbuf_fputs(&sb, stdout);
+   strbuf_fputs(&sb, ce->name, stdout);
if (debug_mode) {
const struct stat_data *sd = &ce->ce_stat_data;
 
@@ -524,6 +533,7 @@ int cmd_ls_files(int argc, const char **argv, const char 
*cmd_prefix)
const char *max_prefix;
struct dir_struct dir;
struct exclude_list *el;
+   struct column_options copts;
struct string_list exclude_list = STRING_LIST_INIT_NODUP;
struct option builtin_ls_files_options[] = {
{ OPTION_CALLBACK, 'z', NULL, NULL, NULL,
@@ -671,7 +681,7 @@ int cmd_ls_files(int argc, const char **argv, const char 
*cmd_prefix)
if (debug_mode)
die(_("--column and --debug are incompatible"));
}
-   if (column_active(colopts))
+   if (column_active(colopts) || porcelain)
line_terminator = 0;
 
if (require_work_tree && !is_inside_work_tree())
@@ -737,13 +747,15 @@ int cmd_ls_files(int argc, const char **argv, const char 
*cmd_prefix)
if (show_resolve_undo)
show_ru_info();
 
-   if (column_active(colopts)) {
-   struct column_options copts;
-   memset(&copts, 0, sizeof(copts));
-   copts.padding = 2;
-   print_columns(&output, colopts, &copts);
-   string_list_clear(&output, 0);
+   memset(&copts, 0, sizeof(copts));
+   copts.padding = 2;
+   if (porcelain) {
+   qsort(output.items, output.nr, sizeof(*output.items),
+ compare_output);
+   string_list_remove_duplicates(&output, 0);
}
+   print_columns(&output, colopts, &copts);
+   string_list_clear(&output, 0);
 
if (ps_matched) {
int bad;
-- 
1.9.1.345.ga1a145c

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 16/18] list-files: show directories as well as files

2014-03-30 Thread Nguyễn Thái Ngọc Duy
The index does not store directories explicitly (except submodules) so
we have to figure them out from file list. The function
show_directories() deliberately generates duplicate directories and
expects the previous patch to remove duplicates.

Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 builtin/ls-files.c | 44 +++-
 1 file changed, 43 insertions(+), 1 deletion(-)

diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 9a8f687..9dc1c39 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -27,6 +27,8 @@ static int show_resolve_undo;
 static int show_modified;
 static int show_killed;
 static int show_valid_bit;
+static int show_tag;
+static int show_dirs;
 static int line_terminator = '\n';
 static int debug_mode;
 static int use_color;
@@ -333,6 +335,43 @@ static void show_files(struct dir_struct *dir)
}
 }
 
+static void show_directories(const struct cache_entry *ce)
+{
+   static const char *last_directory;
+   struct strbuf sb = STRBUF_INIT;
+   const char *p = ce->name + prefix_len;
+   const char *sep;
+
+   if (last_directory) {
+   int len = strlen(last_directory);
+   if (!strncmp(ce->name, last_directory, len) &&
+   ce->name[len] == '/')
+   p += len + 1;
+   }
+
+   while (*p && (sep = strchr(p, '/'))) {
+   struct strbuf sb2 = STRBUF_INIT;
+   strbuf_reset(&sb);
+   strbuf_add(&sb, ce->name, sep - ce->name);
+   p = sep + 1;
+   if (!match_pathspec(&pathspec, sb.buf, sb.len,
+   prefix_len, NULL, 1))
+   continue;
+   write_name(&sb2, sb.buf);
+   if (want_color(use_color)) {
+   struct strbuf sb3 = STRBUF_INIT;
+   color_filename(&sb3, ce->name, sb2.buf, S_IFDIR, 1);
+   strbuf_release(&sb2);
+   sb2 = sb3;
+   }
+   if (show_tag)
+   strbuf_insert(&sb2, 0, tag_cached, strlen(tag_cached));
+   last_directory = strbuf_detach(&sb, NULL);
+   strbuf_fputs(&sb2, last_directory, NULL);
+   strbuf_release(&sb2);
+   }
+}
+
 static void show_files_compact(struct dir_struct *dir)
 {
int i;
@@ -353,6 +392,8 @@ static void show_files_compact(struct dir_struct *dir)
const struct cache_entry *ce = active_cache[i];
struct stat st;
int err, shown = 0;
+   if (show_dirs)
+   show_directories(ce);
if ((dir->flags & DIR_SHOW_IGNORED) &&
!ce_excluded(dir, ce))
continue;
@@ -575,7 +616,7 @@ static int git_ls_config(const char *var, const char 
*value, void *cb)
 
 int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
 {
-   int require_work_tree = 0, show_tag = 0, i;
+   int require_work_tree = 0, i;
int max_depth = -1;
const char *max_prefix;
struct dir_struct dir;
@@ -696,6 +737,7 @@ int cmd_ls_files(int argc, const char **argv, const char 
*cmd_prefix)
use_color = -1;
max_depth = 0;
show_tag = -1;
+   show_dirs = 1;
git_config(git_ls_config, NULL);
} else
git_config(git_default_config, NULL);
-- 
1.9.1.345.ga1a145c

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 1/3] patch-id: make it stable against hunk reordering

2014-03-30 Thread Michael S. Tsirkin
Patch id changes if users
1. reorder file diffs that make up a patch
or
2. split a patch up to multiple diffs that touch the same path
(keeping hunks within a single diff ordered to make patch valid).

As the result is functionally equivalent, a different patch id is
surprising to many users.
In particular, reordering files using diff -O is helpful to make patches
more readable (e.g. API header diff before implementation diff).

Change patch-id behaviour making it stable against these two kinds
of patch change:
1. calculate SHA1 hash for each hunk separately and sum all hashes
(using a symmetrical sum) to get patch id
2. hash the file-level headers together with each hunk (not just the
first hunk)

We use a 20byte sum and not xor - since xor would give 0 output
for patches that have two identical diffs, which isn't all that
unlikely (e.g. append the same line in two places).

Add a new flag --unstable to get the historical behaviour.

Add --stable which is a nop, for symmetry.

Signed-off-by: Michael S. Tsirkin 
---

changes from v2:
several bugfixes
changes from v1:
hanges from v1: documented motivation for supporting
diff splitting (and not just file reordering).
No code changes.

 builtin/patch-id.c | 72 ++
 1 file changed, 56 insertions(+), 16 deletions(-)

diff --git a/builtin/patch-id.c b/builtin/patch-id.c
index 3cfe02d..7fd7007 100644
--- a/builtin/patch-id.c
+++ b/builtin/patch-id.c
@@ -1,17 +1,14 @@
 #include "builtin.h"
 
-static void flush_current_id(int patchlen, unsigned char *id, git_SHA_CTX *c)
+static void flush_current_id(int patchlen, unsigned char *id, unsigned char 
*result)
 {
-   unsigned char result[20];
char name[50];
 
if (!patchlen)
return;
 
-   git_SHA1_Final(result, c);
memcpy(name, sha1_to_hex(id), 41);
printf("%s %s\n", sha1_to_hex(result), name);
-   git_SHA1_Init(c);
 }
 
 static int remove_space(char *line)
@@ -56,10 +53,31 @@ static int scan_hunk_header(const char *p, int *p_before, 
int *p_after)
return 1;
 }
 
-static int get_one_patchid(unsigned char *next_sha1, git_SHA_CTX *ctx, struct 
strbuf *line_buf)
+static void flush_one_hunk(unsigned char *result, git_SHA_CTX *ctx)
 {
-   int patchlen = 0, found_next = 0;
+   unsigned char hash[20];
+   unsigned short carry = 0;
+   int i;
+
+   git_SHA1_Final(hash, ctx);
+   git_SHA1_Init(ctx);
+   /* 20-byte sum, with carry */
+   for (i = 0; i < 20; ++i) {
+   carry += result[i] + hash[i];
+   result[i] = carry;
+   carry >>= 8;
+   }
+}
+
+static int get_one_patchid(unsigned char *next_sha1, unsigned char *result,
+  struct strbuf *line_buf, int stable)
+{
+   int patchlen = 0, found_next = 0, hunks = 0;
int before = -1, after = -1;
+   git_SHA_CTX ctx, header_ctx;
+
+   git_SHA1_Init(&ctx);
+   hashclr(result);
 
while (strbuf_getwholeline(line_buf, stdin, '\n') != EOF) {
char *line = line_buf->buf;
@@ -98,7 +116,19 @@ static int get_one_patchid(unsigned char *next_sha1, 
git_SHA_CTX *ctx, struct st
if (before == 0 && after == 0) {
if (!memcmp(line, "@@ -", 4)) {
/* Parse next hunk, but ignore line numbers.  */
+   if (stable) {
+   /* Hash the file-level headers together 
with each hunk. */
+   if (hunks) {
+   flush_one_hunk(result, &ctx);
+   /* Prepend saved header ctx for 
next hunk.  */
+   memcpy(&ctx, &header_ctx, 
sizeof ctx);
+   } else {
+   /* Save header ctx for next 
hunk.  */
+   memcpy(&header_ctx, &ctx, 
sizeof ctx);
+   }
+   }
scan_hunk_header(line, &before, &after);
+   hunks++;
continue;
}
 
@@ -107,7 +137,10 @@ static int get_one_patchid(unsigned char *next_sha1, 
git_SHA_CTX *ctx, struct st
break;
 
/* Else we're parsing another header.  */
+   if (stable && hunks)
+   flush_one_hunk(result, &ctx);
before = after = -1;
+   hunks = 0;
}
 
/* If we get here, we're inside a hunk.  */
@@ -119,39 +152,46 @@ static int get_one_patchid(unsigned char *next_sha1, 
git_SHA_CTX *ctx, struct st
/* Compute the sha without whitespace 

[PATCH v3 2/3] patch-id: document new behaviour

2014-03-30 Thread Michael S. Tsirkin
Clarify that patch ID is now a sum of hashes, not a hash.
Document --stable and --unstable flags.

Signed-off-by: Michael S. Tsirkin 
---

changes from v2:
explicitly list the kinds of changes against which patch ID is stable

 Documentation/git-patch-id.txt | 23 ++-
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/Documentation/git-patch-id.txt b/Documentation/git-patch-id.txt
index 312c3b1..30923e0 100644
--- a/Documentation/git-patch-id.txt
+++ b/Documentation/git-patch-id.txt
@@ -8,14 +8,14 @@ git-patch-id - Compute unique ID for a patch
 SYNOPSIS
 
 [verse]
-'git patch-id' < 
+'git patch-id' [--stable | --unstable] < 
 
 DESCRIPTION
 ---
-A "patch ID" is nothing but a SHA-1 of the diff associated with a patch, with
-whitespace and line numbers ignored.  As such, it's "reasonably stable", but at
-the same time also reasonably unique, i.e., two patches that have the same 
"patch
-ID" are almost guaranteed to be the same thing.
+A "patch ID" is nothing but a sum of SHA-1 of the diff hunks associated with a
+patch, with whitespace and line numbers ignored.  As such, it's "reasonably
+stable", but at the same time also reasonably unique, i.e., two patches that
+have the same "patch ID" are almost guaranteed to be the same thing.
 
 IOW, you can use this thing to look for likely duplicate commits.
 
@@ -27,6 +27,19 @@ This can be used to make a mapping from patch ID to commit 
ID.
 
 OPTIONS
 ---
+
+--stable::
+   Use a symmetrical sum of hashes as the patch ID.
+   With this option, reordering file diffs that make up a patch or
+   splitting a diff up to multiple diffs that touch the same path
+   does not affect the ID.
+   This is the default.
+
+--unstable::
+   Use a non-symmetrical sum of hashes, such that reordering
+   or splitting the patch does affect the ID.
+   This was the default value for git 1.9 and older.
+
 ::
The diff to create the ID of.
 
-- 
MST

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 3/3] patch-id-test: test --stable and --unstable flags

2014-03-30 Thread Michael S. Tsirkin
Verify that patch ID is now stable against diff split and reordering.

Signed-off-by: Michael S. Tsirkin 
---

Changes from v2:
added test to verify patch ID is stable against diff splitting

 t/t4204-patch-id.sh | 117 
 1 file changed, 109 insertions(+), 8 deletions(-)

diff --git a/t/t4204-patch-id.sh b/t/t4204-patch-id.sh
index d2c930d..1679714 100755
--- a/t/t4204-patch-id.sh
+++ b/t/t4204-patch-id.sh
@@ -5,12 +5,46 @@ test_description='git patch-id'
 . ./test-lib.sh
 
 test_expect_success 'setup' '
-   test_commit initial foo a &&
-   test_commit first foo b &&
-   git checkout -b same HEAD^ &&
-   test_commit same-msg foo b &&
-   git checkout -b notsame HEAD^ &&
-   test_commit notsame-msg foo c
+   cat > a <<-\EOF &&
+   a
+   a
+   a
+   a
+   a
+   a
+   a
+   a
+   EOF
+   (cat a; echo b) > ab &&
+   (echo d; cat a; echo b) > dab &&
+   cp a foo &&
+   cp a bar &&
+   git add foo bar &&
+   git commit -a -m initial &&
+   cp ab foo &&
+   cp ab bar &&
+   git commit -a -m first &&
+   git checkout -b same master &&
+   git commit --amend -m same-msg &&
+   git checkout -b notsame master &&
+   echo c > foo &&
+   echo c > bar &&
+   git commit --amend -a -m notsame-msg &&
+   git checkout -b split master &&
+   cp dab foo &&
+   cp dab bar &&
+   git commit -a -m split &&
+   git checkout -b merged master &&
+   git checkout split -- foo bar &&
+   git commit --amend -a -m merged &&
+   cat > bar-then-foo <<-\EOF &&
+   bar
+   foo
+   EOF
+   cat > foo-then-bar <<-\EOF
+   foo
+   bar
+   EOF
 '
 
 test_expect_success 'patch-id output is well-formed' '
@@ -23,11 +57,33 @@ calc_patch_id () {
sed "s# .*##" > patch-id_"$1"
 }
 
+calc_patch_id_unstable () {
+   git patch-id --unstable |
+   sed "s# .*##" > patch-id_"$1"
+}
+
+calc_patch_id_stable () {
+   git patch-id --stable |
+   sed "s# .*##" > patch-id_"$1"
+}
+
+
 get_patch_id () {
-   git log -p -1 "$1" | git patch-id |
+   git log -p -1 "$1" -O bar-then-foo -- | git patch-id |
sed "s# .*##" > patch-id_"$1"
 }
 
+get_patch_id_stable () {
+   git log -p -1 "$1" -O bar-then-foo | git patch-id --stable |
+   sed "s# .*##" > patch-id_"$1"
+}
+
+get_patch_id_unstable () {
+   git log -p -1 "$1" -O bar-then-foo | git patch-id --unstable |
+   sed "s# .*##" > patch-id_"$1"
+}
+
+
 test_expect_success 'patch-id detects equality' '
get_patch_id master &&
get_patch_id same &&
@@ -52,10 +108,55 @@ test_expect_success 'patch-id supports git-format-patch 
output' '
 test_expect_success 'whitespace is irrelevant in footer' '
get_patch_id master &&
git checkout same &&
-   git format-patch -1 --stdout | sed "s/ \$//" | calc_patch_id same &&
+   git format-patch -1 --stdout | sed "s/ \$//" |
+   calc_patch_id same &&
test_cmp patch-id_master patch-id_same
 '
 
+test_expect_success 'file order is irrelevant by default' '
+   get_patch_id master &&
+   git checkout same &&
+   git format-patch -1 --stdout -O foo-then-bar |
+   calc_patch_id same &&
+   test_cmp patch-id_master patch-id_same
+'
+
+test_expect_success 'file order is irrelevant with --stable' '
+   get_patch_id_stable master &&
+   git checkout same &&
+   git format-patch -1 --stdout -O foo-then-bar |
+   calc_patch_id_stable same &&
+   test_cmp patch-id_master patch-id_same
+'
+
+test_expect_success 'file order is relevant with --unstable' '
+   get_patch_id_unstable master &&
+   git checkout same &&
+   git format-patch -1 --stdout -O foo-then-bar | calc_patch_id_unstable 
notsame &&
+   ! test_cmp patch-id_master patch-id_notsame
+'
+
+test_expect_success 'splitting patch does not affect id by default' '
+   get_patch_id merged &&
+   (git log -p -1 -O foo-then-bar split~1; git diff split~1..split) |
+   calc_patch_id split &&
+   test_cmp patch-id_merged patch-id_split
+'
+
+test_expect_success 'splitting patch does not affect id with --stable' '
+   get_patch_id_stable merged &&
+   (git log -p -1 -O foo-then-bar split~1; git diff split~1..split) |
+   calc_patch_id_stable split &&
+   test_cmp patch-id_merged patch-id_split
+'
+
+test_expect_success 'splitting patch affects id with --unstable' '
+   get_patch_id_unstable merged &&
+   (git log -p -1 -O foo-then-bar split~1; git diff split~1..split) |
+   calc_patch_id_unstable split &&
+   ! test_cmp patch-id_merged patch-id_split
+'
+
 test_expect_success 'patch-id supports gi

socket_perror() "bug"?

2014-03-30 Thread Thiago Farina
Hi,

In imap-send.c:socket_perror() we pass |func| as a parameter, which I
think it is the name of the function that "called" socket_perror, or
the name of the function which generated an error.

But at line 184 and 187 it always assume it was SSL_connect.

Should we instead call perror() and ssl_socket_error() with func?

--
Thiago Farina
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/2] commit: add --ignore-submodules[=] parameter

2014-03-30 Thread Jens Lehmann
Am 29.03.2014 23:50, schrieb Ronald Weiss:
> Git commit honors the 'ignore' setting from .gitmodules or .git/config,
> but didn't allow to override it from command line, like other commands do.
> 
> Useful  values for commit are 'all' (default) or 'none'. The others
> ('dirty' and 'untracked') have same effect as 'none', as commit is only
> interested in whether the submodule's HEAD differs from what is commited
> in the superproject.
> 
> Changes in add.c and cache.h (and related compilo fix in checkout.c) are
> needed to make it work for "commit -a" too.

Looking good so far, but we definitely need tests for this new option.

But I wonder if it would make more sense to start by teaching the
--ignore-submodules option to git add. Then this patch could reuse
that for commit -a.

> Signed-off-by: Ronald Weiss 
> ---
>  Documentation/git-commit.txt |  6 ++
>  builtin/add.c| 16 
>  builtin/checkout.c   |  2 +-
>  builtin/commit.c |  8 +++-
>  cache.h  |  2 +-
>  5 files changed, 27 insertions(+), 7 deletions(-)
> 
> diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
> index 1a7616c..c8839c8 100644
> --- a/Documentation/git-commit.txt
> +++ b/Documentation/git-commit.txt
> @@ -13,6 +13,7 @@ SYNOPSIS
>  [-F  | -m ] [--reset-author] [--allow-empty]
>  [--allow-empty-message] [--no-verify] [-e] [--author=]
>  [--date=] [--cleanup=] [--[no-]status]
> +[--ignore-submodules[=]]
>  [-i | -o] [-S[]] [--] [...]
>  
>  DESCRIPTION
> @@ -271,6 +272,11 @@ The possible options are:
>  The default can be changed using the status.showUntrackedFiles
>  configuration variable documented in linkgit:git-config[1].
>  
> +--ignore-submodules[=]::
> + Can be used to override any settings of the 'ignore' option
> + in linkgit:git-config[1] or linkgit:gitmodules[5].
> +  can be either "none" or "all", which is the default.
> +
>  -v::
>  --verbose::
>   Show unified diff between the HEAD commit and what
> diff --git a/builtin/add.c b/builtin/add.c
> index 672adc0..1086294 100644
> --- a/builtin/add.c
> +++ b/builtin/add.c
> @@ -168,7 +168,8 @@ static void update_callback(struct diff_queue_struct *q,
>  
>  static void update_files_in_cache(const char *prefix,
> const struct pathspec *pathspec,
> -   struct update_callback_data *data)
> +   struct update_callback_data *data,
> +   const char *ignore_submodules_arg)
>  {
>   struct rev_info rev;
>  
> @@ -180,17 +181,24 @@ static void update_files_in_cache(const char *prefix,
>   rev.diffopt.format_callback = update_callback;
>   rev.diffopt.format_callback_data = data;
>   rev.max_count = 0; /* do not compare unmerged paths with stage #2 */
> +
> + if (ignore_submodules_arg) {
> + DIFF_OPT_SET(&rev.diffopt, OVERRIDE_SUBMODULE_CONFIG);
> + handle_ignore_submodules_arg(&rev.diffopt, 
> ignore_submodules_arg);
> + }
> +
>   run_diff_files(&rev, DIFF_RACY_IS_MODIFIED);
>  }
>  
>  int add_files_to_cache(const char *prefix,
> -const struct pathspec *pathspec, int flags)
> +const struct pathspec *pathspec, int flags,
> +const char *ignore_submodules_arg)
>  {
>   struct update_callback_data data;
>  
>   memset(&data, 0, sizeof(data));
>   data.flags = flags;
> - update_files_in_cache(prefix, pathspec, &data);
> + update_files_in_cache(prefix, pathspec, &data, ignore_submodules_arg);
>   return !!data.add_errors;
>  }
>  
> @@ -576,7 +584,7 @@ int cmd_add(int argc, const char **argv, const char 
> *prefix)
>   memset(&pathspec, 0, sizeof(pathspec));
>   }
>   update_data.flags = flags & ~ADD_CACHE_IMPLICIT_DOT;
> - update_files_in_cache(prefix, &pathspec, &update_data);
> + update_files_in_cache(prefix, &pathspec, &update_data, NULL);
>  
>   exit_status |= !!update_data.add_errors;
>   if (add_new_files)
> diff --git a/builtin/checkout.c b/builtin/checkout.c
> index ada51fa..22a4b48 100644
> --- a/builtin/checkout.c
> +++ b/builtin/checkout.c
> @@ -525,7 +525,7 @@ static int merge_working_tree(const struct checkout_opts 
> *opts,
>* entries in the index.
>*/
>  
> - add_files_to_cache(NULL, NULL, 0);
> + add_files_to_cache(NULL, NULL, 0, NULL);
>   /*
>* NEEDSWORK: carrying over local changes
>* when branches have different end-of-line
> diff --git a/builtin/commit.c b/builtin/commit.c
> index 26b2986..121c185 100644
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -360,7 +360,7 @@ static char *prepare_index(int argc, const char **argv, 
> const char *prefix,
>*/
>   if (all || (a

[PATCH v2] commit: add --ignore-submodules[=] parameter

2014-03-30 Thread Ronald Weiss
Git commit honors the 'ignore' setting from .gitmodules or .git/config,
but didn't allow to override it from command line, like other commands do.

Useful  values for commit are 'all' (default) or 'none'. The others
('dirty' and 'untracked') have same effect as 'none', as commit is only
interested in whether the submodule's HEAD differs from what is commited
in the superproject.

Changes in add.c and cache.h (and related compilo fix in checkout.c) are
needed to make it work for "commit -a" too.

Signed-off-by: Ronald Weiss 
---
On 30. 3. 2014 21:48, Jens Lehmann wrote:
> Looking good so far, but we definitely need tests for this new option.

I added two simple tests (one for --ignore-submodules=all, another one
for =none). But I am sure the tests could be written better, by someone
more proficient in Git than I am.

The tests immediately revealed, that the patch was not complete. It
didn't work with commit message given on command line (-m). To make
that work, I had to also patch the index_differs_from function in
diff-lib.c.

> But I wonder if it would make more sense to start by teaching the
> --ignore-submodules option to git add. Then this patch could reuse
> that for commit -a.

That sounds reasonable, however I don't think that any code from my
patch would be affected, or would it? IOW, would commit really "reuse"
anything? If not (or not much), there is probably no point in
postponing this patch, support for git add may be added later.


 Documentation/git-commit.txt|  6 ++
 builtin/add.c   | 16 +++
 builtin/checkout.c  |  2 +-
 builtin/commit.c| 10 --
 cache.h |  2 +-
 diff-lib.c  |  7 ++-
 diff.h  |  3 ++-
 sequencer.c |  4 ++--
 t/t7513-commit-ignore-submodules.sh | 39 +
 9 files changed, 77 insertions(+), 12 deletions(-)
 create mode 100644 t/t7513-commit-ignore-submodules.sh

diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
index 1a7616c..c8839c8 100644
--- a/Documentation/git-commit.txt
+++ b/Documentation/git-commit.txt
@@ -13,6 +13,7 @@ SYNOPSIS
   [-F  | -m ] [--reset-author] [--allow-empty]
   [--allow-empty-message] [--no-verify] [-e] [--author=]
   [--date=] [--cleanup=] [--[no-]status]
+  [--ignore-submodules[=]]
   [-i | -o] [-S[]] [--] [...]
 
 DESCRIPTION
@@ -271,6 +272,11 @@ The possible options are:
 The default can be changed using the status.showUntrackedFiles
 configuration variable documented in linkgit:git-config[1].
 
+--ignore-submodules[=]::
+   Can be used to override any settings of the 'ignore' option
+   in linkgit:git-config[1] or linkgit:gitmodules[5].
+can be either "none" or "all", which is the default.
+
 -v::
 --verbose::
Show unified diff between the HEAD commit and what
diff --git a/builtin/add.c b/builtin/add.c
index 672adc0..1086294 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -168,7 +168,8 @@ static void update_callback(struct diff_queue_struct *q,
 
 static void update_files_in_cache(const char *prefix,
  const struct pathspec *pathspec,
- struct update_callback_data *data)
+ struct update_callback_data *data,
+ const char *ignore_submodules_arg)
 {
struct rev_info rev;
 
@@ -180,17 +181,24 @@ static void update_files_in_cache(const char *prefix,
rev.diffopt.format_callback = update_callback;
rev.diffopt.format_callback_data = data;
rev.max_count = 0; /* do not compare unmerged paths with stage #2 */
+
+   if (ignore_submodules_arg) {
+   DIFF_OPT_SET(&rev.diffopt, OVERRIDE_SUBMODULE_CONFIG);
+   handle_ignore_submodules_arg(&rev.diffopt, 
ignore_submodules_arg);
+   }
+
run_diff_files(&rev, DIFF_RACY_IS_MODIFIED);
 }
 
 int add_files_to_cache(const char *prefix,
-  const struct pathspec *pathspec, int flags)
+  const struct pathspec *pathspec, int flags,
+  const char *ignore_submodules_arg)
 {
struct update_callback_data data;
 
memset(&data, 0, sizeof(data));
data.flags = flags;
-   update_files_in_cache(prefix, pathspec, &data);
+   update_files_in_cache(prefix, pathspec, &data, ignore_submodules_arg);
return !!data.add_errors;
 }
 
@@ -576,7 +584,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
memset(&pathspec, 0, sizeof(pathspec));
}
update_data.flags = flags & ~ADD_CACHE_IMPLICIT_DOT;
-   update_files_in_cache(prefix, &pathspec, &update_data);
+   update_files_in_cache(prefix, &pathspec, &update_data, NULL);
 
exit_status |= !!update_data.add_errors;
if (add_new_fil

[PATCH v2.1] commit: add --ignore-submodules[=] parameter

2014-03-30 Thread Ronald Weiss
Git commit honors the 'ignore' setting from .gitmodules or .git/config,
but didn't allow to override it from command line, like other commands do.

Useful  values for commit are 'all' (default) or 'none'. The others
('dirty' and 'untracked') have same effect as 'none', as commit is only
interested in whether the submodule's HEAD differs from what is commited
in the superproject.

Changes in add.c and cache.h (and related compilo fix in checkout.c) are
needed to make it work for "commit -a" too.

Signed-off-by: Ronald Weiss 
---
The previous patch version (v2) contained bug in the test, by mistake I
have sent older version than I was testing with, sorry for that.

On 30. 3. 2014 21:48, Jens Lehmann wrote:
> Looking good so far, but we definitely need tests for this new option.

I added two simple tests (one for --ignore-submodules=all, another one
for =none). But I am sure the tests could be written better, by someone
more proficient in Git than I am.

The tests immediately revealed, that the patch was not complete. It
didn't work with commit message given on command line (-m). To make
that work, I had to also patch the index_differs_from function in
diff-lib.c.

> But I wonder if it would make more sense to start by teaching the
> --ignore-submodules option to git add. Then this patch could reuse
> that for commit -a.

That sounds reasonable, however I don't think that any code from my
patch would be affected, or would it? IOW, would commit really "reuse"
anything? If not (or not much), there is probably no point in
postponing this patch, support for git add may be added later.


 Documentation/git-commit.txt|  6 ++
 builtin/add.c   | 16 +++
 builtin/checkout.c  |  2 +-
 builtin/commit.c| 10 --
 cache.h |  2 +-
 diff-lib.c  |  7 ++-
 diff.h  |  3 ++-
 sequencer.c |  4 ++--
 t/t7513-commit-ignore-submodules.sh | 39 +
 9 files changed, 77 insertions(+), 12 deletions(-)
 create mode 100644 t/t7513-commit-ignore-submodules.sh

diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
index 1a7616c..c8839c8 100644
--- a/Documentation/git-commit.txt
+++ b/Documentation/git-commit.txt
@@ -13,6 +13,7 @@ SYNOPSIS
   [-F  | -m ] [--reset-author] [--allow-empty]
   [--allow-empty-message] [--no-verify] [-e] [--author=]
   [--date=] [--cleanup=] [--[no-]status]
+  [--ignore-submodules[=]]
   [-i | -o] [-S[]] [--] [...]
 
 DESCRIPTION
@@ -271,6 +272,11 @@ The possible options are:
 The default can be changed using the status.showUntrackedFiles
 configuration variable documented in linkgit:git-config[1].
 
+--ignore-submodules[=]::
+   Can be used to override any settings of the 'ignore' option
+   in linkgit:git-config[1] or linkgit:gitmodules[5].
+can be either "none" or "all", which is the default.
+
 -v::
 --verbose::
Show unified diff between the HEAD commit and what
diff --git a/builtin/add.c b/builtin/add.c
index 672adc0..1086294 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -168,7 +168,8 @@ static void update_callback(struct diff_queue_struct *q,
 
 static void update_files_in_cache(const char *prefix,
  const struct pathspec *pathspec,
- struct update_callback_data *data)
+ struct update_callback_data *data,
+ const char *ignore_submodules_arg)
 {
struct rev_info rev;
 
@@ -180,17 +181,24 @@ static void update_files_in_cache(const char *prefix,
rev.diffopt.format_callback = update_callback;
rev.diffopt.format_callback_data = data;
rev.max_count = 0; /* do not compare unmerged paths with stage #2 */
+
+   if (ignore_submodules_arg) {
+   DIFF_OPT_SET(&rev.diffopt, OVERRIDE_SUBMODULE_CONFIG);
+   handle_ignore_submodules_arg(&rev.diffopt, 
ignore_submodules_arg);
+   }
+
run_diff_files(&rev, DIFF_RACY_IS_MODIFIED);
 }
 
 int add_files_to_cache(const char *prefix,
-  const struct pathspec *pathspec, int flags)
+  const struct pathspec *pathspec, int flags,
+  const char *ignore_submodules_arg)
 {
struct update_callback_data data;
 
memset(&data, 0, sizeof(data));
data.flags = flags;
-   update_files_in_cache(prefix, pathspec, &data);
+   update_files_in_cache(prefix, pathspec, &data, ignore_submodules_arg);
return !!data.add_errors;
 }
 
@@ -576,7 +584,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
memset(&pathspec, 0, sizeof(pathspec));
}
update_data.flags = flags & ~ADD_CACHE_IMPLICIT_DOT;
-   update_files_in_cache(prefix, &pathspec, &update_data);
+ 

[PATCH] gitweb: Improve diffs when filenames contain problem characters

2014-03-30 Thread Andrew Keller
When formatting a diff header line, be sure to escape the raw output from git
for use as HTML.  This ensures that when "problem characters" (&, <, >, ?, etc.)
exist in filenames, gitweb displays them as text, rather than letting the
browser interpret them as HTML.

Reported-by: Dongsheng Song 
Signed-off-by: Andrew Keller 
---
Steps to reproduce:

1)  Create a repository that contains a commit that adds a file:
* with an ampersand in the filename
* with binary contents
2)  Make the repository visible to gitweb
3)  In gitweb, navigate to the page that shows the diff for the commit
that added the file

Behavior without patch: Page stops rendering when it gets to one of
the instances of the filename (in the diff header, to be specific), and
a light-red box appears a the top of the page, saying something like
this:

This page contains the following errors:

error on line 67 at column 22: xmlParseEntityRef: no name

Below is a rendering of the page up to the first error.


(This particular error is what you get with an unescaped ampersand)

Behavior with patch: You see the ampersand in the file name, and the
page renders as one would expect.


Other notes:

Several helper methods exist for escaping HTML, and I was unsure
about which one to use.  Although this patch fixes the problem,
it is possible that it may be more correct to use, for example, the
'esc_html' helper method instead of interacting with $cgi directly.

The first hunk in the diff seems to be all that's required to experience
the good behavior, however upon inspecting the code, it seems
prudent to also include the second one.  It's a nearby section of code,
doing similar work, and is called from the same function as the
former, and with similar arguments.


Thanks,
Andrew Keller


 gitweb/gitweb.perl |4 
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 79057b7..6c559f8 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -2223,6 +2223,8 @@ sub format_git_diff_header_line {
my $diffinfo = shift;
my ($from, $to) = @_;
 
+   $line = $cgi->escapeHTML($line);
+
if ($diffinfo->{'nparents'}) {
# combined diff
$line =~ s!^(diff (.*?) )"?.*$!$1!;
@@ -2259,6 +2261,8 @@ sub format_extended_diff_header_line {
my $diffinfo = shift;
my ($from, $to) = @_;
 
+   $line = $cgi->escapeHTML($line);
+
# match 
if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
$line .= $cgi->a({-href=>$from->{'href'}, -class=>"path"},
-- 
1.7.7.1

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html