Re: [RFC/PATCH 00/18] Add --index-only option to git merge

2016-04-09 Thread Elijah Newren
On Thu, Apr 7, 2016 at 11:58 PM, Elijah Newren  wrote:
>   Luckily, I figured out that bug.  So, that leaves just one case left
>   that I can't seem to figure out: read_tree_trivial.  So much better,
>   right?  Even it's name is sitting there, mocking me.  "Ha ha, I'm
>   read_tree_*trivial* and you can't figure me out."  read_tree_trivial
>   is a jerk.

It turns out this wasn't a bug in my index-only handling of the
trivial merge case; it was a pre-existing bug in git handling of
trivial merges that probably no one else had ever triggered before.
I'm submitting a fix with my other miscellaneous merge fixups...
--
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 00/24] Yet another pre-refs-backend series

2016-04-09 Thread Junio C Hamano
On Sat, Apr 9, 2016 at 9:19 AM, Michael Haggerty  wrote:
>
> I think this risk is acceptable nevertheless, because expiring reflogs
> is an uncommon operation and unlikely to be done from two processes at
> the same time; moreover, the integrity of reflogs is not a matter of
> life or death.
> ...
> If somebody is really upset about the risk of a race between an old and
> new version of `git reflog expire`, the way to increase the safety would
> be to lock *both* the symref and the referent while changing the
> symref's reflog. I think that would be overkill.

Thanks, I agree with all of the above.

> This whole series is
>
> Reviewed-by: Michael Haggerty 

Will squeeze it into all of them, then, and merge to 'next'.

Thanks.
--
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: Hardcoded #!/bin/sh in t5532 causes problems on Solaris

2016-04-09 Thread Junio C Hamano
Jeff King  writes:

> Hmm. t3404.40 does this:
>
> echo "#!/bin/sh" > $PRE_COMMIT &&
>   echo "test -z \"\$(git diff --cached --check)\"" >>$PRE_COMMIT &&
>   chmod a+x $PRE_COMMIT &&
>
> So I'm pretty sure that $PRE_COMMIT script should be barfing each time
> it is called on Solaris. I think the test itself doesn't notice because
> "/bin/sh barfed" and "the pre-commit check said no" look the same from
> git's perspective (both non-zero exits), and we test only cases where we
> expect the hook to fail.

I looked at

$ git grep -c '#! */bin/sh' t | grep -v ':1$'

and did a few just for fun.  Doing it fully may be a good
microproject for next year ;-)

 t/t1020-subdirectory.sh   |  6 +++---
 t/t2050-git-dir-relative.sh   | 11 ++-
 t/t3404-rebase-interactive.sh |  7 +++
 3 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/t/t1020-subdirectory.sh b/t/t1020-subdirectory.sh
index 8e22b03..6dedb1c 100755
--- a/t/t1020-subdirectory.sh
+++ b/t/t1020-subdirectory.sh
@@ -142,9 +142,9 @@ test_expect_success 'GIT_PREFIX for built-ins' '
# Use GIT_EXTERNAL_DIFF to test that the "diff" built-in
# receives the GIT_PREFIX variable.
printf "dir/" >expect &&
-   printf "#!/bin/sh\n" >diff &&
-   printf "printf \"\$GIT_PREFIX\"" >>diff &&
-   chmod +x diff &&
+   write_script diff <<-\EOF &&
+   printf "%s" "$GIT_PREFIX"
+   EOF
(
cd dir &&
printf "change" >two &&
diff --git a/t/t2050-git-dir-relative.sh b/t/t2050-git-dir-relative.sh
index 21f4659..7a05b20 100755
--- a/t/t2050-git-dir-relative.sh
+++ b/t/t2050-git-dir-relative.sh
@@ -18,11 +18,12 @@ COMMIT_FILE="$(pwd)/output"
 export COMMIT_FILE
 
 test_expect_success 'Setting up post-commit hook' '
-mkdir -p .git/hooks &&
-echo >.git/hooks/post-commit "#!/bin/sh
-touch \"\${COMMIT_FILE}\"
-echo Post commit hook was called." &&
-chmod +x .git/hooks/post-commit'
+   mkdir -p .git/hooks &&
+   write_script .git/hooks/post-commit <<-\EOF
+   >"${COMMIT_FILE}"
+   echo Post commit hook was called.
+   EOF
+'
 
 test_expect_success 'post-commit hook used ordinarily' '
 echo initial >top &&
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index b79f442..d96d0e4 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -555,10 +555,9 @@ test_expect_success 'rebase a detached HEAD' '
 test_expect_success 'rebase a commit violating pre-commit' '
 
mkdir -p .git/hooks &&
-   PRE_COMMIT=.git/hooks/pre-commit &&
-   echo "#!/bin/sh" > $PRE_COMMIT &&
-   echo "test -z \"\$(git diff --cached --check)\"" >> $PRE_COMMIT &&
-   chmod a+x $PRE_COMMIT &&
+   write_script .git/hooks/pre-commit <<-\EOF &&
+   test -z "$(git diff --cached --check)"
+   EOF
echo "monde! " >> file1 &&
test_tick &&
test_must_fail git commit -m doesnt-verify file1 &&
--
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: Hardcoded #!/bin/sh in t5532 causes problems on Solaris

2016-04-09 Thread Jeff King
On Sun, Apr 10, 2016 at 12:29:45AM +0200, Tom G. Christensen wrote:

> On 09/04/16 23:04, Jeff King wrote:
> >I did some quick grepping around, and I suspect you may run
> >into the same thing in other places (e.g., t3404.40 looks
> >like a similar case).
> 
> There are only a few tests that fail and just t5532.3 seems affected by this
> issue.

Hmm. t3404.40 does this:

echo "#!/bin/sh" > $PRE_COMMIT &&
echo "test -z \"\$(git diff --cached --check)\"" >>$PRE_COMMIT &&
chmod a+x $PRE_COMMIT &&

So I'm pretty sure that $PRE_COMMIT script should be barfing each time
it is called on Solaris. I think the test itself doesn't notice because
"/bin/sh barfed" and "the pre-commit check said no" look the same from
git's perspective (both non-zero exits), and we test only cases where we
expect the hook to fail.

I think that particular test could simplify its pre-commit hook to just
"exit 1".

I didn't dig into any other cases, so that might be the only one. If
you're not seeing problems, I'm not inclined to explore each one
manually.

> I applied this to 2.8.1 and as expected the test now passes on Solaris.

Thanks.

-Peff
--
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: Hardcoded #!/bin/sh in t5532 causes problems on Solaris

2016-04-09 Thread Tom G. Christensen

On 09/04/16 23:04, Jeff King wrote:

I did some quick grepping around, and I suspect you may run
into the same thing in other places (e.g., t3404.40 looks
like a similar case).


There are only a few tests that fail and just t5532.3 seems affected by 
this issue.



Subject: [PATCH] t5532: use write_script

The recent cleanup in b7cbbff switched t5532's use of
backticks to $(). This matches our normal shell style, which
is good. But it also breaks the test on Solaris, where
/bin/sh does not understand $().

Our normal shell style assumes a modern-ish shell which
knows about $(). However, some tests create small helper
scripts and just write "#!/bin/sh" into them. These scripts
either need to go back to using backticks, or they need to
respect $SHELL_PATH. The easiest way to do the latter is to
use write_script.

While we're at it, let's also stick the script creation
inside a test_expect block (our usual style), and split the
perl snippet into its own script (to prevent quoting
madness).

Signed-off-by: Jeff King 
---
  t/t5532-fetch-proxy.sh | 21 -
  1 file changed, 12 insertions(+), 9 deletions(-)



I applied this to 2.8.1 and as expected the test now passes on Solaris.

-tgc
--
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: Hardcoded #!/bin/sh in t5532 causes problems on Solaris

2016-04-09 Thread Jeff King
On Sat, Apr 09, 2016 at 10:27:37PM +0200, Tom G. Christensen wrote:

> Looking at the testsuite results on Solaris I see a failure in t5532.3.
> 
> Running the testsuite with -v -i revealed a shell syntax error:
> 
> proxying for example.com 9418
> ./proxy: syntax error at line 3: `cmd=$' unexpected
> not ok 3 - fetch through proxy works
> #
> #   git fetch fake &&
> #   echo one >expect &&
> #   git log -1 --format=%s FETCH_HEAD >actual &&
> #   test_cmp expect actual
> #
> 
> 
> Looking a t5532-fetch-proxy.sh the problem is obvious, it writes out a
> helper script which explicitly uses #!/bin/sh but fails to take into account
> that systems like Solaris has an ancient /bin/sh that knows nothing about
> POSIX things like $().
> Replacing $() with `` was enough to make the test pass.

Right, this is a recent regression from Elia's $() series. Rather than
just revert, I think the cleanup below is the best fix.

I did some quick grepping around, and I suspect you may run
into the same thing in other places (e.g., t3404.40 looks
like a similar case). We left a lot of "#!/bin/sh" cases
unconverted to write_script because we knew what they were
doing was trivial enough not to matter. But the $()
conversion made them non-trivial.

-- >8 --
Subject: [PATCH] t5532: use write_script

The recent cleanup in b7cbbff switched t5532's use of
backticks to $(). This matches our normal shell style, which
is good. But it also breaks the test on Solaris, where
/bin/sh does not understand $().

Our normal shell style assumes a modern-ish shell which
knows about $(). However, some tests create small helper
scripts and just write "#!/bin/sh" into them. These scripts
either need to go back to using backticks, or they need to
respect $SHELL_PATH. The easiest way to do the latter is to
use write_script.

While we're at it, let's also stick the script creation
inside a test_expect block (our usual style), and split the
perl snippet into its own script (to prevent quoting
madness).

Signed-off-by: Jeff King 
---
 t/t5532-fetch-proxy.sh | 21 -
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/t/t5532-fetch-proxy.sh b/t/t5532-fetch-proxy.sh
index d75ef0e..51c9669 100755
--- a/t/t5532-fetch-proxy.sh
+++ b/t/t5532-fetch-proxy.sh
@@ -12,10 +12,8 @@ test_expect_success 'setup remote repo' '
)
 '
 
-cat >proxy <<'EOF'
-#!/bin/sh
-echo >&2 "proxying for $*"
-cmd=$("$PERL_PATH" -e '
+test_expect_success 'setup proxy script' '
+   write_script proxy-get-cmd "$PERL_PATH" <<-\EOF &&
read(STDIN, $buf, 4);
my $n = hex($buf) - 4;
read(STDIN, $buf, $n);
@@ -23,11 +21,16 @@ cmd=$("$PERL_PATH" -e '
# drop absolute-path on repo name
$cmd =~ s{ /}{ };
print $cmd;
-')
-echo >&2 "Running '$cmd'"
-exec $cmd
-EOF
-chmod +x proxy
+   EOF
+
+   write_script proxy <<-\EOF
+   echo >&2 "proxying for $*"
+   cmd=$(./proxy-get-cmd)
+   echo >&2 "Running $cmd"
+   exec $cmd
+   EOF
+'
+
 test_expect_success 'setup local repo' '
git remote add fake git://example.com/remote &&
git config core.gitproxy ./proxy
-- 
2.8.1.245.g18e0f5c

--
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 v2 6/7] i18n: builtin/rm.c: remove a comma ',' from string

2016-04-09 Thread Vasco Almeida
Remove a comma from string marked for translation. Make the string match the
one in builtin/mv.c. Now translators have do handle this string only once.

Signed-off-by: Vasco Almeida 
---
 builtin/rm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/builtin/rm.c b/builtin/rm.c
index 8829b09..be83c43 100644
--- a/builtin/rm.c
+++ b/builtin/rm.c
@@ -314,7 +314,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
list.entry[list.nr].is_submodule = S_ISGITLINK(ce->ce_mode);
if (list.entry[list.nr++].is_submodule &&
!is_staging_gitmodules_ok())
-   die (_("Please, stage your changes to .gitmodules or 
stash them to proceed"));
+   die (_("Please stage your changes to .gitmodules or 
stash them to proceed"));
}
 
if (pathspec.nr) {
-- 
2.1.4

--
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 v2 5/7] i18n: builtin/pull.c: split strings marked for translation

2016-04-09 Thread Vasco Almeida
Split string "If you wish to set tracking information
for this branch you can do so with:\n" to match occurring string in
git-parse-remote.sh. In this case, the translator handles it only once.

On the other hand, the translations of the string that were already made
are mark as fuzzy and the translator needs to correct it herself.

Signed-off-by: Vasco Almeida 
---
 builtin/pull.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/builtin/pull.c b/builtin/pull.c
index 9e8883c..617893c 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -475,10 +475,10 @@ static void NORETURN die_no_merge_candidates(const char 
*repo, const char **refs
fprintf(stderr, "\n");
fprintf_ln(stderr, "git pull <%s> <%s>", _("remote"), 
_("branch"));
fprintf(stderr, "\n");
-   fprintf_ln(stderr, _("If you wish to set tracking information 
for this branch you can do so with:\n"
-   "\n"
-   "git branch --set-upstream-to=%s/ 
%s\n"),
-   remote_name, curr_branch->name);
+   fprintf_ln(stderr, _("If you wish to set tracking information 
for this branch you can do so with:"));
+   fprintf(stderr, "\n");
+   fprintf_ln(stderr, "git branch --set-upstream-to=%s/<%s> 
%s\n",
+   remote_name, _("branch"), curr_branch->name);
} else
fprintf_ln(stderr, _("Your configuration specifies to merge 
with the ref '%s'\n"
"from the remote, but no such ref was fetched."),
-- 
2.1.4

--
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 v2 7/7] i18n: builtin/branch.c: mark option for translation

2016-04-09 Thread Vasco Almeida
Mark description and parameter for option "set-upstream-to" for translation.

Signed-off-by: Vasco Almeida 
---
 builtin/branch.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/builtin/branch.c b/builtin/branch.c
index 7b45b6b..5ab106b 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -620,7 +620,7 @@ int cmd_branch(int argc, const char **argv, const char 
*prefix)
BRANCH_TRACK_EXPLICIT),
OPT_SET_INT( 0, "set-upstream",  , N_("change upstream 
info"),
BRANCH_TRACK_OVERRIDE),
-   OPT_STRING('u', "set-upstream-to", _upstream, "upstream", 
"change the upstream info"),
+   OPT_STRING('u', "set-upstream-to", _upstream, 
N_("upstream"), N_("change the upstream info")),
OPT_BOOL(0, "unset-upstream", _upstream, "Unset the 
upstream info"),
OPT__COLOR(_use_color, N_("use colored output")),
OPT_SET_INT('r', "remotes", , N_("act on 
remote-tracking branches"),
-- 
2.1.4

--
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 v2 4/7] i18n: builtin/pull.c: mark strings for translation

2016-04-09 Thread Vasco Almeida
Some translations might also translate "" and "".

Signed-off-by: Vasco Almeida 
---
 builtin/pull.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/builtin/pull.c b/builtin/pull.c
index 10eff03..9e8883c 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -458,13 +458,13 @@ static void NORETURN die_no_merge_candidates(const char 
*repo, const char **refs
fprintf_ln(stderr, _("Please specify which branch you 
want to merge with."));
fprintf_ln(stderr, _("See git-pull(1) for details."));
fprintf(stderr, "\n");
-   fprintf_ln(stderr, "git pull  ");
+   fprintf_ln(stderr, "git pull <%s> <%s>", _("remote"), 
_("branch"));
fprintf(stderr, "\n");
} else if (!curr_branch->merge_nr) {
const char *remote_name = NULL;
 
if (for_each_remote(get_only_remote, _name) || 
!remote_name)
-   remote_name = "";
+   remote_name = _("");
 
fprintf_ln(stderr, _("There is no tracking information for the 
current branch."));
if (opt_rebase)
@@ -473,7 +473,7 @@ static void NORETURN die_no_merge_candidates(const char 
*repo, const char **refs
fprintf_ln(stderr, _("Please specify which branch you 
want to merge with."));
fprintf_ln(stderr, _("See git-pull(1) for details."));
fprintf(stderr, "\n");
-   fprintf_ln(stderr, "git pull  ");
+   fprintf_ln(stderr, "git pull <%s> <%s>", _("remote"), 
_("branch"));
fprintf(stderr, "\n");
fprintf_ln(stderr, _("If you wish to set tracking information 
for this branch you can do so with:\n"
"\n"
-- 
2.1.4

--
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 v2 3/7] i18n: git-parse-remote.sh: mark strings for translation

2016-04-09 Thread Vasco Almeida
Change Makefile to include git-parse-remote.sh in LOCALIZED_SH.

TODO: remove 3rd argument of error_on_missing_default_upstream function
that is no longer required.

Signed-off-by: Vasco Almeida 
---
 Makefile|  2 +-
 git-parse-remote.sh | 50 +-
 2 files changed, 34 insertions(+), 18 deletions(-)

diff --git a/Makefile b/Makefile
index 2742a69..2249bab 100644
--- a/Makefile
+++ b/Makefile
@@ -2069,7 +2069,7 @@ XGETTEXT_FLAGS_SH = $(XGETTEXT_FLAGS) --language=Shell \
--keyword=gettextln --keyword=eval_gettextln
 XGETTEXT_FLAGS_PERL = $(XGETTEXT_FLAGS) --keyword=__ --language=Perl
 LOCALIZED_C = $(C_OBJ:o=c) $(LIB_H) $(GENERATED_H)
-LOCALIZED_SH = $(SCRIPT_SH)
+LOCALIZED_SH = $(SCRIPT_SH) git-parse-remote.sh
 LOCALIZED_PERL = $(SCRIPT_PERL)
 
 ifdef XGETTEXT_INCLUDE_TESTS
diff --git a/git-parse-remote.sh b/git-parse-remote.sh
index 55fe8d5..c5e5840 100644
--- a/git-parse-remote.sh
+++ b/git-parse-remote.sh
@@ -6,6 +6,9 @@
 # this would fail in that case and would issue an error message.
 GIT_DIR=$(git rev-parse -q --git-dir) || :;
 
+. git-sh-setup
+. git-sh-i18n
+
 get_default_remote () {
curr_branch=$(git symbolic-ref -q HEAD)
curr_branch="${curr_branch#refs/heads/}"
@@ -56,11 +59,13 @@ get_remote_merge_branch () {
 error_on_missing_default_upstream () {
cmd="$1"
op_type="$2"
-   op_prep="$3"
+   op_prep="$3" # FIXME: op_prep is no longer used
example="$4"
branch_name=$(git symbolic-ref -q HEAD)
+   display_branch_name="${branch_name#refs/heads/}"
# If there's only one remote, use that in the suggestion
-   remote=""
+   remote="$(gettext "")"
+   branch="$(gettext "branch")"
if test $(git remote | wc -l) = 1
then
remote=$(git remote)
@@ -68,22 +73,33 @@ error_on_missing_default_upstream () {
 
if test -z "$branch_name"
then
-   echo "You are not currently on a branch. Please specify which
-branch you want to $op_type $op_prep. See git-${cmd}(1) for details.
-
-$example
-"
+   gettextln "You are not currently on a branch."
+   if test "$op_type" = rebase
+   then
+   gettextln "Please specify which branch you want to 
rebase against."
+   else
+   gettextln "Please specify which branch you want to 
merge with."
+   fi
+   eval_gettextln "See git-\${cmd}(1) for details."
+   echo
+   echo "$example"
+   echo
else
-   echo "There is no tracking information for the current branch.
-Please specify which branch you want to $op_type $op_prep.
-See git-${cmd}(1) for details
-
-$example
-
-If you wish to set tracking information for this branch you can do so with:
-
-git branch --set-upstream-to=$remote/ ${branch_name#refs/heads/}
-"
+   gettextln "There is no tracking information for the current 
branch."
+   if test "$op_type" = rebase
+   then
+   gettextln "Please specify which branch you want to 
rebase against."
+   else
+   gettextln "Please specify which branch you want to 
merge with."
+   fi
+   eval_gettextln "See git-\${cmd}(1) for details."
+   echo
+   echo "$example"
+   echo
+   gettextln "If you wish to set tracking information for this 
branch you can do so with:"
+   echo
+   echo "git branch --set-upstream-to=$remote/<$branch> 
$display_branch_name"
+   echo
fi
exit 1
 }
-- 
2.1.4

--
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 v2 2/7] i18n: unpack-trees: mark strings for translation

2016-04-09 Thread Vasco Almeida
Mark strings seen by the user inside setup_unpack_trees_porcelain() and
display_error_msgs() functions for translation.

Signed-off-by: Vasco Almeida 
---
 unpack-trees.c | 24 
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/unpack-trees.c b/unpack-trees.c
index 9f55cc2..4bc6b4f 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -61,21 +61,21 @@ void setup_unpack_trees_porcelain(struct 
unpack_trees_options *opts,
const char *cmd2 = strcmp(cmd, "checkout") ? cmd : "switch branches";
 
if (advice_commit_before_merge)
-   msg = "Your local changes to the following files would be 
overwritten by %s:\n%%s"
-   "Please, commit your changes or stash them before you 
can %s.";
+   msg = _("Your local changes to the following files would be 
overwritten by %s:\n%%s"
+   "Please, commit your changes or stash them before you 
can %s.");
else
-   msg = "Your local changes to the following files would be 
overwritten by %s:\n%%s";
+   msg = _("Your local changes to the following files would be 
overwritten by %s:\n%%s");
msgs[ERROR_WOULD_OVERWRITE] = msgs[ERROR_NOT_UPTODATE_FILE] =
xstrfmt(msg, cmd, cmd2);
 
msgs[ERROR_NOT_UPTODATE_DIR] =
-   "Updating the following directories would lose untracked files 
in it:\n%s";
+   _("Updating the following directories would lose untracked 
files in it:\n%s");
 
if (advice_commit_before_merge)
-   msg = "The following untracked working tree files would be %s 
by %s:\n%%s"
-   "Please move or remove them before you can %s.";
+   msg = _("The following untracked working tree files would be %s 
by %s:\n%%s"
+   "Please move or remove them before you can %s.");
else
-   msg = "The following untracked working tree files would be %s 
by %s:\n%%s";
+   msg = _("The following untracked working tree files would be %s 
by %s:\n%%s");
 
msgs[ERROR_WOULD_LOSE_UNTRACKED_REMOVED] = xstrfmt(msg, "removed", cmd, 
cmd2);
msgs[ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN] = xstrfmt(msg, 
"overwritten", cmd, cmd2);
@@ -84,14 +84,14 @@ void setup_unpack_trees_porcelain(struct 
unpack_trees_options *opts,
 * Special case: ERROR_BIND_OVERLAP refers to a pair of paths, we
 * cannot easily display it as a list.
 */
-   msgs[ERROR_BIND_OVERLAP] = "Entry '%s' overlaps with '%s'.  Cannot 
bind.";
+   msgs[ERROR_BIND_OVERLAP] = _("Entry '%s' overlaps with '%s'.  Cannot 
bind.");
 
msgs[ERROR_SPARSE_NOT_UPTODATE_FILE] =
-   "Cannot update sparse checkout: the following entries are not 
up-to-date:\n%s";
+   _("Cannot update sparse checkout: the following entries are not 
up-to-date:\n%s");
msgs[ERROR_WOULD_LOSE_ORPHANED_OVERWRITTEN] =
-   "The following Working tree files would be overwritten by 
sparse checkout update:\n%s";
+   _("The following Working tree files would be overwritten by 
sparse checkout update:\n%s");
msgs[ERROR_WOULD_LOSE_ORPHANED_REMOVED] =
-   "The following Working tree files would be removed by sparse 
checkout update:\n%s";
+   _("The following Working tree files would be removed by sparse 
checkout update:\n%s");
 
opts->show_all_errors = 1;
/* rejected paths may not have a static buffer */
@@ -168,7 +168,7 @@ static void display_error_msgs(struct unpack_trees_options 
*o)
string_list_clear(rejects, 0);
}
if (something_displayed)
-   fprintf(stderr, "Aborting\n");
+   fprintf(stderr, _("Aborting\n"));
 }
 
 /*
-- 
2.1.4

--
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 v2 1/7] i18n: index-pack: use plural string instead of normal one

2016-04-09 Thread Vasco Almeida
Git could output "completed with 1 local objects", but in this case
using "object" instead of "objects" is the correct form.
Use Q_() instead of _().

Signed-off-by: Vasco Almeida 
---
 builtin/index-pack.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 2d1eb8b..e8c71fc 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -1250,7 +1250,9 @@ static void conclude_pack(int fix_thin_pack, const char 
*curr_pack, unsigned cha
   nr_unresolved * sizeof(*objects));
f = sha1fd(output_fd, curr_pack);
fix_unresolved_deltas(f);
-   strbuf_addf(, _("completed with %d local objects"),
+   strbuf_addf(, Q_("completed with %d local object",
+"completed with %d local objects",
+nr_objects - nr_objects_initial),
nr_objects - nr_objects_initial);
stop_progress_msg(, msg.buf);
strbuf_release();
-- 
2.1.4

--
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: git segfaults on older Solaris releases

2016-04-09 Thread Jeff King
On Sat, Apr 09, 2016 at 10:17:56PM +0200, Tom G. Christensen wrote:

> On 09/04/16 19:39, Jeff King wrote:
> 
> >   [1/3]: config: lower-case first word of error strings
> >   [2/3]: git_config_set_multivar_in_file: all non-zero returns are errors
> >   [3/3]: git_config_set_multivar_in_file: handle "unset" errors
> >
> 
> I applied them to 2.8.1 and ran the testsuite again on Solaris 8/x86 and the
> segfault is gone.

Thanks for testing. By the way, I ran the whole test suite with "--tee -v"
and grepped for "(null)", which does find this case on glibc systems. I
didn't see any other interesting cases (there _are_ mentions of
"(null)", but they are from our code, not glibc converting NULLs). Which
I guess is just corroborating your testing, since you would have seen
any bad cases as segfaults.

-Peff
--
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


Hardcoded #!/bin/sh in t5532 causes problems on Solaris

2016-04-09 Thread Tom G. Christensen

Hello,

Looking at the testsuite results on Solaris I see a failure in t5532.3.

Running the testsuite with -v -i revealed a shell syntax error:

proxying for example.com 9418
./proxy: syntax error at line 3: `cmd=$' unexpected
not ok 3 - fetch through proxy works
#
#   git fetch fake &&
#   echo one >expect &&
#   git log -1 --format=%s FETCH_HEAD >actual &&
#   test_cmp expect actual
#


Looking a t5532-fetch-proxy.sh the problem is obvious, it writes out a 
helper script which explicitly uses #!/bin/sh but fails to take into 
account that systems like Solaris has an ancient /bin/sh that knows 
nothing about POSIX things like $().

Replacing $() with `` was enough to make the test pass.

-tgc
--
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: git segfaults on older Solaris releases

2016-04-09 Thread Tom G. Christensen

On 09/04/16 19:39, Jeff King wrote:


   [1/3]: config: lower-case first word of error strings
   [2/3]: git_config_set_multivar_in_file: all non-zero returns are errors
   [3/3]: git_config_set_multivar_in_file: handle "unset" errors



I applied them to 2.8.1 and ran the testsuite again on Solaris 8/x86 and 
the segfault is gone.


-tgc

--
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] Documentation: clarify signature verification

2016-04-09 Thread The Fox in the Shell
Hi,

I encountered some issues with the git documentation while modifying
my deployment scripts to enforce that the tree being fetched was
signed by a trusted key.

It was unclear which commits needed to be signed (in the case of `git
merge`) and what were the criteria for the signature to be considered
valid.

Here is a patch proposal.

Signed-off-by: The Fox in the Shell 
---
 Documentation/merge-options.txt  | 4 +++-
 Documentation/pretty-formats.txt | 4 ++--
 Documentation/pretty-options.txt | 4 ++--
 3 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/Documentation/merge-options.txt b/Documentation/merge-options.txt
index f08e9b8..edd50bf 100644
--- a/Documentation/merge-options.txt
+++ b/Documentation/merge-options.txt
@@ -89,8 +89,10 @@ option can be used to override --squash.
 
 --verify-signatures::
 --no-verify-signatures::
-   Verify that the commits being merged have good and trusted GPG 
signatures
+   Verify that the commits being merged have good and valid GPG signatures
and abort the merge in case they do not.
+   For instance, when running `git merge --verify-signature remote/branch`,
+   only the head commit on `remote/branch` needs to be signed.
 
 --summary::
 --no-summary::
diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt
index 671cebd..29b19b9 100644
--- a/Documentation/pretty-formats.txt
+++ b/Documentation/pretty-formats.txt
@@ -143,8 +143,8 @@ ifndef::git-rev-list[]
 - '%N': commit notes
 endif::git-rev-list[]
 - '%GG': raw verification message from GPG for a signed commit
-- '%G?': show "G" for a Good signature, "B" for a Bad signature, "U" for a 
good,
-  untrusted signature and "N" for no signature
+- '%G?': show "G" for a good (valid) signature, "B" for a bad signature,
+  "U" for a good signature with unknown validity and "N" for no signature
 - '%GS': show the name of the signer for a signed commit
 - '%GK': show the key used to sign a signed commit
 - '%gD': reflog selector, e.g., `refs/stash@{1}`
diff --git a/Documentation/pretty-options.txt b/Documentation/pretty-options.txt
index 54b88b6..62cbae2 100644
--- a/Documentation/pretty-options.txt
+++ b/Documentation/pretty-options.txt
@@ -78,5 +78,5 @@ being displayed. Examples: "--notes=foo" will show only notes 
from
 endif::git-rev-list[]
 
 --show-signature::
-   Check the validity of a signed commit object by passing the signature
-   to `gpg --verify` and show the output.
+   Check the validity of a signed commit object, by passing the signature
+   to `gpg --verify`, and show the output.
-- 
2.1.4

--
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 06/16] ref-filter: introduce format_ref_array_item()

2016-04-09 Thread Karthik Nayak
To allow column display, we will need to first render the output in a
string list to allow print_columns() to compute the proper size of
each column before starting the actual output. Introduce the function
format_ref_array_item() that does the formatting of a ref_array_item
to an strbuf.

show_ref_array_item() is kept as a convenience wrapper around it which
obtains the strbuf and prints it the standard output.

Mentored-by: Christian Couder 
Mentored-by: Matthieu Moy 
Signed-off-by: Karthik Nayak 
---
 ref-filter.c | 16 
 ref-filter.h |  3 +++
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/ref-filter.c b/ref-filter.c
index 7004bf0..3bb474f 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1813,10 +1813,10 @@ static void append_literal(const char *cp, const char 
*ep, struct ref_formatting
}
 }
 
-void show_ref_array_item(struct ref_array_item *info, const char *format, int 
quote_style)
+void format_ref_array_item(struct ref_array_item *info, const char *format,
+  int quote_style, struct strbuf *final_buf)
 {
const char *cp, *sp, *ep;
-   struct strbuf *final_buf;
struct ref_formatting_state state = REF_FORMATTING_STATE_INIT;
 
state.quote_style = quote_style;
@@ -1846,9 +1846,17 @@ void show_ref_array_item(struct ref_array_item *info, 
const char *format, int qu
}
if (state.stack->prev)
die(_("format: %%(end) atom missing"));
-   final_buf = >output;
-   fwrite(final_buf->buf, 1, final_buf->len, stdout);
+   strbuf_addbuf(final_buf, >output);
pop_stack_element();
+}
+
+void show_ref_array_item(struct ref_array_item *info, const char *format, int 
quote_style)
+{
+   struct strbuf final_buf = STRBUF_INIT;
+
+   format_ref_array_item(info, format, quote_style, _buf);
+   fwrite(final_buf.buf, 1, final_buf.len, stdout);
+   strbuf_release(_buf);
putchar('\n');
 }
 
diff --git a/ref-filter.h b/ref-filter.h
index 4aea594..0014b92 100644
--- a/ref-filter.h
+++ b/ref-filter.h
@@ -98,6 +98,9 @@ int parse_ref_filter_atom(const char *atom, const char *ep);
 int verify_ref_format(const char *format);
 /*  Sort the given ref_array as per the ref_sorting provided */
 void ref_array_sort(struct ref_sorting *sort, struct ref_array *array);
+/*  Based on the given format and quote_style, fill the strbuf */
+void format_ref_array_item(struct ref_array_item *info, const char *format,
+  int quote_style, struct strbuf *final_buf);
 /*  Print the ref using the given format and quote_style */
 void show_ref_array_item(struct ref_array_item *info, const char *format, int 
quote_style);
 /*  Callback function for parsing the sort option */
-- 
2.8.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 14/16] branch, tag: use porcelain output

2016-04-09 Thread Karthik Nayak
Call ref-filter's setup_ref_filter_porcelain_msg() to enable
translated messages for the %(upstream:tack) atom. Although branch.c
doesn't currently use ref-filter's printing API's, this will ensure
that when it does in the future patches, we do not need to worry about
translation.

Written-by: Matthieu Moy 
Mentored-by: Christian Couder 
Mentored-by: Matthieu Moy 
Signed-off-by: Karthik Nayak 
---
 builtin/branch.c | 2 ++
 builtin/tag.c| 2 ++
 2 files changed, 4 insertions(+)

diff --git a/builtin/branch.c b/builtin/branch.c
index 460f32f..8747d82 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -622,6 +622,8 @@ int cmd_branch(int argc, const char **argv, const char 
*prefix)
OPT_END(),
};
 
+   setup_ref_filter_porcelain_msg();
+
memset(, 0, sizeof(filter));
filter.kind = FILTER_REFS_BRANCHES;
filter.abbrev = -1;
diff --git a/builtin/tag.c b/builtin/tag.c
index 528a1ba..3b51be1 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -379,6 +379,8 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
OPT_END()
};
 
+   setup_ref_filter_porcelain_msg();
+
git_config(git_tag_config, sorting_tail);
 
memset(, 0, sizeof(opt));
-- 
2.8.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 16/16] branch: implement '--format' option

2016-04-09 Thread Karthik Nayak
Implement the '--format' option provided by 'ref-filter'. This lets the
user list branches as per desired format similar to the implementation
in 'git for-each-ref'.

Add tests and documentation for the same.

Mentored-by: Christian Couder 
Mentored-by: Matthieu Moy 
Signed-off-by: Karthik Nayak 
---
 Documentation/git-branch.txt |  7 ++-
 builtin/branch.c | 14 +-
 t/t3203-branch-output.sh | 12 
 3 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt
index 4a7037f..8af132f 100644
--- a/Documentation/git-branch.txt
+++ b/Documentation/git-branch.txt
@@ -12,7 +12,7 @@ SYNOPSIS
[--list] [-v [--abbrev= | --no-abbrev]]
[--column[=] | --no-column]
[(--merged | --no-merged | --contains) []] [--sort=]
-   [--points-at ] [...]
+   [--points-at ] [--format=] [...]
 'git branch' [--set-upstream | --track | --no-track] [-l] [-f]  
[]
 'git branch' (--set-upstream-to= | -u ) []
 'git branch' --unset-upstream []
@@ -246,6 +246,11 @@ start-point is either a local or remote-tracking branch.
 --points-at ::
Only list branches of the given object.
 
+--format ::
+   A string that interpolates `%(fieldname)` from the object
+   pointed at by a ref being shown.  The format is the same as
+   that of linkgit:git-for-each-ref[1].
+
 Examples
 
 
diff --git a/builtin/branch.c b/builtin/branch.c
index e59cde3..665ee57 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -27,6 +27,7 @@ static const char * const builtin_branch_usage[] = {
N_("git branch [] [-r] (-d | -D) ..."),
N_("git branch [] (-m | -M) [] "),
N_("git branch [] [-r | -a] [--points-at]"),
+   N_("git branch [] [-r | -a] [--format]"),
NULL
 };
 
@@ -332,14 +333,14 @@ static char *build_format(struct ref_filter *filter, int 
maxwidth, const char *r
return strbuf_detach(, NULL);
 }
 
-static void print_ref_list(struct ref_filter *filter, struct ref_sorting 
*sorting)
+static void print_ref_list(struct ref_filter *filter, struct ref_sorting 
*sorting, const char *format)
 {
int i;
struct ref_array array;
int maxwidth = 0;
const char *remote_prefix = "";
struct strbuf out = STRBUF_INIT;
-   char *format;
+   char *to_free = NULL;
 
/*
 * If we are listing more than just remote branches,
@@ -356,7 +357,8 @@ static void print_ref_list(struct ref_filter *filter, 
struct ref_sorting *sortin
if (filter->verbose)
maxwidth = calc_maxwidth(, strlen(remote_prefix));
 
-   format = build_format(filter, maxwidth, remote_prefix);
+   if (!format)
+   format = to_free = build_format(filter, maxwidth, 
remote_prefix);
verify_ref_format(format);
 
/*
@@ -384,7 +386,7 @@ static void print_ref_list(struct ref_filter *filter, 
struct ref_sorting *sortin
}
 
ref_array_clear();
-   free(format);
+   free(to_free);
 }
 
 static void rename_branch(const char *oldname, const char *newname, int force)
@@ -484,6 +486,7 @@ int cmd_branch(int argc, const char **argv, const char 
*prefix)
enum branch_track track;
struct ref_filter filter;
static struct ref_sorting *sorting = NULL, **sorting_tail = 
+   const char *format = NULL;
 
struct option options[] = {
OPT_GROUP(N_("Generic options")),
@@ -524,6 +527,7 @@ int cmd_branch(int argc, const char **argv, const char 
*prefix)
OPTION_CALLBACK, 0, "points-at", _at, 
N_("object"),
N_("print only branches of the object"), 0, 
parse_opt_object_name
},
+   OPT_STRING(  0 , "format", , N_("format"), N_("format to 
use for the output")),
OPT_END(),
};
 
@@ -584,7 +588,7 @@ int cmd_branch(int argc, const char **argv, const char 
*prefix)
if ((filter.kind & FILTER_REFS_BRANCHES) && filter.detached)
filter.kind |= FILTER_REFS_DETACHED_HEAD;
filter.name_patterns = argv;
-   print_ref_list(, sorting);
+   print_ref_list(, sorting, format);
print_columns(, colopts, NULL);
string_list_clear(, 0);
return 0;
diff --git a/t/t3203-branch-output.sh b/t/t3203-branch-output.sh
index 4261403..c33a3f3 100755
--- a/t/t3203-branch-output.sh
+++ b/t/t3203-branch-output.sh
@@ -184,4 +184,16 @@ test_expect_success 'ambiguous branch/tag not marked' '
test_cmp expect actual
 '
 
+test_expect_success 'git branch --format option' '
+   cat >expect <<-\EOF &&
+   Refname is (HEAD detached from fromtag)
+   Refname is refs/heads/ambiguous
+   Refname is refs/heads/branch-one
+   Refname is refs/heads/branch-two
+   Refname is 

[PATCH v4 08/16] ref-filter: add support for %(upstream:track,nobracket)

2016-04-09 Thread Karthik Nayak
Add support for %(upstream:track,nobracket) which will print the
tracking information without the brackets (i.e. "ahead N, behind M").
This is needed when we port branch.c to use ref-filter's printing APIs.

Add test and documentation for the same.

Mentored-by: Christian Couder 
Mentored-by: Matthieu Moy 
Signed-off-by: Karthik Nayak 
---
 Documentation/git-for-each-ref.txt |  8 +++--
 ref-filter.c   | 67 +-
 t/t6300-for-each-ref.sh|  2 ++
 3 files changed, 51 insertions(+), 26 deletions(-)

diff --git a/Documentation/git-for-each-ref.txt 
b/Documentation/git-for-each-ref.txt
index 85ac2a8..be763c4 100644
--- a/Documentation/git-for-each-ref.txt
+++ b/Documentation/git-for-each-ref.txt
@@ -118,9 +118,11 @@ upstream::
`refname` above.  Additionally respects `:track` to show
"[ahead N, behind M]" and `:trackshort` to show the terse
version: ">" (ahead), "<" (behind), "<>" (ahead and behind),
-   or "=" (in sync).  Has no effect if the ref does not have
-   tracking information associated with it. `:track` also prints
-   "[gone]" whenever unknown upstream ref is encountered.
+   or "=" (in sync). `:track` also prints "[gone]" whenever
+   unknown upstream ref is encountered. Append `:track,nobracket`
+   to show tracking information without brackets (i.e "ahead N,
+   behind M").  Has no effect if the ref does not have tracking
+   information associated with it.
 
 push::
The name of a local ref which represents the `@{push}` location
diff --git a/ref-filter.c b/ref-filter.c
index 4d7e0c0..8c97cdb 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -46,8 +46,10 @@ static struct used_atom {
union {
char color[COLOR_MAXLEN];
struct align align;
-   enum { RR_NORMAL, RR_SHORTEN, RR_TRACK, RR_TRACKSHORT }
-   remote_ref;
+   struct {
+   enum { RR_NORMAL, RR_SHORTEN, RR_TRACK, RR_TRACKSHORT } 
option;
+   unsigned int nobracket: 1;
+   } remote_ref;
struct {
enum { C_BARE, C_BODY, C_BODY_DEP, C_LINES, C_SIG, 
C_SUB } option;
unsigned int nlines;
@@ -75,16 +77,33 @@ static void color_atom_parser(struct used_atom *atom, const 
char *color_value)
 
 static void remote_ref_atom_parser(struct used_atom *atom, const char *arg)
 {
-   if (!arg)
-   atom->u.remote_ref = RR_NORMAL;
-   else if (!strcmp(arg, "short"))
-   atom->u.remote_ref = RR_SHORTEN;
-   else if (!strcmp(arg, "track"))
-   atom->u.remote_ref = RR_TRACK;
-   else if (!strcmp(arg, "trackshort"))
-   atom->u.remote_ref = RR_TRACKSHORT;
-   else
-   die(_("unrecognized format: %%(%s)"), atom->name);
+   struct string_list params = STRING_LIST_INIT_DUP;
+   int i;
+
+   if (!arg) {
+   atom->u.remote_ref.option = RR_NORMAL;
+   return;
+   }
+
+   atom->u.remote_ref.nobracket = 0;
+   string_list_split(, arg, ',', -1);
+
+   for (i = 0; i < params.nr; i++) {
+   const char *s = params.items[i].string;
+
+   if (!strcmp(s, "short"))
+   atom->u.remote_ref.option = RR_SHORTEN;
+   else if (!strcmp(s, "track"))
+   atom->u.remote_ref.option = RR_TRACK;
+   else if (!strcmp(s, "trackshort"))
+   atom->u.remote_ref.option = RR_TRACKSHORT;
+   else if (!strcmp(s, "nobracket"))
+   atom->u.remote_ref.nobracket = 1;
+   else
+   die(_("unrecognized format: %%(%s)"), atom->name);
+   }
+
+   string_list_clear(, 0);
 }
 
 static void body_atom_parser(struct used_atom *atom, const char *arg)
@@ -1045,25 +1064,27 @@ static void fill_remote_ref_details(struct used_atom 
*atom, const char *refname,
struct branch *branch, const char **s)
 {
int num_ours, num_theirs;
-   if (atom->u.remote_ref == RR_SHORTEN)
+   if (atom->u.remote_ref.option == RR_SHORTEN)
*s = shorten_unambiguous_ref(refname, warn_ambiguous_refs);
-   else if (atom->u.remote_ref == RR_TRACK) {
+   else if (atom->u.remote_ref.option == RR_TRACK) {
if (stat_tracking_info(branch, _ours,
   _theirs, NULL)) {
-   *s = "[gone]";
-   return;
-   }
-
-   if (!num_ours && !num_theirs)
+   *s = xstrdup("gone");
+   } else if (!num_ours && !num_theirs)
*s = "";
else if (!num_ours)
-   *s = xstrfmt("[behind %d]", num_theirs);
+ 

[PATCH v4 13/16] ref-filter: allow porcelain to translate messages in the output

2016-04-09 Thread Karthik Nayak
Introduce setup_ref_filter_porcelain_msg() so that the messages used in
the atom %(upstream:track) can be translated if needed. This is needed
as we port branch.c to use ref-filter's printing API's.

Written-by: Matthieu Moy 
Mentored-by: Christian Couder 
Mentored-by: Matthieu Moy 
Signed-off-by: Karthik Nayak 
---
 ref-filter.c | 28 
 ref-filter.h |  2 ++
 2 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/ref-filter.c b/ref-filter.c
index 73e0a7f..3435df1 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -15,6 +15,26 @@
 #include "version.h"
 #include "wt-status.h"
 
+static struct ref_msg {
+   const char *gone;
+   const char *ahead;
+   const char *behind;
+   const char *ahead_behind;
+} msgs = {
+   "gone",
+   "ahead %d",
+   "behind %d",
+   "ahead %d, behind %d"
+};
+
+void setup_ref_filter_porcelain_msg(void)
+{
+   msgs.gone = _("gone");
+   msgs.ahead = _("ahead %d");
+   msgs.behind = _("behind %d");
+   msgs.ahead_behind = _("ahead %d, behind %d");
+}
+
 typedef enum { FIELD_STR, FIELD_ULONG, FIELD_TIME } cmp_type;
 
 struct align {
@@ -1097,15 +1117,15 @@ static void fill_remote_ref_details(struct used_atom 
*atom, const char *refname,
else if (atom->u.remote_ref.option == RR_TRACK) {
if (stat_tracking_info(branch, _ours,
   _theirs, NULL)) {
-   *s = xstrdup("gone");
+   *s = xstrdup(msgs.gone);
} else if (!num_ours && !num_theirs)
*s = "";
else if (!num_ours)
-   *s = xstrfmt("behind %d", num_theirs);
+   *s = xstrfmt(msgs.behind, num_theirs);
else if (!num_theirs)
-   *s = xstrfmt("ahead %d", num_ours);
+   *s = xstrfmt(msgs.ahead, num_ours);
else
-   *s = xstrfmt("ahead %d, behind %d",
+   *s = xstrfmt(msgs.ahead_behind,
 num_ours, num_theirs);
if (!atom->u.remote_ref.nobracket && *s[0]) {
const char *to_free = *s;
diff --git a/ref-filter.h b/ref-filter.h
index 0014b92..da17145 100644
--- a/ref-filter.h
+++ b/ref-filter.h
@@ -111,5 +111,7 @@ struct ref_sorting *ref_default_sorting(void);
 int parse_opt_merge_filter(const struct option *opt, const char *arg, int 
unset);
 /*  Get the current HEAD's description */
 char *get_head_description(void);
+/*  Set up translated strings in the output. */
+void setup_ref_filter_porcelain_msg(void);
 
 #endif /*  REF_FILTER_H  */
-- 
2.8.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 15/16] branch: use ref-filter printing APIs

2016-04-09 Thread Karthik Nayak
Port branch.c to use ref-filter APIs for printing. This clears out
most of the code used in branch.c for printing and replaces them with
calls made to the ref-filter library.

Introduce build_format() which gets the format required for printing
of refs. Make amendments to print_ref_list() to reflect these changes.

Change calc_maxwidth() to also account for the length of HEAD ref, by
calling ref-filter:get_head_discription().

Also change the test in t6040 to reflect the changes.

Mentored-by: Christian Couder 
Mentored-by: Matthieu Moy 
Signed-off-by: Karthik Nayak 
---
 builtin/branch.c | 227 ++-
 t/t6040-tracking-info.sh |   2 +-
 2 files changed, 67 insertions(+), 162 deletions(-)

diff --git a/builtin/branch.c b/builtin/branch.c
index 8747d82..e59cde3 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -35,12 +35,12 @@ static unsigned char head_sha1[20];
 
 static int branch_use_color = -1;
 static char branch_colors[][COLOR_MAXLEN] = {
-   GIT_COLOR_RESET,
-   GIT_COLOR_NORMAL,   /* PLAIN */
-   GIT_COLOR_RED,  /* REMOTE */
-   GIT_COLOR_NORMAL,   /* LOCAL */
-   GIT_COLOR_GREEN,/* CURRENT */
-   GIT_COLOR_BLUE, /* UPSTREAM */
+   "%(color:reset)",
+   "%(color:reset)",   /* PLAIN */
+   "%(color:red)", /* REMOTE */
+   "%(color:reset)",   /* LOCAL */
+   "%(color:green)",   /* CURRENT */
+   "%(color:blue)",/* UPSTREAM */
 };
 enum color_branch {
BRANCH_COLOR_RESET = 0,
@@ -271,157 +271,6 @@ static int delete_branches(int argc, const char **argv, 
int force, int kinds,
return(ret);
 }
 
-static void fill_tracking_info(struct strbuf *stat, const char *branch_name,
-   int show_upstream_ref)
-{
-   int ours, theirs;
-   char *ref = NULL;
-   struct branch *branch = branch_get(branch_name);
-   const char *upstream;
-   struct strbuf fancy = STRBUF_INIT;
-   int upstream_is_gone = 0;
-   int added_decoration = 1;
-
-   if (stat_tracking_info(branch, , , ) < 0) {
-   if (!upstream)
-   return;
-   upstream_is_gone = 1;
-   }
-
-   if (show_upstream_ref) {
-   ref = shorten_unambiguous_ref(upstream, 0);
-   if (want_color(branch_use_color))
-   strbuf_addf(, "%s%s%s",
-   branch_get_color(BRANCH_COLOR_UPSTREAM),
-   ref, 
branch_get_color(BRANCH_COLOR_RESET));
-   else
-   strbuf_addstr(, ref);
-   }
-
-   if (upstream_is_gone) {
-   if (show_upstream_ref)
-   strbuf_addf(stat, _("[%s: gone]"), fancy.buf);
-   else
-   added_decoration = 0;
-   } else if (!ours && !theirs) {
-   if (show_upstream_ref)
-   strbuf_addf(stat, _("[%s]"), fancy.buf);
-   else
-   added_decoration = 0;
-   } else if (!ours) {
-   if (show_upstream_ref)
-   strbuf_addf(stat, _("[%s: behind %d]"), fancy.buf, 
theirs);
-   else
-   strbuf_addf(stat, _("[behind %d]"), theirs);
-
-   } else if (!theirs) {
-   if (show_upstream_ref)
-   strbuf_addf(stat, _("[%s: ahead %d]"), fancy.buf, ours);
-   else
-   strbuf_addf(stat, _("[ahead %d]"), ours);
-   } else {
-   if (show_upstream_ref)
-   strbuf_addf(stat, _("[%s: ahead %d, behind %d]"),
-   fancy.buf, ours, theirs);
-   else
-   strbuf_addf(stat, _("[ahead %d, behind %d]"),
-   ours, theirs);
-   }
-   strbuf_release();
-   if (added_decoration)
-   strbuf_addch(stat, ' ');
-   free(ref);
-}
-
-static void add_verbose_info(struct strbuf *out, struct ref_array_item *item,
-struct ref_filter *filter, const char *refname)
-{
-   struct strbuf subject = STRBUF_INIT, stat = STRBUF_INIT;
-   const char *sub = _("  invalid ref ");
-   struct commit *commit = item->commit;
-
-   if (!parse_commit(commit)) {
-   pp_commit_easy(CMIT_FMT_ONELINE, commit, );
-   sub = subject.buf;
-   }
-
-   if (item->kind == FILTER_REFS_BRANCHES)
-   fill_tracking_info(, refname, filter->verbose > 1);
-
-   strbuf_addf(out, " %s %s%s",
-   find_unique_abbrev(item->commit->object.oid.hash, 
filter->abbrev),
-   stat.buf, sub);
-   strbuf_release();
-   strbuf_release();
-}
-
-static void format_and_print_ref_item(struct ref_array_item *item, int 

[PATCH v4 10/16] ref-filter: introduce symref_atom_parser()

2016-04-09 Thread Karthik Nayak
Introduce symref_atom_parser() which will parse the '%(symref)' atom and
store information into the 'used_atom' structure based on the modifiers
used along with the atom.

Signed-off-by: Karthik Nayak 
---
 ref-filter.c | 25 +++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/ref-filter.c b/ref-filter.c
index 5c59b17..7b35e4f 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -62,6 +62,7 @@ static struct used_atom {
enum { O_FULL, O_LENGTH, O_SHORT } option;
unsigned int length;
} objectname;
+   enum { S_FULL, S_SHORT } symref;
} u;
 } *used_atom;
 static int used_atom_cnt, need_tagged, need_symref;
@@ -217,6 +218,15 @@ static void if_atom_parser(struct used_atom *atom, const 
char *arg)
die(_("unrecognized %%(if) argument: %s"), arg);
 }
 
+static void symref_atom_parser(struct used_atom *atom, const char *arg)
+{
+   if (!arg)
+   atom->u.symref = S_FULL;
+   else if (!strcmp(arg, "short"))
+   atom->u.symref = S_SHORT;
+   else
+   die(_("unrecognized %%(symref) argument: %s"), arg);
+}
 
 static struct {
const char *name;
@@ -252,7 +262,7 @@ static struct {
{ "contents", FIELD_STR, contents_atom_parser },
{ "upstream", FIELD_STR, remote_ref_atom_parser },
{ "push", FIELD_STR, remote_ref_atom_parser },
-   { "symref" },
+   { "symref", FIELD_STR, symref_atom_parser },
{ "flag" },
{ "HEAD" },
{ "color", FIELD_STR, color_atom_parser },
@@ -1132,6 +1142,17 @@ char *get_head_description(void)
return strbuf_detach(, NULL);
 }
 
+static const char *get_symref(struct used_atom *atom, struct ref_array_item 
*ref)
+{
+   if (!ref->symref)
+   return "";
+   else if (atom->u.symref == S_SHORT)
+   return shorten_unambiguous_ref(ref->symref,
+  warn_ambiguous_refs);
+   else
+   return ref->symref;
+}
+
 /*
  * Parse the object referred by ref, and grab needed value.
  */
@@ -1176,7 +1197,7 @@ static void populate_value(struct ref_array_item *ref)
if (ref->kind & FILTER_REFS_DETACHED_HEAD)
refname = get_head_description();
} else if (starts_with(name, "symref"))
-   refname = ref->symref ? ref->symref : "";
+   refname = get_symref(atom, ref);
else if (starts_with(name, "upstream")) {
const char *branch_name;
/* only local branches may have an upstream */
-- 
2.8.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 04/16] ref-filter: modify "%(objectname:short)" to take length

2016-04-09 Thread Karthik Nayak
Add support for %(objectname:short=) which would print the
abbreviated unique objectname of given length. When no length is
specified, the length is 'DEFAULT_ABBREV'. The minimum length is
'MINIMUM_ABBREV'. The length may be exceeded to ensure that the provided
object name is unique.

Add tests and documentation for the same.

Mentored-by: Christian Couder 
Mentored-by: Matthieu Moy 
Helped-by: Jacob Keller 
Signed-off-by: Karthik Nayak 
---
 Documentation/git-for-each-ref.txt |  4 
 ref-filter.c   | 25 +++--
 t/t6300-for-each-ref.sh| 10 ++
 3 files changed, 33 insertions(+), 6 deletions(-)

diff --git a/Documentation/git-for-each-ref.txt 
b/Documentation/git-for-each-ref.txt
index e1b1a66..d3223a2 100644
--- a/Documentation/git-for-each-ref.txt
+++ b/Documentation/git-for-each-ref.txt
@@ -107,6 +107,10 @@ objectsize::
 objectname::
The object name (aka SHA-1).
For a non-ambiguous abbreviation of the object name append `:short`.
+   For an abbreviation of the object name with desired length append
+   `:short=`, where the minimum length is MINIMUM_ABBREV. The
+   length may be exceeded to ensure unique object names.
+
 
 upstream::
The name of a local ref which can be considered ``upstream''
diff --git a/ref-filter.c b/ref-filter.c
index 857a8b5..17f781d 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -55,7 +55,10 @@ static struct used_atom {
const char *if_equals,
*not_equals;
} if_then_else;
-   enum { O_FULL, O_SHORT } objectname;
+   struct {
+   enum { O_FULL, O_LENGTH, O_SHORT } option;
+   unsigned int length;
+   } objectname;
} u;
 } *used_atom;
 static int used_atom_cnt, need_tagged, need_symref;
@@ -118,10 +121,17 @@ static void contents_atom_parser(struct used_atom *atom, 
const char *arg)
 static void objectname_atom_parser(struct used_atom *atom, const char *arg)
 {
if (!arg)
-   atom->u.objectname = O_FULL;
+   atom->u.objectname.option = O_FULL;
else if (!strcmp(arg, "short"))
-   atom->u.objectname = O_SHORT;
-   else
+   atom->u.objectname.option = O_SHORT;
+   else if (skip_prefix(arg, "short=", )) {
+   atom->u.contents.option = O_LENGTH;
+   if (strtoul_ui(arg, 10, >u.objectname.length) ||
+   atom->u.objectname.length == 0)
+   die(_("positive value expected objectname:short=%s"), 
arg);
+   if (atom->u.objectname.length < MINIMUM_ABBREV)
+   atom->u.objectname.length = MINIMUM_ABBREV;
+   } else
die(_("unrecognized %%(objectname) argument: %s"), arg);
 }
 
@@ -591,12 +601,15 @@ static int grab_objectname(const char *name, const 
unsigned char *sha1,
   struct atom_value *v, struct used_atom *atom)
 {
if (starts_with(name, "objectname")) {
-   if (atom->u.objectname == O_SHORT) {
+   if (atom->u.objectname.option == O_SHORT) {
v->s = xstrdup(find_unique_abbrev(sha1, 
DEFAULT_ABBREV));
return 1;
-   } else if (atom->u.objectname == O_FULL) {
+   } else if (atom->u.objectname.option == O_FULL) {
v->s = xstrdup(sha1_to_hex(sha1));
return 1;
+   } else if (atom->u.objectname.option == O_LENGTH) {
+   v->s = xstrdup(find_unique_abbrev(sha1, 
atom->u.objectname.length));
+   return 1;
} else
die("BUG: unknown %%(objectname) option");
}
diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh
index 19a2823..2be0a3f 100755
--- a/t/t6300-for-each-ref.sh
+++ b/t/t6300-for-each-ref.sh
@@ -60,6 +60,8 @@ test_atom head objecttype commit
 test_atom head objectsize 171
 test_atom head objectname $(git rev-parse refs/heads/master)
 test_atom head objectname:short $(git rev-parse --short refs/heads/master)
+test_atom head objectname:short=1 $(git rev-parse --short=1 refs/heads/master)
+test_atom head objectname:short=10 $(git rev-parse --short=10 
refs/heads/master)
 test_atom head tree $(git rev-parse refs/heads/master^{tree})
 test_atom head parent ''
 test_atom head numparent 0
@@ -99,6 +101,8 @@ test_atom tag objecttype tag
 test_atom tag objectsize 154
 test_atom tag objectname $(git rev-parse refs/tags/testtag)
 test_atom tag objectname:short $(git rev-parse --short refs/tags/testtag)
+test_atom head objectname:short=1 $(git rev-parse --short=1 refs/heads/master)
+test_atom head objectname:short=10 $(git rev-parse --short=10 
refs/heads/master)
 test_atom tag tree ''
 test_atom tag 

[PATCH v4 09/16] ref-filter: make "%(symref)" atom work with the ':short' modifier

2016-04-09 Thread Karthik Nayak
The "%(symref)" atom doesn't work when used with the ':short' modifier
because we strictly match only 'symref' for setting the 'need_symref'
indicator. Fix this by using comparing with valid_atom rather than used_atom.

Add tests for %(symref) and %(symref:short) while we're here.

Helped-by: Junio C Hamano 
Signed-off-by: Karthik Nayak 
---
 ref-filter.c|  2 +-
 t/t6300-for-each-ref.sh | 24 
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/ref-filter.c b/ref-filter.c
index 8c97cdb..5c59b17 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -338,7 +338,7 @@ int parse_ref_filter_atom(const char *atom, const char *ep)
valid_atom[i].parser(_atom[at], arg);
if (*atom == '*')
need_tagged = 1;
-   if (!strcmp(used_atom[at].name, "symref"))
+   if (!strcmp(valid_atom[i].name, "symref"))
need_symref = 1;
return at;
 }
diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh
index 2c5f177..b06ea1c 100755
--- a/t/t6300-for-each-ref.sh
+++ b/t/t6300-for-each-ref.sh
@@ -38,6 +38,7 @@ test_atom() {
case "$1" in
head) ref=refs/heads/master ;;
 tag) ref=refs/tags/testtag ;;
+sym) ref=refs/heads/sym ;;
   *) ref=$1 ;;
esac
printf '%s\n' "$3" >expected
@@ -565,4 +566,27 @@ test_expect_success 'Verify sort with multiple keys' '
refs/tags/bogo refs/tags/master > actual &&
test_cmp expected actual
 '
+
+test_expect_success 'Add symbolic ref for the following tests' '
+   git symbolic-ref refs/heads/sym refs/heads/master
+'
+
+cat >expected < actual &&
+   test_cmp expected actual
+'
+
+cat >expected < actual &&
+   test_cmp expected actual
+'
+
 test_done
-- 
2.8.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 11/16] ref-filter: introduce refname_atom_parser()

2016-04-09 Thread Karthik Nayak
Introduce refname_atom_parser() which will parse the '%(refname)' atom
and store information into the 'used_atom' structure based on the
modifiers used along with the atom.

Signed-off-by: Karthik Nayak 
---
 ref-filter.c | 70 +---
 1 file changed, 39 insertions(+), 31 deletions(-)

diff --git a/ref-filter.c b/ref-filter.c
index 7b35e4f..dc1e404 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -63,6 +63,10 @@ static struct used_atom {
unsigned int length;
} objectname;
enum { S_FULL, S_SHORT } symref;
+   struct {
+   enum { R_NORMAL, R_SHORT, R_STRIP } option;
+   unsigned int strip;
+   } refname;
} u;
 } *used_atom;
 static int used_atom_cnt, need_tagged, need_symref;
@@ -228,12 +232,27 @@ static void symref_atom_parser(struct used_atom *atom, 
const char *arg)
die(_("unrecognized %%(symref) argument: %s"), arg);
 }
 
+static void refname_atom_parser(struct used_atom *atom, const char *arg)
+{
+   if (!arg)
+   atom->u.refname.option = R_NORMAL;
+   else if (!strcmp(arg, "short"))
+   atom->u.refname.option = R_SHORT;
+   else if (skip_prefix(arg, "strip=", )) {
+   atom->u.contents.option = R_STRIP;
+   if (strtoul_ui(arg, 10, >u.refname.strip) ||
+   atom->u.refname.strip <= 0)
+   die(_("positive value expected refname:strip=%s"), arg);
+   } else
+   die(_("unrecognized %%(refname) argument: %s"), arg);
+}
+
 static struct {
const char *name;
cmp_type cmp_type;
void (*parser)(struct used_atom *atom, const char *arg);
 } valid_atom[] = {
-   { "refname" },
+   { "refname", FIELD_STR, refname_atom_parser },
{ "objecttype" },
{ "objectsize", FIELD_ULONG },
{ "objectname", FIELD_STR, objectname_atom_parser },
@@ -1047,21 +1066,16 @@ static inline char *copy_advance(char *dst, const char 
*src)
return dst;
 }
 
-static const char *strip_ref_components(const char *refname, const char 
*nr_arg)
+static const char *strip_ref_components(const char *refname, unsigned int len)
 {
-   char *end;
-   long nr = strtol(nr_arg, , 10);
-   long remaining = nr;
+   long remaining = len;
const char *start = refname;
 
-   if (nr < 1 || *end != '\0')
-   die(_(":strip= requires a positive integer argument"));
-
while (remaining) {
switch (*start++) {
case '\0':
-   die(_("ref '%s' does not have %ld components to 
:strip"),
-   refname, nr);
+   die("ref '%s' does not have %ud components to :strip",
+   refname, len);
case '/':
remaining--;
break;
@@ -1153,6 +1167,18 @@ static const char *get_symref(struct used_atom *atom, 
struct ref_array_item *ref
return ref->symref;
 }
 
+static const char *get_refname(struct used_atom *atom, struct ref_array_item 
*ref)
+{
+   if (ref->kind & FILTER_REFS_DETACHED_HEAD)
+   return get_head_description();
+   if (atom->u.refname.option == R_SHORT)
+   return shorten_unambiguous_ref(ref->refname, 
warn_ambiguous_refs);
+   else if (atom->u.refname.option == R_STRIP)
+   return strip_ref_components(ref->refname, 
atom->u.refname.strip);
+   else
+   return ref->refname;
+}
+
 /*
  * Parse the object referred by ref, and grab needed value.
  */
@@ -1181,7 +1207,6 @@ static void populate_value(struct ref_array_item *ref)
struct atom_value *v = >value[i];
int deref = 0;
const char *refname;
-   const char *formatp;
struct branch *branch = NULL;
 
v->handler = append_atom;
@@ -1192,11 +1217,9 @@ static void populate_value(struct ref_array_item *ref)
name++;
}
 
-   if (starts_with(name, "refname")) {
-   refname = ref->refname;
-   if (ref->kind & FILTER_REFS_DETACHED_HEAD)
-   refname = get_head_description();
-   } else if (starts_with(name, "symref"))
+   if (starts_with(name, "refname"))
+   refname = get_refname(atom, ref);
+   else if (starts_with(name, "symref"))
refname = get_symref(atom, ref);
else if (starts_with(name, "upstream")) {
const char *branch_name;
@@ -1273,21 +1296,6 @@ static void populate_value(struct ref_array_item *ref)
} else
continue;
 
-   formatp = strchr(name, ':');
-   

[PATCH v4 07/16] ref-filter: make %(upstream:track) prints "[gone]" for invalid upstreams

2016-04-09 Thread Karthik Nayak
Borrowing from branch.c's implementation print "[gone]" whenever an
unknown upstream ref is encountered instead of just ignoring it.

This makes sure that when branch.c is ported over to using ref-filter
APIs for printing, this feature is not lost.

Make changes to t/t6300-for-each-ref.sh and
Documentation/git-for-each-ref.txt to reflect this change.

Mentored-by: Christian Couder 
Mentored-by: Matthieu Moy 
Helped-by : Jacob Keller 
Signed-off-by: Karthik Nayak 
---
 Documentation/git-for-each-ref.txt | 3 ++-
 ref-filter.c   | 4 +++-
 t/t6300-for-each-ref.sh| 2 +-
 3 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/Documentation/git-for-each-ref.txt 
b/Documentation/git-for-each-ref.txt
index d3223a2..85ac2a8 100644
--- a/Documentation/git-for-each-ref.txt
+++ b/Documentation/git-for-each-ref.txt
@@ -119,7 +119,8 @@ upstream::
"[ahead N, behind M]" and `:trackshort` to show the terse
version: ">" (ahead), "<" (behind), "<>" (ahead and behind),
or "=" (in sync).  Has no effect if the ref does not have
-   tracking information associated with it.
+   tracking information associated with it. `:track` also prints
+   "[gone]" whenever unknown upstream ref is encountered.
 
 push::
The name of a local ref which represents the `@{push}` location
diff --git a/ref-filter.c b/ref-filter.c
index 3bb474f..4d7e0c0 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1049,8 +1049,10 @@ static void fill_remote_ref_details(struct used_atom 
*atom, const char *refname,
*s = shorten_unambiguous_ref(refname, warn_ambiguous_refs);
else if (atom->u.remote_ref == RR_TRACK) {
if (stat_tracking_info(branch, _ours,
-  _theirs, NULL))
+  _theirs, NULL)) {
+   *s = "[gone]";
return;
+   }
 
if (!num_ours && !num_theirs)
*s = "";
diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh
index 2be0a3f..a92b36f 100755
--- a/t/t6300-for-each-ref.sh
+++ b/t/t6300-for-each-ref.sh
@@ -382,7 +382,7 @@ test_expect_success 'Check that :track[short] cannot be 
used with other atoms' '
 
 test_expect_success 'Check that :track[short] works when upstream is invalid' '
cat >expected <<-\EOF &&
-
+   [gone]
 
EOF
test_when_finished "git config branch.master.merge refs/heads/master" &&
-- 
2.8.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 12/16] ref-filter: add support for %(refname:dir) and %(refname:base)

2016-04-09 Thread Karthik Nayak
Add the options `:dir` and `:base` to the %(refname) atom. The `:dir`
option gives the directory (the part after $GIT_DIR/) of the ref without
the refname. The `:base` option gives the base directory of the given
ref (i.e. the directory following $GIT_DIR/refs/).

Add tests and documentation for the same.

Signed-off-by: Karthik Nayak 
---
 Documentation/git-for-each-ref.txt |  4 +++-
 ref-filter.c   | 28 +---
 t/t6300-for-each-ref.sh|  2 ++
 3 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/Documentation/git-for-each-ref.txt 
b/Documentation/git-for-each-ref.txt
index be763c4..0d7d80f 100644
--- a/Documentation/git-for-each-ref.txt
+++ b/Documentation/git-for-each-ref.txt
@@ -96,7 +96,9 @@ refname::
slash-separated path components from the front of the refname
(e.g., `%(refname:strip=2)` turns `refs/tags/foo` into `foo`.
`` must be a positive integer.  If a displayed ref has fewer
-   components than ``, the command aborts with an error.
+   components than ``, the command aborts with an error. For the base
+   directory of the ref (i.e. foo in refs/foo/bar/boz) append
+   `:base`. For the entire directory path append `:dir`.
 
 objecttype::
The type of the object (`blob`, `tree`, `commit`, `tag`).
diff --git a/ref-filter.c b/ref-filter.c
index dc1e404..73e0a7f 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -64,7 +64,7 @@ static struct used_atom {
} objectname;
enum { S_FULL, S_SHORT } symref;
struct {
-   enum { R_NORMAL, R_SHORT, R_STRIP } option;
+   enum { R_BASE, R_DIR, R_NORMAL, R_SHORT, R_STRIP } 
option;
unsigned int strip;
} refname;
} u;
@@ -243,7 +243,11 @@ static void refname_atom_parser(struct used_atom *atom, 
const char *arg)
if (strtoul_ui(arg, 10, >u.refname.strip) ||
atom->u.refname.strip <= 0)
die(_("positive value expected refname:strip=%s"), arg);
-   } else
+   } else if (!strcmp(arg, "dir"))
+   atom->u.contents.option = R_DIR;
+   else if (!strcmp(arg, "base"))
+   atom->u.contents.option = R_BASE;
+   else
die(_("unrecognized %%(refname) argument: %s"), arg);
 }
 
@@ -1175,7 +1179,25 @@ static const char *get_refname(struct used_atom *atom, 
struct ref_array_item *re
return shorten_unambiguous_ref(ref->refname, 
warn_ambiguous_refs);
else if (atom->u.refname.option == R_STRIP)
return strip_ref_components(ref->refname, 
atom->u.refname.strip);
-   else
+   else if (atom->u.refname.option == R_BASE) {
+   const char *sp, *ep;
+
+   if (skip_prefix(ref->refname, "refs/", )) {
+   ep = strchr(sp, '/');
+   if (!ep)
+   return "";
+   return xstrndup(sp, ep - sp);
+   }
+   return "";
+   } else if (atom->u.refname.option == R_DIR) {
+   const char *sp, *ep;
+
+   sp = ref->refname;
+   ep = strrchr(sp, '/');
+   if (!ep)
+   return "";
+   return xstrndup(sp, ep - sp);
+   } else
return ref->refname;
 }
 
diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh
index b06ea1c..36d32d7 100755
--- a/t/t6300-for-each-ref.sh
+++ b/t/t6300-for-each-ref.sh
@@ -53,6 +53,8 @@ test_atom head refname refs/heads/master
 test_atom head refname:short master
 test_atom head refname:strip=1 heads/master
 test_atom head refname:strip=2 master
+test_atom head refname:dir refs/heads
+test_atom head refname:base heads
 test_atom head upstream refs/remotes/origin/master
 test_atom head upstream:short origin/master
 test_atom head push refs/remotes/myfork/master
-- 
2.8.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 02/16] ref-filter: include reference to 'used_atom' within 'atom_value'

2016-04-09 Thread Karthik Nayak
Ensure that each 'atom_value' has a reference to its corresponding
'used_atom'. This let's us use values within 'used_atom' in the
'handler' function.

Hence we can get the %(align) atom's parameters directly from the
'used_atom' therefore removing the necessity of passing %(align) atom's
parameters to 'atom_value'.

This also acts as a preparatory patch for the upcoming patch where we
introduce %(if:equals=) and %(if:notequals=).

Signed-off-by: Karthik Nayak 
---
 ref-filter.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/ref-filter.c b/ref-filter.c
index 41e73f0..12e646c 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -230,11 +230,9 @@ struct ref_formatting_state {
 
 struct atom_value {
const char *s;
-   union {
-   struct align align;
-   } u;
void (*handler)(struct atom_value *atomv, struct ref_formatting_state 
*state);
unsigned long ul; /* used for sorting when not FIELD_STR */
+   struct used_atom *atom;
 };
 
 /*
@@ -370,7 +368,7 @@ static void align_atom_handler(struct atom_value *atomv, 
struct ref_formatting_s
push_stack_element(>stack);
new = state->stack;
new->at_end = end_align_handler;
-   new->at_end_data = >u.align;
+   new->at_end_data = >atom->u.align;
 }
 
 static void if_then_else_handler(struct ref_formatting_stack **stack)
@@ -1069,6 +1067,7 @@ static void populate_value(struct ref_array_item *ref)
struct branch *branch = NULL;
 
v->handler = append_atom;
+   v->atom = atom;
 
if (*name == '*') {
deref = 1;
@@ -1133,7 +1132,6 @@ static void populate_value(struct ref_array_item *ref)
v->s = " ";
continue;
} else if (starts_with(name, "align")) {
-   v->u.align = atom->u.align;
v->handler = align_atom_handler;
continue;
} else if (!strcmp(name, "end")) {
-- 
2.8.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 00/16] port branch.c to use ref-filter's printing options

2016-04-09 Thread Karthik Nayak
This is part of unification of the commands 'git tag -l, git branch -l
and git for-each-ref'. This ports over branch.c to use ref-filter's
printing options.

Initially posted here: $(gmane/279226). It was decided that this series
would follow up after refactoring ref-filter parsing mechanism, which
is now merged into master (9606218b32344c5c756f7c29349d3845ef60b80c).

v1 can be found here: $(gmane/288342)
v2 can be found here: $(gmane/288863)
v3 can be found here: $(gmane/290299)

Changes in this version:
1. Rebased on top of Erics changes, this was breaking tests. Thanks
to Dennis Kaarsemaker and Ramsay Jones for reporting this in.
2. Show local branch symrefs if available, changed this in the format
for `git branch -l`.

Thanks to Junio, Matthieu, Dennis and Ramsay for all suggestions on the
previous iteration.

Karthik Nayak (16):
  ref-filter: implement %(if), %(then), and %(else) atoms
  ref-filter: include reference to 'used_atom' within 'atom_value'
  ref-filter: implement %(if:equals=) and
%(if:notequals=)
  ref-filter: modify "%(objectname:short)" to take length
  ref-filter: move get_head_description() from branch.c
  ref-filter: introduce format_ref_array_item()
  ref-filter: make %(upstream:track) prints "[gone]" for invalid
upstreams
  ref-filter: add support for %(upstream:track,nobracket)
  ref-filter: make "%(symref)" atom work with the ':short' modifier
  ref-filter: introduce symref_atom_parser()
  ref-filter: introduce refname_atom_parser()
  ref-filter: add support for %(refname:dir) and %(refname:base)
  ref-filter: allow porcelain to translate messages in the output
  branch, tag: use porcelain output
  branch: use ref-filter printing APIs
  branch: implement '--format' option

 Documentation/git-branch.txt   |   7 +-
 Documentation/git-for-each-ref.txt |  63 +-
 builtin/branch.c   | 268 ++
 builtin/tag.c  |   2 +
 ref-filter.c   | 447 +++--
 ref-filter.h   |   7 +
 t/t3203-branch-output.sh   |  12 +
 t/t6040-tracking-info.sh   |   2 +-
 t/t6300-for-each-ref.sh|  40 +++-
 t/t6302-for-each-ref-filter.sh |  94 
 10 files changed, 664 insertions(+), 278 deletions(-)

Interdiff:

diff --git a/builtin/branch.c b/builtin/branch.c
index fb05b39..665ee57 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -320,7 +320,8 @@ static char *build_format(struct ref_filter *filter, int 
maxwidth, const char *r
branch_get_color(BRANCH_COLOR_REMOTE), maxwidth,
remote_prefix, 
branch_get_color(BRANCH_COLOR_RESET));
} else {
-   strbuf_addf(, "%%(refname:strip=2)%s", 
branch_get_color(BRANCH_COLOR_RESET));
+   strbuf_addf(, 
"%%(refname:strip=2)%s%%(if)%%(symref)%%(then) -> %%(symref:short)%%(end)",
+   branch_get_color(BRANCH_COLOR_RESET));
strbuf_addf(, 
"%s%s%%(refname:strip=2)%s%%(if)%%(symref)%%(then) -> %%(symref:short)%%(end)",
branch_get_color(BRANCH_COLOR_REMOTE), 
remote_prefix, branch_get_color(BRANCH_COLOR_RESET));
}
diff --git a/t/t6302-for-each-ref-filter.sh b/t/t6302-for-each-ref-filter.sh
index 841f0c1..206ad67 100755
--- a/t/t6302-for-each-ref-filter.sh
+++ b/t/t6302-for-each-ref-filter.sh
@@ -349,6 +349,8 @@ test_expect_success 'check %(if)...%(then)...%(end) atoms' '
A U Thor: refs/heads/side
A U Thor: refs/odd/spot

+   
+   
A U Thor: refs/tags/foo1.10
A U Thor: refs/tags/foo1.3
A U Thor: refs/tags/foo1.6
@@ -367,7 +369,9 @@ test_expect_success 'check 
%(if)...%(then)...%(else)...%(end) atoms' '
A U Thor: refs/heads/master
A U Thor: refs/heads/side
A U Thor: refs/odd/spot
-   No author: refs/tags/double-tag
+   No author: refs/tags/annotated-tag
+   No author: refs/tags/doubly-annotated-tag
+   No author: refs/tags/doubly-signed-tag
A U Thor: refs/tags/foo1.10
A U Thor: refs/tags/foo1.3
A U Thor: refs/tags/foo1.6
@@ -385,7 +389,9 @@ test_expect_success 'ignore spaces in %(if) atom usage' '
master: Head ref
side: Not Head ref
odd/spot: Not Head ref
-   double-tag: Not Head ref
+   annotated-tag: Not Head ref
+   doubly-annotated-tag: Not Head ref
+   doubly-signed-tag: Not Head ref
foo1.10: Not Head ref
foo1.3: Not Head ref
foo1.6: Not Head ref


-- 
2.8.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 05/16] ref-filter: move get_head_description() from branch.c

2016-04-09 Thread Karthik Nayak
Move the implementation of get_head_description() from branch.c to
ref-filter.  This gives a description of the HEAD ref if called. This
is used as the refname for the HEAD ref whenever the
FILTER_REFS_DETACHED_HEAD option is used. Make it public because we
need it to calculate the length of the HEAD refs description in
branch.c:calc_maxwidth() when we port branch.c to use ref-filter
APIs.

Mentored-by: Christian Couder 
Mentored-by: Matthieu Moy 
Signed-off-by: Karthik Nayak 
---
 builtin/branch.c | 31 ---
 ref-filter.c | 38 --
 ref-filter.h |  2 ++
 3 files changed, 38 insertions(+), 33 deletions(-)

diff --git a/builtin/branch.c b/builtin/branch.c
index 7b45b6b..460f32f 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -355,37 +355,6 @@ static void add_verbose_info(struct strbuf *out, struct 
ref_array_item *item,
strbuf_release();
 }
 
-static char *get_head_description(void)
-{
-   struct strbuf desc = STRBUF_INIT;
-   struct wt_status_state state;
-   memset(, 0, sizeof(state));
-   wt_status_get_state(, 1);
-   if (state.rebase_in_progress ||
-   state.rebase_interactive_in_progress)
-   strbuf_addf(, _("(no branch, rebasing %s)"),
-   state.branch);
-   else if (state.bisect_in_progress)
-   strbuf_addf(, _("(no branch, bisect started on %s)"),
-   state.branch);
-   else if (state.detached_from) {
-   /* TRANSLATORS: make sure these match _("HEAD detached at ")
-  and _("HEAD detached from ") in wt-status.c */
-   if (state.detached_at)
-   strbuf_addf(, _("(HEAD detached at %s)"),
-   state.detached_from);
-   else
-   strbuf_addf(, _("(HEAD detached from %s)"),
-   state.detached_from);
-   }
-   else
-   strbuf_addstr(, _("(no branch)"));
-   free(state.branch);
-   free(state.onto);
-   free(state.detached_from);
-   return strbuf_detach(, NULL);
-}
-
 static void format_and_print_ref_item(struct ref_array_item *item, int 
maxwidth,
  struct ref_filter *filter, const char 
*remote_prefix)
 {
diff --git a/ref-filter.c b/ref-filter.c
index 17f781d..7004bf0 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -13,6 +13,7 @@
 #include "utf8.h"
 #include "git-compat-util.h"
 #include "version.h"
+#include "wt-status.h"
 
 typedef enum { FIELD_STR, FIELD_ULONG, FIELD_TIME } cmp_type;
 
@@ -1077,6 +1078,37 @@ static void fill_remote_ref_details(struct used_atom 
*atom, const char *refname,
*s = refname;
 }
 
+char *get_head_description(void)
+{
+   struct strbuf desc = STRBUF_INIT;
+   struct wt_status_state state;
+   memset(, 0, sizeof(state));
+   wt_status_get_state(, 1);
+   if (state.rebase_in_progress ||
+   state.rebase_interactive_in_progress)
+   strbuf_addf(, _("(no branch, rebasing %s)"),
+   state.branch);
+   else if (state.bisect_in_progress)
+   strbuf_addf(, _("(no branch, bisect started on %s)"),
+   state.branch);
+   else if (state.detached_from) {
+   /* TRANSLATORS: make sure these match _("HEAD detached at ")
+  and _("HEAD detached from ") in wt-status.c */
+   if (state.detached_at)
+   strbuf_addf(, _("(HEAD detached at %s)"),
+   state.detached_from);
+   else
+   strbuf_addf(, _("(HEAD detached from %s)"),
+   state.detached_from);
+   }
+   else
+   strbuf_addstr(, _("(no branch)"));
+   free(state.branch);
+   free(state.onto);
+   free(state.detached_from);
+   return strbuf_detach(, NULL);
+}
+
 /*
  * Parse the object referred by ref, and grab needed value.
  */
@@ -1116,9 +1148,11 @@ static void populate_value(struct ref_array_item *ref)
name++;
}
 
-   if (starts_with(name, "refname"))
+   if (starts_with(name, "refname")) {
refname = ref->refname;
-   else if (starts_with(name, "symref"))
+   if (ref->kind & FILTER_REFS_DETACHED_HEAD)
+   refname = get_head_description();
+   } else if (starts_with(name, "symref"))
refname = ref->symref ? ref->symref : "";
else if (starts_with(name, "upstream")) {
const char *branch_name;
diff --git a/ref-filter.h b/ref-filter.h
index 14d435e..4aea594 100644
--- a/ref-filter.h
+++ b/ref-filter.h
@@ -106,5 +106,7 @@ int 

[PATCH v4 03/16] ref-filter: implement %(if:equals=) and %(if:notequals=)

2016-04-09 Thread Karthik Nayak
Implement %(if:equals=) wherein the if condition is only
satisfied if the value obtained between the %(if:...) and %(then) atom
is the same as the given ''.

Similarly, implement (if:notequals=) wherein the if condition
is only satisfied if the value obtained between the %(if:...) and
%(then) atom is differnt from the given ''.

This is done by introducing 'if_atom_parser()' which parses the given
%(if) atom and then stores the data in used_atom which is later passed
on to the used_atom of the %(then) atom, so that it can do the required
comparisons.

Add tests and Documentation for the same.

Mentored-by: Christian Couder 
Mentored-by: Matthieu Moy 
Signed-off-by: Karthik Nayak 
---
 Documentation/git-for-each-ref.txt |  3 +++
 ref-filter.c   | 43 +-
 t/t6302-for-each-ref-filter.sh | 18 
 3 files changed, 59 insertions(+), 5 deletions(-)

diff --git a/Documentation/git-for-each-ref.txt 
b/Documentation/git-for-each-ref.txt
index d048561..e1b1a66 100644
--- a/Documentation/git-for-each-ref.txt
+++ b/Documentation/git-for-each-ref.txt
@@ -152,6 +152,9 @@ if::
evaluating the string before %(then), this is useful when we
use the %(HEAD) atom which prints either "*" or " " and we
want to apply the 'if' condition only on the 'HEAD' ref.
+   Append ":equals=" or ":notequals=" to compare
+   the value between the %(if:...) and %(then) atoms with the
+   given string.
 
 In addition to the above, for commit and tag objects, the header
 field names (`tree`, `parent`, `object`, `type`, and `tag`) can
diff --git a/ref-filter.c b/ref-filter.c
index 12e646c..857a8b5 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -22,6 +22,8 @@ struct align {
 };
 
 struct if_then_else {
+   const char *if_equals,
+   *not_equals;
unsigned int then_atom_seen : 1,
else_atom_seen : 1,
condition_satisfied : 1;
@@ -49,6 +51,10 @@ static struct used_atom {
enum { C_BARE, C_BODY, C_BODY_DEP, C_LINES, C_SIG, 
C_SUB } option;
unsigned int nlines;
} contents;
+   struct {
+   const char *if_equals,
+   *not_equals;
+   } if_then_else;
enum { O_FULL, O_SHORT } objectname;
} u;
 } *used_atom;
@@ -169,6 +175,19 @@ static void align_atom_parser(struct used_atom *atom, 
const char *arg)
string_list_clear(, 0);
 }
 
+static void if_atom_parser(struct used_atom *atom, const char *arg)
+{
+   if (!arg)
+   return;
+   else if (skip_prefix(arg, "equals=", >u.if_then_else.if_equals))
+;
+   else if (skip_prefix(arg, "notequals=", 
>u.if_then_else.not_equals))
+   ;
+   else
+   die(_("unrecognized %%(if) argument: %s"), arg);
+}
+
+
 static struct {
const char *name;
cmp_type cmp_type;
@@ -209,7 +228,7 @@ static struct {
{ "color", FIELD_STR, color_atom_parser },
{ "align", FIELD_STR, align_atom_parser },
{ "end" },
-   { "if" },
+   { "if", FIELD_STR, if_atom_parser },
{ "then" },
{ "else" },
 };
@@ -410,6 +429,9 @@ static void if_atom_handler(struct atom_value *atomv, 
struct ref_formatting_stat
struct ref_formatting_stack *new;
struct if_then_else *if_then_else = xcalloc(sizeof(struct 
if_then_else), 1);
 
+   if_then_else->if_equals = atomv->atom->u.if_then_else.if_equals;
+   if_then_else->not_equals = atomv->atom->u.if_then_else.not_equals;
+
push_stack_element(>stack);
new = state->stack;
new->at_end = if_then_else_handler;
@@ -441,10 +463,17 @@ static void then_atom_handler(struct atom_value *atomv, 
struct ref_formatting_st
die(_("format: %%(then) atom used after %%(else)"));
if_then_else->then_atom_seen = 1;
/*
-* If there exists non-empty string between the 'if' and
-* 'then' atom then the 'if' condition is satisfied.
+* If the 'equals' or 'notequals' attribute is used then
+* perform the required comparison. If not, only non-empty
+* strings satisfy the 'if' condition.
 */
-   if (cur->output.len && !is_empty(cur->output.buf))
+   if (if_then_else->if_equals) {
+   if (!strcmp(if_then_else->if_equals, cur->output.buf))
+   if_then_else->condition_satisfied = 1;
+   } else  if (if_then_else->not_equals) {
+   if (strcmp(if_then_else->not_equals, cur->output.buf))
+   if_then_else->condition_satisfied = 1;
+   } else if (cur->output.len && !is_empty(cur->output.buf))
if_then_else->condition_satisfied = 1;
strbuf_reset(>output);
 }
@@ -1137,7 +1166,11 @@ static void 

[PATCH v4 01/16] ref-filter: implement %(if), %(then), and %(else) atoms

2016-04-09 Thread Karthik Nayak
Implement %(if), %(then) and %(else) atoms. Used as
%(if)...%(then)...%(end) or %(if)...%(then)...%(else)...%(end). If the
format string between %(if) and %(then) expands to an empty string, or
to only whitespaces, then the whole %(if)...%(end) expands to the string
following %(then). Otherwise, it expands to the string following
%(else), if any. Nesting of this construct is possible.

This is in preparation for porting over `git branch -l` to use
ref-filter APIs for printing.

Add Documentation and tests regarding the same.

Mentored-by: Christian Couder 
Mentored-by: Matthieu Moy 
Signed-off-by: Karthik Nayak 
---
 Documentation/git-for-each-ref.txt |  45 +++--
 ref-filter.c   | 133 +++--
 t/t6302-for-each-ref-filter.sh |  76 +
 3 files changed, 243 insertions(+), 11 deletions(-)

diff --git a/Documentation/git-for-each-ref.txt 
b/Documentation/git-for-each-ref.txt
index 012e8f9..d048561 100644
--- a/Documentation/git-for-each-ref.txt
+++ b/Documentation/git-for-each-ref.txt
@@ -141,10 +141,17 @@ align::
"width=" and/or "position=" prefixes may be omitted, and bare
 and  used instead.  For instance,
`%(align:,)`. If the contents length is more
-   than the width then no alignment is performed. If used with
-   '--quote' everything in between %(align:...) and %(end) is
-   quoted, but if nested then only the topmost level performs
-   quoting.
+   than the width then no alignment is performed.
+
+if::
+   Used as %(if)...%(then)...(%end) or
+   %(if)...%(then)...%(else)...%(end).  If there is an atom with
+   value or string literal after the %(if) then everything after
+   the %(then) is printed, else if the %(else) atom is used, then
+   everything after %(else) is printed. We ignore space when
+   evaluating the string before %(then), this is useful when we
+   use the %(HEAD) atom which prints either "*" or " " and we
+   want to apply the 'if' condition only on the 'HEAD' ref.
 
 In addition to the above, for commit and tag objects, the header
 field names (`tree`, `parent`, `object`, `type`, and `tag`) can
@@ -181,6 +188,20 @@ As a special case for the date-type fields, you may 
specify a format for
 the date by adding `:` followed by date format name (see the
 values the `--date` option to linkgit::git-rev-list[1] takes).
 
+Some atoms like %(align) and %(if) always require a matching %(end).
+We call them "opening atoms" and sometimes denote them as %($open).
+
+When a scripting language specific quoting is in effect (i.e. one of
+`--shell`, `--perl`, `--python`, `--tcl` is used), except for opening
+atoms, replacement from every %(atom) is quoted when and only when it
+appears at the top-level (that is, when it appears outside
+%($open)...%(end)).
+
+When a scripting language specific quoting is in effect, everything
+between a top-level opening atom and its matching %(end) is evaluated
+according to the semantics of the opening atom and its result is
+quoted.
+
 
 EXAMPLES
 
@@ -268,6 +289,22 @@ eval=`git for-each-ref --shell --format="$fmt" \
 eval "$eval"
 
 
+
+An example to show the usage of %(if)...%(then)...%(else)...%(end).
+This prefixes the current branch with a star.
+
+
+git for-each-ref --format="%(if)%(HEAD)%(then)* %(else)  
%(end)%(refname:short)" refs/heads/
+
+
+
+An example to show the usage of %(if)...%(then)...%(end).
+This prints the authorname, if present.
+
+
+git for-each-ref --format="%(refname)%(if)%(authorname)%(then) 
%(color:red)Authored by: %(authorname)%(end)"
+
+
 SEE ALSO
 
 linkgit:git-show-ref[1]
diff --git a/ref-filter.c b/ref-filter.c
index bc551a7..41e73f0 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -21,6 +21,12 @@ struct align {
unsigned int width;
 };
 
+struct if_then_else {
+   unsigned int then_atom_seen : 1,
+   else_atom_seen : 1,
+   condition_satisfied : 1;
+};
+
 /*
  * An atom is a valid field atom listed below, possibly prefixed with
  * a "*" to denote deref_tag().
@@ -203,6 +209,9 @@ static struct {
{ "color", FIELD_STR, color_atom_parser },
{ "align", FIELD_STR, align_atom_parser },
{ "end" },
+   { "if" },
+   { "then" },
+   { "else" },
 };
 
 #define REF_FORMATTING_STATE_INIT  { 0, NULL }
@@ -210,7 +219,7 @@ static struct {
 struct ref_formatting_stack {
struct ref_formatting_stack *prev;
struct strbuf output;
-   void (*at_end)(struct ref_formatting_stack *stack);
+   void (*at_end)(struct ref_formatting_stack **stack);
void *at_end_data;
 };
 
@@ -343,13 +352,14 @@ static void pop_stack_element(struct ref_formatting_stack 
**stack)
*stack = prev;
 }
 
-static void end_align_handler(struct ref_formatting_stack 

[PATCH 3/3] git_config_set_multivar_in_file: handle "unset" errors

2016-04-09 Thread Jeff King
We pass off to the "_gently" form to do the real work, and
just die() if it returned an error. However, our die message
de-references "value", which may be NULL if the request was
to unset a variable. Nobody using glibc noticed, because it
simply prints "(null)", which is good enough for the test
suite (and presumably very few people run across this in
practice). But other libc implementations (like Solaris) may
segfault.

Let's not only fix that, but let's make the message more
clear about what is going on in the "unset" case.

Reported-by: "Tom G. Christensen" 
Signed-off-by: Jeff King 
---
 config.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/config.c b/config.c
index d446315..3fe40c3 100644
--- a/config.c
+++ b/config.c
@@ -2221,9 +2221,13 @@ void git_config_set_multivar_in_file(const char 
*config_filename,
 const char *key, const char *value,
 const char *value_regex, int multi_replace)
 {
-   if (git_config_set_multivar_in_file_gently(config_filename, key, value,
-  value_regex, multi_replace))
+   if (!git_config_set_multivar_in_file_gently(config_filename, key, value,
+   value_regex, multi_replace))
+   return;
+   if (value)
die(_("could not set '%s' to '%s'"), key, value);
+   else
+   die(_("could not unset '%s'"), key);
 }
 
 int git_config_set_multivar_gently(const char *key, const char *value,
-- 
2.8.1.245.g18e0f5c
--
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 2/3] git_config_set_multivar_in_file: all non-zero returns are errors

2016-04-09 Thread Jeff King
This function is just a thin wrapper for the "_gently" form
of the function. But the gently form is designed to feed
builtin/config.c, which passes our return code directly to
its exit status, and thus uses positive error values for
some cases. We check only negative values, meaning we would
fail to die in some cases (e.g., a malformed key).

This may or may not be triggerable in practice; we tend to
use this non-gentle form only when setting internal
variables, which would not have malformed keys.

Signed-off-by: Jeff King 
---
 config.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/config.c b/config.c
index 6b81931..d446315 100644
--- a/config.c
+++ b/config.c
@@ -,7 +,7 @@ void git_config_set_multivar_in_file(const char 
*config_filename,
 const char *value_regex, int multi_replace)
 {
if (git_config_set_multivar_in_file_gently(config_filename, key, value,
-  value_regex, multi_replace) 
< 0)
+  value_regex, multi_replace))
die(_("could not set '%s' to '%s'"), key, value);
 }
 
-- 
2.8.1.245.g18e0f5c

--
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 1/3] config: lower-case first word of error strings

2016-04-09 Thread Jeff King
This follows our usual style (both throughout git, and
throughout the rest of this file).

This covers the whole file, but note that I left the capitalization in
the multi-sentence:

  error: malformed value...
  error: Must be one of ...

because it helps make it clear that we are starting a new sentence in
the second one.

Signed-off-by: Jeff King 
---
 config.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/config.c b/config.c
index 8f66519..6b81931 100644
--- a/config.c
+++ b/config.c
@@ -108,7 +108,7 @@ static int handle_path_include(const char *path, struct 
config_include_data *inc
 
expanded = expand_user_path(path);
if (!expanded)
-   return error("Could not expand include path '%s'", path);
+   return error("could not expand include path '%s'", path);
path = expanded;
 
/*
@@ -950,7 +950,7 @@ static int git_default_branch_config(const char *var, const 
char *value)
else if (!strcmp(value, "always"))
autorebase = AUTOREBASE_ALWAYS;
else
-   return error("Malformed value for %s", var);
+   return error("malformed value for %s", var);
return 0;
}
 
@@ -976,7 +976,7 @@ static int git_default_push_config(const char *var, const 
char *value)
else if (!strcmp(value, "current"))
push_default = PUSH_DEFAULT_CURRENT;
else {
-   error("Malformed value for %s: %s", var, value);
+   error("malformed value for %s: %s", var, value);
return error("Must be one of nothing, matching, simple, 
"
 "upstream or current.");
}
@@ -2223,7 +2223,7 @@ void git_config_set_multivar_in_file(const char 
*config_filename,
 {
if (git_config_set_multivar_in_file_gently(config_filename, key, value,
   value_regex, multi_replace) 
< 0)
-   die(_("Could not set '%s' to '%s'"), key, value);
+   die(_("could not set '%s' to '%s'"), key, value);
 }
 
 int git_config_set_multivar_gently(const char *key, const char *value,
@@ -2404,7 +2404,7 @@ int git_config_rename_section(const char *old_name, const 
char *new_name)
 #undef config_error_nonbool
 int config_error_nonbool(const char *var)
 {
-   return error("Missing value for '%s'", var);
+   return error("missing value for '%s'", var);
 }
 
 int parse_config_key(const char *var,
-- 
2.8.1.245.g18e0f5c

--
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: git segfaults on older Solaris releases

2016-04-09 Thread Jeff King
On Sat, Apr 09, 2016 at 09:02:38AM +0200, Tom G. Christensen wrote:

> I've finished testing 2.8.1 and I found one more case where a null is being
> printed and causing a segfault. This happens even on Solaris 8 and 9.
> The failling test is t3200.63.

Oh good, this one wasn't me. :)

It's just a normal "oops, we feed NULL and nobody on glibc noticed
because it silently replaced it with "(null)" case. I did find a few
other oddities while fixing it, though. +cc Patrick, who worked in this
area most recently.

  [1/3]: config: lower-case first word of error strings
  [2/3]: git_config_set_multivar_in_file: all non-zero returns are errors
  [3/3]: git_config_set_multivar_in_file: handle "unset" errors

I think we may want some additional improvements. While doing 1/3, I
noticed that many of these error messages could stand to be marked for
translation. As other people are already looking at mass-conversion,
I stopped short of doing it here (and merely contented myself with
throwing a conflict into their patches ;) ).

The other thing is that 2/3 notices the error return from the
config-setting functions is weird. It's sometimes negative and sometimes
positive. I fixed this caller, but I think it's possible for the
negative values to leak into our exit codes:

  $ touch .git/config
  $ git config foo.bar baz
  error: could not lock config file .git/config: File exists
  $ echo $?
  255

I seem to recall some systems having trouble with negative error codes,
so we may want to make that more consistent.

-Peff
--
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] rebase: convert revert to squash on autosquash

2016-04-09 Thread Michael S. Tsirkin
On Fri, Apr 08, 2016 at 01:13:51PM +0200, Johannes Schindelin wrote:
> Hi Michael,
> 
> On Thu, 7 Apr 2016, Michael S. Tsirkin wrote:
> 
> > On Thu, Apr 07, 2016 at 05:23:09PM +0200, Johannes Schindelin wrote:
> > > 
> > > On Thu, 7 Apr 2016, Michael S. Tsirkin wrote:
> > > 
> > > > Reverts can typically be treated like squash.  Eliminating both the
> > > > original commit and the revert would be even nicer, but this seems a bit
> > > > harder to implement.
> > > 
> > > Whoa. This rings a lot of alarm bells, very loudly.
> > 
> > Whoa don't be alarmed. It's just a patch :).
> 
> It's just a patch. Like every major breakage would be. So: no, there is
> reason to be alarmed if it is likely to disrupt normal usage.
> 
> > > It seems you intend to introduce a *major* change in behavior,
> > 
> > Doing this automatically for all users might be a bit too drastic for
> > the upstream git.
> 
> That is a pretty safe thing to say, even without the subjunctive.
> 
> > If there's a commit later followed by a revert, history can be
> > simplified by squashing them, and if the result is empty, removing both.
> 
> True. But that is not what the user told Git to do. If the user's
> intention was to squash the reverting patch, she could have easily done
> this:
> 
>   git revert -n deadbeef
>   git commit --squash deadbeef
> 
> where "deadbeef" is the placeholder for the actual commit to revert.
> 
> And indeed, I use exactly this song and dance quite frequently, *iff* my
> intention is to drop a patch.

Well then you have to decide whether you want to drop it
when you commit.
If *I* want do drop the patch when I commit, I just do
git rebase.

> A much better idea than co-opting the "Revert" commit message would be to
> introduce a sibling to --fixup and --squash that you could call --drop.
> 
> Ciao,
> Johannes

Maybe but it's a different usecase.

What this addresses is a case where you first wanted to
avoid rebases, so you reverted.
But then you rebased after all.
Now finding what was reverted automatically is helpful.

--
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 00/24] Yet another pre-refs-backend series

2016-04-09 Thread Michael Haggerty
On 04/07/2016 03:02 PM, David Turner wrote:
> We now have quite a large number of patches before we even get into
> the meat of the pluggable refs backend series.  So it's worth breaking
> those out and getting them in before we get into the main series
> (which Michael Haggerty swants to redesign a bit anyway).
> 
> This set of patches should be applied on top of
> jk/check-repository-format.
> 
> Michael Haggerty has reviewed those of my patches which are in here
> except maybe:
>   refs: on symref reflog expire, lock symref not referrent
> This was the one from later in the series that was straightforward to
> move to before the vtable; the other two were going to be harder to
> move and can wait until after the vtable.

This last patch deserves a little bit of discussion. Currently, when the
reflog of a symref is expired, the pointed-to ref is locked rather than
the symref. This patch changes the code to lock the symref instead.

This is clearly the right thing to do, and I consider this change a bug
fix. However, it introduces an incompatibility. An old version of `git
reflog expire` and a new version wouldn't agree on the locking protocol,
and could potentially try to overwrite the same reflog at the same time.

I think this risk is acceptable nevertheless, because expiring reflogs
is an uncommon operation and unlikely to be done from two processes at
the same time; moreover, the integrity of reflogs is not a matter of
life or death.

A far more likely conflict would be between a reflog expiration and a
symref update (e.g., `git checkout otherbranch`). This use case is
currently *broken* because `git checkout` locks HEAD. It would be fixed
by this patch.

If somebody is really upset about the risk of a race between an old and
new version of `git reflog expire`, the way to increase the safety would
be to lock *both* the symref and the referent while changing the
symref's reflog. I think that would be overkill.

This whole series is

Reviewed-by: Michael Haggerty 

David mentioned that I want to redesign the vtable patches somewhat.
Anybody who is curious can look at the work in progress branch on my
GitHub fork [1], branch wip/ref-storage.

Michael

[1] https://github.com/mhagger/git

--
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 2/4] format-patch: add '--base' option to record base tree info

2016-04-09 Thread Ye Xiaolong
On Thu, Mar 31, 2016 at 10:38:04AM -0700, Junio C Hamano wrote:
>> diff --git a/builtin/log.c b/builtin/log.c
>> index 0d738d6..03cbab0 100644
>> --- a/builtin/log.c
>> +++ b/builtin/log.c
>> @@ -1185,6 +1185,82 @@ static int from_callback(const struct option *opt, 
>> const char *arg, int unset)
>>  return 0;
>>  }
>>  
>> +struct base_tree_info {
>> +struct object_id base_commit;
>> +int nr_patch_id, alloc_patch_id;
>> +struct object_id *patch_id;
>> +};
>> +
>> +static void prepare_bases(struct base_tree_info *bases,
>> +  const char *base_commit,
>> +  struct commit **list,
>> +  int total)
>> +{
>> +struct commit *base = NULL, *commit;
>> +struct rev_info revs;
>> +struct diff_options diffopt;
>> +struct object_id *patch_id;
>> +unsigned char sha1[20];
>> +int i;
>> +
>> +diff_setup();
>> +DIFF_OPT_SET(, RECURSIVE);
>> +diff_setup_done();
>> +
>> +base = lookup_commit_reference_by_name(base_commit);
>> +if (!base)
>> +die(_("Unknown commit %s"), base_commit);
>> +oidcpy(>base_commit, >object.oid);
>> +
>> +init_revisions(, NULL);
>> +revs.max_parents = 1;
>> +base->object.flags |= UNINTERESTING;
>> +add_pending_object(, >object, "base");
>> +for (i = 0; i < total; i++) {
>> +list[i]->object.flags |= 0;
>
>What does this statement do, exactly?  Are you clearing some bits
>but not others, and if so which ones?
>
>> +add_pending_object(, [i]->object, "rev_list");
>> +list[i]->util = (void *)1;
>
>Are we sure commit objects not on the list have their ->util cleared?
>The while() loop below seems to rely on that to correctly filter out
>the ones that are on the list.
>
After some investigation and according to my understanding, the commit
object is allocated through alloc_commit_node->alloc_node, 

void *alloc_commit_node(void)
{
struct commit *c = alloc_node(_state, sizeof(struct commit));
c->object.type = OBJ_COMMIT;
c->index = alloc_commit_index();
return c;
}

static inline void *alloc_node(struct alloc_state *s, size_t node_size)
{
void *ret;

if (!s->nr) {
s->nr = BLOCKING;
s->p = xmalloc(BLOCKING * node_size);
}
s->nr--;
s->count++;
ret = s->p;
s->p = (char *)s->p + node_size;
memset(ret, 0, node_size);
return ret;
}

So the commit->util should be cleared after initialization, and it has
not been touched except above "for" loop in our code execution path, I think
it is safe to rely on it to filter out commits that are on the rev list.

Thanks,
Xiaolong.
>> +}
>> +
>> +if (prepare_revision_walk())
>> +die(_("revision walk setup failed"));
>> +/*
>> + * Traverse the prerequisite commits list,
>> + * get the patch ids and stuff them in bases structure.
>> + */
>> +while ((commit = get_revision()) != NULL) {
>> +if (commit->util)
>> +continue;
>> +if (commit_patch_id(commit, , sha1))
>> +die(_("cannot get patch id"));
>> +ALLOC_GROW(bases->patch_id, bases->nr_patch_id + 1, 
>> bases->alloc_patch_id);
>> +patch_id = bases->patch_id + bases->nr_patch_id;
>> +hashcpy(patch_id->hash, sha1);
>

--
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


need customers?

2016-04-09 Thread Jeff Allen

Hey,

Greeting!!

Do you need to increase your sales?
Do you need more clients leads?
Do you need our marketing services?

No matter you are selling products or services, we can generate you new
leads from our marketing service.

If you need more information please contact us today.

Thanks,
Jeff Allen
Contact: xxian...@sina.com

--
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 4/7] l10n: builtin/pull.c: mark strings for translation

2016-04-09 Thread Vasco Almeida
Às 20:33 de 08-04-2016, Junio C Hamano escreveu:
> Vasco Almeida  writes:
> 
>> Some translations might also translate "" and "".
>> ...
>>  fprintf_ln(stderr, _("See git-pull(1) for details."));
>>  fprintf(stderr, "\n");
>> -fprintf_ln(stderr, "git pull  ");
>> +fprintf_ln(stderr, _("git pull  "));
> 
> But "git pull" itself must never be translated, and there is no hint
> given to those who are working on *.po files to prevent it.
> 
> Wouldn't it make more sense to do it like this?
> 
>   fprintf_ln(stderr, "git pull <%s> <%s>", _("remote"), _("branch"));
> 
Yes, I think the way you suggest is better, since it prevents
translation mistakes. I'll do the same to

eval_gettextln "git branch 
--set-upstream-to=\$remote/\$display_branch_name"

in git-parse-remote.sh ending.
--
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 v13 3/6] t0040-parse-options: improve test coverage

2016-04-09 Thread Pranit Bauva
Include tests to check for multiple levels of quiet and to check if the
'--no-quiet' option sets it to 0.

Signed-off-by: Pranit Bauva 
---
 t/t0040-parse-options.sh | 37 +
 1 file changed, 37 insertions(+)

diff --git a/t/t0040-parse-options.sh b/t/t0040-parse-options.sh
index 450da45..c913d1c 100755
--- a/t/t0040-parse-options.sh
+++ b/t/t0040-parse-options.sh
@@ -476,4 +476,41 @@ test_expect_success '--no-list resets list' '
test_cmp expect output
 '
 
+cat >expect <<\EOF
+boolean: 0
+integer: 0
+magnitude: 0
+timestamp: 0
+string: (not set)
+abbrev: 7
+verbose: 0
+quiet: 3
+dry run: no
+file: (not set)
+EOF
+
+test_expect_success 'multiple quiet levels' '
+   test-parse-options -q -q -q >output 2>output.err &&
+   test_must_be_empty output.err &&
+   test_cmp expect output
+'
+
+cat >expect <<\EOF
+boolean: 0
+integer: 0
+magnitude: 0
+timestamp: 0
+string: (not set)
+abbrev: 7
+verbose: 0
+quiet: 0
+dry run: no
+file: (not set)
+EOF
+
+test_expect_success '--no-quiet sets quiet to 0' '
+   test-parse-options --no-quiet >output 2>output.err &&
+   test_must_be_empty output.err &&
+   test_cmp expect output
+'
 test_done

--
https://github.com/git/git/pull/218
--
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 v13 6/6] commit: add a commit.verbose config variable

2016-04-09 Thread Pranit Bauva
Add commit.verbose configuration variable as a convenience for those
who always prefer --verbose.

Helped-by: Junio C Hamano 
Helped-by: Eric Sunshine 
Signed-off-by: Pranit Bauva 

---
The previous version of the patch are:
 - [v12] $gmane/288820
 - [v11] $gmane/288820
 - [v10] $gmane/288820
 - [v9] $gmane/288820
 - [v8] $gmane/288820
 - [v7] $gmane/288820
 - [v6] $gmane/288728
 - [v5] $gmane/288728
 - [v4] $gmane/288652
 - [v3] $gmane/288634
 - [v2] $gmane/288569
 - [v1] $gmane/287540

   Note: One might think some tests are extra but I think that it will
   be better to include them as they "complete the continuity" thus
   generalising the series which will make the patch even more clearer.

Changes wrt v12:
 - Change the setup test as suggested by Eric.
 - Use for loops for systematic testing. I have avoided nested-for loops
   or using a function to test because I believe it will just add to the
   complexity rather than simplifying it. Just by using for loops the
   tests look quite systematic and easy to digest.
---
 Documentation/config.txt |  4 
 Documentation/git-commit.txt |  3 ++-
 builtin/commit.c | 14 ++-
 t/t7507-commit-verbose.sh| 56 
 4 files changed, 75 insertions(+), 2 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 2cd6bdd..1d0ec2e 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1110,6 +1110,10 @@ commit.template::
"`~/`" is expanded to the value of `$HOME` and "`~user/`" to the
specified user's home directory.
 
+commit.verbose::
+   A boolean or int to specify the level of verbose with `git commit`.
+   See linkgit:git-commit[1].
+
 credential.helper::
Specify an external helper to be called when a username or
password credential is needed; the helper may consult external
diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
index 9ec6b3c..d474226 100644
--- a/Documentation/git-commit.txt
+++ b/Documentation/git-commit.txt
@@ -290,7 +290,8 @@ configuration variable documented in linkgit:git-config[1].
what changes the commit has.
Note that this diff output doesn't have its
lines prefixed with '#'. This diff will not be a part
-   of the commit message.
+   of the commit message. See the `commit.verbose` configuration
+   variable in linkgit:git-config[1].
 +
 If specified twice, show in addition the unified diff between
 what would be committed and the worktree files, i.e. the unstaged
diff --git a/builtin/commit.c b/builtin/commit.c
index b3bd2d4..96e6190 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -113,7 +113,9 @@ static char *edit_message, *use_message;
 static char *fixup_message, *squash_message;
 static int all, also, interactive, patch_interactive, only, amend, signoff;
 static int edit_flag = -1; /* unspecified */
-static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship;
+static int config_verbose = -1; /* unspecified */
+static int verbose = -1; /* unspecified */
+static int quiet, no_verify, allow_empty, dry_run, renew_authorship;
 static int no_post_rewrite, allow_empty_message;
 static char *untracked_files_arg, *force_date, *ignore_submodule_arg;
 static char *sign_commit;
@@ -1354,6 +1356,8 @@ int cmd_status(int argc, const char **argv, const char 
*prefix)
 builtin_status_usage, 0);
finalize_colopts(, -1);
finalize_deferred_config();
+   if (verbose == -1)
+   verbose = 0;
 
handle_untracked_files_arg();
if (show_ignored_in_status)
@@ -1505,6 +1509,11 @@ static int git_commit_config(const char *k, const char 
*v, void *cb)
sign_commit = git_config_bool(k, v) ? "" : NULL;
return 0;
}
+   if (!strcmp(k, "commit.verbose")) {
+   int is_bool;
+   config_verbose = git_config_bool_or_int(k, v, _bool);
+   return 0;
+   }
 
status = git_gpg_config(k, v, NULL);
if (status)
@@ -1654,6 +1663,9 @@ int cmd_commit(int argc, const char **argv, const char 
*prefix)
argc = parse_and_validate_options(argc, argv, builtin_commit_options,
  builtin_commit_usage,
  prefix, current_head, );
+   if (verbose == -1)
+   verbose = (config_verbose < 0) ? 0 : config_verbose;
+
if (dry_run)
return dry_run_commit(argc, argv, prefix, current_head, );
index_file = prepare_index(argc, argv, prefix, current_head, 0);
diff --git a/t/t7507-commit-verbose.sh b/t/t7507-commit-verbose.sh
index 0f28a86..00e0c3d 100755
--- a/t/t7507-commit-verbose.sh
+++ b/t/t7507-commit-verbose.sh
@@ -98,4 +98,60 @@ test_expect_success 'verbose diff is stripped out with set 

[PATCH v13 5/6] t7507-commit-verbose: improve test coverage by testing number of diffs

2016-04-09 Thread Pranit Bauva
Make the fake "editor" store output of grep in a file so that we can
see how many diffs were contained in the message and use them in
individual tests where ever it is required. A subsequent commit will
introduce scenarios where it is important to be able to exactly
determine how many diffs were present.

Also use write_script() to create the fake "editor".

The fake "editor" is always made to succeed regardless of whether grep
found diff headers or not so that we don't have to use 'test_must_fail'
for which 'test_line_count = 0' is an easy substitute.

Helped-by: Eric Sunshine 
Signed-off-by: Pranit Bauva 

---
Previous version of this patch:
 - [v12] : $gmane/288820
 - [v11] : $gmane/288820
 - [v10]: $gmane/288820

Changes this version wrt previous one:
Change the commit message as suggested by Eric
---
 t/t7507-commit-verbose.sh | 16 +---
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/t/t7507-commit-verbose.sh b/t/t7507-commit-verbose.sh
index 2ddf28c..0f28a86 100755
--- a/t/t7507-commit-verbose.sh
+++ b/t/t7507-commit-verbose.sh
@@ -3,11 +3,10 @@
 test_description='verbose commit template'
 . ./test-lib.sh
 
-cat >check-for-diff message <<'EOF'
@@ -23,7 +22,8 @@ test_expect_success 'setup' '
 '
 
 test_expect_success 'initial commit shows verbose diff' '
-   git commit --amend -v
+   git commit --amend -v &&
+   test_line_count = 1 out
 '
 
 test_expect_success 'second commit' '
@@ -39,13 +39,15 @@ check_message() {
 
 test_expect_success 'verbose diff is stripped out' '
git commit --amend -v &&
-   check_message message
+   check_message message &&
+   test_line_count = 1 out
 '
 
 test_expect_success 'verbose diff is stripped out (mnemonicprefix)' '
git config diff.mnemonicprefix true &&
git commit --amend -v &&
-   check_message message
+   check_message message &&
+   test_line_count = 1 out
 '
 
 cat >diff <<'EOF'

--
https://github.com/git/git/pull/218
--
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 v13 4/6] parse-options.c: make OPTION_COUNTUP respect "unspecified" values

2016-04-09 Thread Pranit Bauva
OPT_COUNTUP() merely increments the counter upon --option, and resets it
to 0 upon --no-option, which means that there is no "unspecified" value
with which a client can initialize the counter to determine whether or
not --[no]-option was seen at all.

Make OPT_COUNTUP() treat any negative number as an "unspecified" value
to address this shortcoming. In particular, if a client initializes the
counter to -1, then if it is still -1 after parse_options(), then
neither --option nor --no-option was seen; If it is 0, then --no-option
was seen last, and if it is 1 or greater, than --option was seen last.

This change does not affect the behavior of existing clients because
they all use the initial value of 0 (or more).

Note that builtin/clean.c initializes the variable used with
OPT__FORCE (which uses OPT_COUNTUP()) to a negative value, but it is set
to either 0 or 1 by reading the configuration before the code calls
parse_options(), i.e. as far as parse_options() is concerned, the
initial value of the variable is not negative.

To test this behavior, in test-parse-options.c, "verbose" is set to
"unspecified" while quiet is set to 0 which will test the new behavior
with all sets of values.

Helped-by: Jeff King 
Helped-by: Eric Sunshine 
Helped-by: Junio C Hamano 
Signed-off-by: Pranit Bauva 

---
The discussion about this patch:
[1] : http://thread.gmane.org/gmane.comp.version-control.git/289027

Previous version of the patch:
[v11] : http://thread.gmane.org/gmane.comp.version-control.git/288820
[v10] : http://thread.gmane.org/gmane.comp.version-control.git/288820
[v9] : http://thread.gmane.org/gmane.comp.version-control.git/288820
[v1] : http://thread.gmane.org/gmane.comp.version-control.git/289061

Changes wrt previous version (v12):
 - Use bits of commit message provided by Eric Sunshine.

Please Note: The diff might seem improper especially the part where I
have introduced some continuous lines but this is a logical error by git
diff (nothing could be done about it) and thus the changes will be
clearly visible with the original file itself.
---
 Documentation/technical/api-parse-options.txt |  8 --
 parse-options.c   |  2 ++
 t/t0040-parse-options.sh  | 39 ---
 test-parse-options.c  |  3 ++-
 4 files changed, 39 insertions(+), 13 deletions(-)

diff --git a/Documentation/technical/api-parse-options.txt 
b/Documentation/technical/api-parse-options.txt
index 5f0757d..8908bf7 100644
--- a/Documentation/technical/api-parse-options.txt
+++ b/Documentation/technical/api-parse-options.txt
@@ -144,8 +144,12 @@ There are some macros to easily define options:
 
 `OPT_COUNTUP(short, long, _var, description)`::
Introduce a count-up option.
-   `int_var` is incremented on each use of `--option`, and
-   reset to zero with `--no-option`.
+   Each use of `--option` increments `int_var`, starting from zero
+   (even if initially negative), and `--no-option` resets it to
+   zero. To determine if `--option` or `--no-option` was set at
+   all, set `int_var` to a negative value, and if it is still
+   negative after parse_options(), then neither `--option` nor
+   `--no-option` was seen.
 
 `OPT_BIT(short, long, _var, description, mask)`::
Introduce a boolean option.
diff --git a/parse-options.c b/parse-options.c
index 47a9192..312a85d 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -110,6 +110,8 @@ static int get_value(struct parse_opt_ctx_t *p,
return 0;
 
case OPTION_COUNTUP:
+   if (*(int *)opt->value < 0)
+   *(int *)opt->value = 0;
*(int *)opt->value = unset ? 0 : *(int *)opt->value + 1;
return 0;
 
diff --git a/t/t0040-parse-options.sh b/t/t0040-parse-options.sh
index c913d1c..efcd844 100755
--- a/t/t0040-parse-options.sh
+++ b/t/t0040-parse-options.sh
@@ -63,7 +63,7 @@ magnitude: 0
 timestamp: 0
 string: (not set)
 abbrev: 7
-verbose: 0
+verbose: -1
 quiet: 0
 dry run: no
 file: (not set)
@@ -211,7 +211,7 @@ magnitude: 0
 timestamp: 0
 string: 123
 abbrev: 7
-verbose: 0
+verbose: -1
 quiet: 0
 dry run: no
 file: (not set)
@@ -234,7 +234,7 @@ magnitude: 0
 timestamp: 0
 string: (not set)
 abbrev: 7
-verbose: 0
+verbose: -1
 quiet: 0
 dry run: no
 file: (not set)
@@ -263,7 +263,7 @@ magnitude: 0
 timestamp: 0
 string: 123
 abbrev: 7
-verbose: 0
+verbose: -1
 quiet: 0
 dry run: no
 file: (not set)
@@ -302,7 +302,7 @@ magnitude: 0
 timestamp: 0
 string: (not set)
 abbrev: 7
-verbose: 0
+verbose: -1
 quiet: 0
 dry run: no
 file: (not set)
@@ -322,7 +322,7 @@ magnitude: 0
 timestamp: 1
 string: (not set)
 abbrev: 7
-verbose: 0
+verbose: -1
 quiet: 1
 dry run: no
 file: (not set)
@@ -344,7 +344,7 @@ magnitude: 0
 timestamp: 0
 string: (not set)
 abbrev: 7
-verbose: 0
+verbose: -1
 quiet: 0
 dry run: no
 

[PATCH v13 2/6] test-parse-options: print quiet as integer

2016-04-09 Thread Pranit Bauva
Current implementation of parse-options.c treats OPT__QUIET() as integer
and not boolean and thus it is more appropriate to print it as integer
to avoid confusion.

Signed-off-by: Pranit Bauva 
---
 t/t0040-parse-options.sh | 26 +-
 test-parse-options.c |  2 +-
 2 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/t/t0040-parse-options.sh b/t/t0040-parse-options.sh
index 477fcff..450da45 100755
--- a/t/t0040-parse-options.sh
+++ b/t/t0040-parse-options.sh
@@ -64,7 +64,7 @@ timestamp: 0
 string: (not set)
 abbrev: 7
 verbose: 0
-quiet: no
+quiet: 0
 dry run: no
 file: (not set)
 EOF
@@ -164,7 +164,7 @@ timestamp: 0
 string: 123
 abbrev: 7
 verbose: 2
-quiet: no
+quiet: 0
 dry run: yes
 file: prefix/my.file
 EOF
@@ -184,7 +184,7 @@ timestamp: 0
 string: 321
 abbrev: 10
 verbose: 2
-quiet: no
+quiet: 0
 dry run: no
 file: prefix/fi.le
 EOF
@@ -212,7 +212,7 @@ timestamp: 0
 string: 123
 abbrev: 7
 verbose: 0
-quiet: no
+quiet: 0
 dry run: no
 file: (not set)
 arg 00: a1
@@ -235,7 +235,7 @@ timestamp: 0
 string: (not set)
 abbrev: 7
 verbose: 0
-quiet: no
+quiet: 0
 dry run: no
 file: (not set)
 EOF
@@ -264,7 +264,7 @@ timestamp: 0
 string: 123
 abbrev: 7
 verbose: 0
-quiet: no
+quiet: 0
 dry run: no
 file: (not set)
 EOF
@@ -303,7 +303,7 @@ timestamp: 0
 string: (not set)
 abbrev: 7
 verbose: 0
-quiet: no
+quiet: 0
 dry run: no
 file: (not set)
 arg 00: --quux
@@ -323,7 +323,7 @@ timestamp: 1
 string: (not set)
 abbrev: 7
 verbose: 0
-quiet: yes
+quiet: 1
 dry run: no
 file: (not set)
 arg 00: foo
@@ -345,7 +345,7 @@ timestamp: 0
 string: (not set)
 abbrev: 7
 verbose: 0
-quiet: no
+quiet: 0
 dry run: no
 file: (not set)
 EOF
@@ -374,7 +374,7 @@ timestamp: 0
 string: (not set)
 abbrev: 7
 verbose: 0
-quiet: no
+quiet: 0
 dry run: no
 file: (not set)
 EOF
@@ -399,7 +399,7 @@ timestamp: 0
 string: (not set)
 abbrev: 7
 verbose: 0
-quiet: no
+quiet: 0
 dry run: no
 file: (not set)
 EOF
@@ -430,7 +430,7 @@ timestamp: 0
 string: (not set)
 abbrev: 7
 verbose: 0
-quiet: no
+quiet: 0
 dry run: no
 file: (not set)
 EOF
@@ -449,7 +449,7 @@ timestamp: 0
 string: (not set)
 abbrev: 7
 verbose: 0
-quiet: no
+quiet: 0
 dry run: no
 file: (not set)
 EOF
diff --git a/test-parse-options.c b/test-parse-options.c
index 2c8c8f1..86afa98 100644
--- a/test-parse-options.c
+++ b/test-parse-options.c
@@ -90,7 +90,7 @@ int main(int argc, char **argv)
printf("string: %s\n", string ? string : "(not set)");
printf("abbrev: %d\n", abbrev);
printf("verbose: %d\n", verbose);
-   printf("quiet: %s\n", quiet ? "yes" : "no");
+   printf("quiet: %d\n", quiet);
printf("dry run: %s\n", dry_run ? "yes" : "no");
printf("file: %s\n", file ? file : "(not set)");
 

--
https://github.com/git/git/pull/218
--
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 v13 1/6] t0040-test-parse-options.sh: fix style issues

2016-04-09 Thread Pranit Bauva
Signed-off-by: Pranit Bauva 

---
Changes wrt previous version (v12):
 - Use '\' when interpolation isn't required
---
 t/t0040-parse-options.sh | 76 
 1 file changed, 38 insertions(+), 38 deletions(-)

diff --git a/t/t0040-parse-options.sh b/t/t0040-parse-options.sh
index 9be6411..477fcff 100755
--- a/t/t0040-parse-options.sh
+++ b/t/t0040-parse-options.sh
@@ -7,7 +7,7 @@ test_description='our own option parser'
 
 . ./test-lib.sh
 
-cat > expect << EOF
+cat >expect <<\EOF
 usage: test-parse-options 
 
 --yes get a boolean
@@ -49,14 +49,14 @@ Standard options
 EOF
 
 test_expect_success 'test help' '
-   test_must_fail test-parse-options -h > output 2> output.err &&
+   test_must_fail test-parse-options -h >output 2>output.err &&
test_must_be_empty output.err &&
test_i18ncmp expect output
 '
 
 mv expect expect.err
 
-cat >expect.template  expect << EOF
+cat >expect <<\EOF
 boolean: 2
 integer: 1729
 magnitude: 16384
@@ -176,7 +176,7 @@ test_expect_success 'short options' '
test_must_be_empty output.err
 '
 
-cat > expect << EOF
+cat >expect <<\EOF
 boolean: 2
 integer: 1729
 magnitude: 16384
@@ -204,7 +204,7 @@ test_expect_success 'missing required value' '
test_expect_code 129 test-parse-options --file
 '
 
-cat > expect << EOF
+cat >expect <<\EOF
 boolean: 1
 integer: 13
 magnitude: 0
@@ -222,12 +222,12 @@ EOF
 
 test_expect_success 'intermingled arguments' '
test-parse-options a1 --string 123 b1 --boolean -j 13 -- --boolean \
-   > output 2> output.err &&
+   >output 2>output.err &&
test_must_be_empty output.err &&
test_cmp expect output
 '
 
-cat > expect << EOF
+cat >expect <<\EOF
 boolean: 0
 integer: 2
 magnitude: 0
@@ -241,13 +241,13 @@ file: (not set)
 EOF
 
 test_expect_success 'unambiguously abbreviated option' '
-   test-parse-options --int 2 --boolean --no-bo > output 2> output.err &&
+   test-parse-options --int 2 --boolean --no-bo >output 2>output.err &&
test_must_be_empty output.err &&
test_cmp expect output
 '
 
 test_expect_success 'unambiguously abbreviated option with "="' '
-   test-parse-options --int=2 > output 2> output.err &&
+   test-parse-options --int=2 >output 2>output.err &&
test_must_be_empty output.err &&
test_cmp expect output
 '
@@ -256,7 +256,7 @@ test_expect_success 'ambiguously abbreviated option' '
test_expect_code 129 test-parse-options --strin 123
 '
 
-cat > expect << EOF
+cat >expect <<\EOF
 boolean: 0
 integer: 0
 magnitude: 0
@@ -270,32 +270,32 @@ file: (not set)
 EOF
 
 test_expect_success 'non ambiguous option (after two options it abbreviates)' '
-   test-parse-options --st 123 > output 2> output.err &&
+   test-parse-options --st 123 >output 2>output.err &&
test_must_be_empty output.err &&
test_cmp expect output
 '
 
-cat > typo.err << EOF
-error: did you mean \`--boolean\` (with two dashes ?)
+cat >typo.err <<\EOF
+error: did you mean `--boolean` (with two dashes ?)
 EOF
 
 test_expect_success 'detect possible typos' '
-   test_must_fail test-parse-options -boolean > output 2> output.err &&
+   test_must_fail test-parse-options -boolean >output 2>output.err &&
test_must_be_empty output &&
test_cmp typo.err output.err
 '
 
-cat > typo.err << EOF
-error: did you mean \`--ambiguous\` (with two dashes ?)
+cat >typo.err <<\EOF
+error: did you mean `--ambiguous` (with two dashes ?)
 EOF
 
 test_expect_success 'detect possible typos' '
-   test_must_fail test-parse-options -ambiguous > output 2> output.err &&
+   test_must_fail test-parse-options -ambiguous >output 2>output.err &&
test_must_be_empty output &&
test_cmp typo.err output.err
 '
 
-cat > expect  output 2> output.err &&
+   test-parse-options --quux >output 2>output.err &&
test_must_be_empty output.err &&
-test_cmp expect output
+   test_cmp expect output
 '
 
-cat > expect  output 2> output.err &&
+   foo -q >output 2>output.err &&
test_must_be_empty output.err &&
test_cmp expect output
 '
 
-cat > expect 

Re: [PATCH 2/7] l10n: unpack-trees: mark strings for translation

2016-04-09 Thread Vasco Almeida
Às 20:23 de 08-04-2016, Junio C Hamano escreveu:
> Vasco Almeida  writes:
> 
>> Mark strings seen by the user inside setup_unpack_trees_porcelain() and
>> display_error_msgs() functions for translation.
>>
>> One case Git outputs the named strings is when the user does some editing to
>> a file on some branch and then checks out other branch, but that file
>> changes by the checkout. This is the case of the first string marked.
> 
> The second paragraph puzzling.  Other strings are not shown at all?
> Or is it just you didn't bother explaining the others cases?
> 
> Either case, it is not immediately clear why you felt that one
> string among others deserve more attention.  Care to elaborate?

I meant that as an example, which was the situation I was when I found
the untranslated string.
I should have written that outside the commit message, as a note.
I'm going to remove that paragraph since it isn’t irrelevant and
confusing. Hope I answered you.

> 
> In the patch itself I did not find anything questionable, though.
> 
> Thanks.
> 
>>
>> Signed-off-by: Vasco Almeida 
>> ---
>>  unpack-trees.c | 24 
>>  1 file changed, 12 insertions(+), 12 deletions(-)
>>
>> diff --git a/unpack-trees.c b/unpack-trees.c
>> index 9f55cc2..4bc6b4f 100644
>> --- a/unpack-trees.c
>> +++ b/unpack-trees.c
>> @@ -61,21 +61,21 @@ void setup_unpack_trees_porcelain(struct 
>> unpack_trees_options *opts,
>>  const char *cmd2 = strcmp(cmd, "checkout") ? cmd : "switch branches";
>>  
>>  if (advice_commit_before_merge)
>> -msg = "Your local changes to the following files would be 
>> overwritten by %s:\n%%s"
>> -"Please, commit your changes or stash them before you 
>> can %s.";
>> +msg = _("Your local changes to the following files would be 
>> overwritten by %s:\n%%s"
>> +"Please, commit your changes or stash them before you 
>> can %s.");
>>  else
>> -msg = "Your local changes to the following files would be 
>> overwritten by %s:\n%%s";
>> +msg = _("Your local changes to the following files would be 
>> overwritten by %s:\n%%s");
>>  msgs[ERROR_WOULD_OVERWRITE] = msgs[ERROR_NOT_UPTODATE_FILE] =
>>  xstrfmt(msg, cmd, cmd2);
>>  
>>  msgs[ERROR_NOT_UPTODATE_DIR] =
>> -"Updating the following directories would lose untracked files 
>> in it:\n%s";
>> +_("Updating the following directories would lose untracked 
>> files in it:\n%s");
>>  
>>  if (advice_commit_before_merge)
>> -msg = "The following untracked working tree files would be %s 
>> by %s:\n%%s"
>> -"Please move or remove them before you can %s.";
>> +msg = _("The following untracked working tree files would be %s 
>> by %s:\n%%s"
>> +"Please move or remove them before you can %s.");
>>  else
>> -msg = "The following untracked working tree files would be %s 
>> by %s:\n%%s";
>> +msg = _("The following untracked working tree files would be %s 
>> by %s:\n%%s");
>>  
>>  msgs[ERROR_WOULD_LOSE_UNTRACKED_REMOVED] = xstrfmt(msg, "removed", cmd, 
>> cmd2);
>>  msgs[ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN] = xstrfmt(msg, 
>> "overwritten", cmd, cmd2);
>> @@ -84,14 +84,14 @@ void setup_unpack_trees_porcelain(struct 
>> unpack_trees_options *opts,
>>   * Special case: ERROR_BIND_OVERLAP refers to a pair of paths, we
>>   * cannot easily display it as a list.
>>   */
>> -msgs[ERROR_BIND_OVERLAP] = "Entry '%s' overlaps with '%s'.  Cannot 
>> bind.";
>> +msgs[ERROR_BIND_OVERLAP] = _("Entry '%s' overlaps with '%s'.  Cannot 
>> bind.");
>>  
>>  msgs[ERROR_SPARSE_NOT_UPTODATE_FILE] =
>> -"Cannot update sparse checkout: the following entries are not 
>> up-to-date:\n%s";
>> +_("Cannot update sparse checkout: the following entries are not 
>> up-to-date:\n%s");
>>  msgs[ERROR_WOULD_LOSE_ORPHANED_OVERWRITTEN] =
>> -"The following Working tree files would be overwritten by 
>> sparse checkout update:\n%s";
>> +_("The following Working tree files would be overwritten by 
>> sparse checkout update:\n%s");
>>  msgs[ERROR_WOULD_LOSE_ORPHANED_REMOVED] =
>> -"The following Working tree files would be removed by sparse 
>> checkout update:\n%s";
>> +_("The following Working tree files would be removed by sparse 
>> checkout update:\n%s");
>>  
>>  opts->show_all_errors = 1;
>>  /* rejected paths may not have a static buffer */
>> @@ -168,7 +168,7 @@ static void display_error_msgs(struct 
>> unpack_trees_options *o)
>>  string_list_clear(rejects, 0);
>>  }
>>  if (something_displayed)
>> -fprintf(stderr, "Aborting\n");
>> +fprintf(stderr, _("Aborting\n"));
>>  }
>>  
>>  /*
--
To unsubscribe from this list: send the line "unsubscribe 

Re: git 2.8.1 not working with socks5h https proxy anymore

2016-04-09 Thread Felix Ruess
Thanks a lot!
Tested the patch and it works as expected :-)

On Fri, Apr 8, 2016 at 9:16 PM, Junio C Hamano  wrote:
> Felix Ruess  writes:
>
>> I just encountered a problem with the latest git version (2.8.1) that
>> looks like a regression to me:
>> When trying to clone a repo via a https socks5 proxy the connection times 
>> out:
>>
>> $ git config --global 'http.proxy=socks5h://127.0.0.1:1080'
>
> The first version of Git that has code that explicitly supports
> socks proxy is 2.6.4, it seems.  Since then we have always used
> CURLPROXY_SOCKS5 for curl_http_proxy that begins with a string
> "socks5".
>
> Checking
>
> https://github.com/curl/curl/blob/master/docs/libcurl/symbols-in-versions
>
> I find that that at curl 7.18.0, curl added a separate
> CURLPROXY_SOCKS5_HOSTNAME that can be triggered by "socks5h:" that
> is separate from CURLPROXY_SOCKS5, and I am guessing that the
> differences in behaviour between these two is what is causing you
> trouble.  https://curl.haxx.se/libcurl/c/CURLOPT_PROXY.html says
>
>   ..., socks5h:// (the last one to enable socks5 and asking the proxy
>   to do the resolving, also known as CURLPROXY_SOCKS5_HOSTNAME type)
>
> and because not using _HOSTNAME variant would likely not ask the
> proxy to do the resolving, it explains the stall on your end, if
> your box cannot resolve external hostname.
>
> Perhaps the attached patch may help?
>
> I do not know if Pat is still active as a developer, but I am
> wondering what the reason was to use starts_with(..., "socks5")
> instead of "socks5:", "socks4a:", etc. when identifying the proxy
> type.
>
>  http.c | 5 -
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/http.c b/http.c
> index 69da445..4304b80 100644
> --- a/http.c
> +++ b/http.c
> @@ -605,7 +605,10 @@ static CURL *get_curl_handle(void)
> if (curl_http_proxy) {
> curl_easy_setopt(result, CURLOPT_PROXY, curl_http_proxy);
>  #if LIBCURL_VERSION_NUM >= 0x071800
> -   if (starts_with(curl_http_proxy, "socks5"))
> +   if (starts_with(curl_http_proxy, "socks5h"))
> +   curl_easy_setopt(result,
> +   CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5_HOSTNAME);
> +   else if (starts_with(curl_http_proxy, "socks5"))
> curl_easy_setopt(result,
> CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
> else if (starts_with(curl_http_proxy, "socks4a"))
--
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] rewrite t1500-rev-parse.sh

2016-04-09 Thread Michael Rappazzo
I was working on a simple bug fix[1], and I wanted to add a test to t1500.  I 
put
the new test at the beginning rather than try to decipher what state the test 
run
would be in at the end. In the review, Eric Sunshine described the test:

> this script is ancient and cd's all around the place with wild abandon and
> leaks environment variables

I decided to rewrite this test in (what I hope is) the modern test format.  In
doing so, I expanded the size of the test file greatly, but I think it is much
clearer to read and understand as you go through it.  This also has the 
advantage
of allowing a tester to use verbose options when testing.  As noted in the 
commit
comment, tests which compare text (rather than booleans) were also adjusted to 
use
the test_cmp function.

This patch is based on 'pu' because of a feature to add `--absolute-git-dir` to
rev-parse[2].

I considered including this patch as the first commit in the aforementioned bug
fix, but I wanted to get it out for review to make sure that it is acceptible.


[1]http://thread.gmane.org/gmane.comp.version-control.git/290669
[2]http://article.gmane.org/gmane.comp.version-control.git/287462

Michael Rappazzo (1):
  t1500-rev-parse: rewrite each test to run in isolation

 t/t1500-rev-parse.sh | 607 +--
 1 file changed, 545 insertions(+), 62 deletions(-)

-- 
2.8.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] t1500-rev-parse: rewrite each test to run in isolation

2016-04-09 Thread Michael Rappazzo
t1500-rev-parse has many tests which change directories and leak
environment variables.  This makes it difficult to add new tests without
minding the environment variables and current directory.

Each test is now setup, executed, and cleaned up without leaving anything
behind.  Tests which have textual expectations have been converted to use
test_cmp (which will show a diff when the test is run with --verbose).

Signed-off-by: Michael Rappazzo 
---
 t/t1500-rev-parse.sh | 607 +--
 1 file changed, 545 insertions(+), 62 deletions(-)

diff --git a/t/t1500-rev-parse.sh b/t/t1500-rev-parse.sh
index 617fcd8..dffa9f3 100755
--- a/t/t1500-rev-parse.sh
+++ b/t/t1500-rev-parse.sh
@@ -3,88 +3,571 @@
 test_description='test git rev-parse'
 . ./test-lib.sh
 
-test_rev_parse() {
-   name=$1
-   shift
+test_expect_success 'toplevel: is-bare-repository' '
+   test false = "$(git rev-parse --is-bare-repository)"
+'
 
-   test_expect_success "$name: is-bare-repository" \
-   "test '$1' = \"\$(git rev-parse --is-bare-repository)\""
-   shift
-   [ $# -eq 0 ] && return
+test_expect_success 'toplevel: is-inside-git-dir' '
+   test false = "$(git rev-parse --is-inside-git-dir)"
+'
 
-   test_expect_success "$name: is-inside-git-dir" \
-   "test '$1' = \"\$(git rev-parse --is-inside-git-dir)\""
-   shift
-   [ $# -eq 0 ] && return
+test_expect_success 'toplevel: is-inside-work-tree' '
+   test true = "$(git rev-parse --is-inside-work-tree)"
+'
 
-   test_expect_success "$name: is-inside-work-tree" \
-   "test '$1' = \"\$(git rev-parse --is-inside-work-tree)\""
-   shift
-   [ $# -eq 0 ] && return
+test_expect_success 'toplevel: prefix' '
+   echo >expected &&
+   git rev-parse --show-prefix >actual &&
+   test_cmp expected actual
+'
 
-   test_expect_success "$name: prefix" \
-   "test '$1' = \"\$(git rev-parse --show-prefix)\""
-   shift
-   [ $# -eq 0 ] && return
+test_expect_success 'toplevel: git-dir' '
+   echo .git >expected &&
+   git rev-parse --git-dir >actual &&
+   test_cmp expected actual
+'
 
-   test_expect_success "$name: git-dir" \
-   "test '$1' = \"\$(git rev-parse --git-dir)\""
-   shift
-   [ $# -eq 0 ] && return
+test_expect_success 'toplevel: absolute-git-dir' '
+   echo "$(pwd)/.git" >expected &&
+   git rev-parse --absolute-git-dir >actual &&
+   test_cmp expected actual
+'
 
-   test_expect_success "$name: absolute-git-dir" \
-   "verbose test '$1' = \"\$(git rev-parse --absolute-git-dir)\""
-}
+test_expect_success '.git/: is-bare-repository' '
+   (cd .git && test false = "$(git rev-parse --is-bare-repository)")
+'
 
-# label is-bare is-inside-git is-inside-work prefix git-dir absolute-git-dir
+test_expect_success '.git/: is-inside-git-dir' '
+   (cd .git && test true = "$(git rev-parse --is-inside-git-dir)")
+'
 
-ROOT=$(pwd)
+test_expect_success '.git/: is-inside-work-tree' '
+   (cd .git && test false = "$(git rev-parse --is-inside-work-tree)")
+'
 
-test_rev_parse toplevel false false true '' .git "$ROOT/.git"
+test_expect_success '.git/: prefix' '
+   (
+   cd .git &&
+   echo >expected &&
+   git rev-parse --show-prefix >actual &&
+   test_cmp expected actual
+   )
+'
 
-cd .git || exit 1
-test_rev_parse .git/ false true false '' . "$ROOT/.git"
-cd objects || exit 1
-test_rev_parse .git/objects/ false true false '' "$ROOT/.git" "$ROOT/.git"
-cd ../.. || exit 1
+test_expect_success '.git/: git-dir' '
+   (
+   cd .git &&
+   echo . >expected &&
+   git rev-parse --git-dir >actual &&
+   test_cmp expected actual
+   )
+'
 
-mkdir -p sub/dir || exit 1
-cd sub/dir || exit 1
-test_rev_parse subdirectory false false true sub/dir/ "$ROOT/.git" "$ROOT/.git"
-cd ../.. || exit 1
+test_expect_success '.git/: absolute-git-dir' '
+   (
+   ROOT=$(pwd) &&
+   cd .git &&
+   echo "$ROOT/.git" >expected &&
+   git rev-parse --absolute-git-dir >actual &&
+   test_cmp expected actual
+   )
+'
 
-git config core.bare true
-test_rev_parse 'core.bare = true' true false false
+test_expect_success '.git/objects/: is-bare-repository' '
+   (cd .git/objects && test false = "$(git rev-parse 
--is-bare-repository)")
+'
 
-git config --unset core.bare
-test_rev_parse 'core.bare undefined' false false true
+test_expect_success '.git/objects/: is-inside-git-dir' '
+   (cd .git/objects && test true = "$(git rev-parse --is-inside-git-dir)")
+'
 
-mkdir work || exit 1
-cd work || exit 1
-GIT_DIR=../.git
-GIT_CONFIG="$(pwd)"/../.git/config
-export GIT_DIR GIT_CONFIG
+test_expect_success '.git/objects/: is-inside-work-tree' '
+   (cd .git/objects && test false = "$(git rev-parse 
--is-inside-work-tree)")
+'
 
-git config 

Re: git segfaults on older Solaris releases

2016-04-09 Thread Tom G. Christensen

On 07/04/16 22:19, Tom G. Christensen wrote:

On 07/04/16 20:50, Junio C Hamano wrote:

Junio C Hamano  writes:
So perhaps this is all we need to fix your box.

  setup.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)



I applied this patch to 2.8.0 and have completed a testsuite run on
Solaris 2.6/x86 with only a few unrelated problems.
I will continue testing on the other Solaris < 10 releases but I do not
expect any difference in the outcome.



I've finished testing 2.8.1 and I found one more case where a null is 
being printed and causing a segfault. This happens even on Solaris 8 and 9.

The failling test is t3200.63.

Here is the backtrace from a Solaris 8/SPARC machine:

(gdb) core trash directory.t3200-branch/core
[New LWP 1]
[Thread debugging using libthread_db enabled]
[New Thread 1 (LWP 1)]
Core was generated by `/export/home/tgc/buildpkg/git/src/git-2.8.1/git 
branch --unset-upstream'.

Program terminated with signal SIGSEGV, Segmentation fault.
#0  0xfecb32cc in strlen () from /usr/lib/libc.so.1
(gdb) bt
#0  0xfecb32cc in strlen () from /usr/lib/libc.so.1
#1  0xfed06508 in _doprnt () from /usr/lib/libc.so.1
#2  0xfed08690 in vfprintf () from /usr/lib/libc.so.1
#3  0x001487bc in vreportf (prefix=, err=, 
params=0xffbfe408) at usage.c:23
#4  0x0014881c in die_builtin (err=0x198f90 "Could not set '%s' to 
'%s'", params=0xffbfe408) at usage.c:35
#5  0x00148934 in die (err=0x198f90 "Could not set '%s' to '%s'") at 
usage.c:108
#6  0x000af1b0 in git_config_set_multivar_in_file (value=0x0, 
key=0x1ecca0 "branch.master.remote",
config_filename=, value_regex=, 
multi_replace=) at config.c:2226
#7  git_config_set_multivar_in_file (config_filename=0x0, key=0x1ecca0 
"branch.master.remote", value=0x0,

value_regex=0x0, multi_replace=1) at config.c:2220
#8  0x0003aa6c in cmd_branch (argc=0, argv=0xffbfec00, prefix=out>) at builtin/branch.c:793
#9  0x000255e8 in run_builtin (argv=0xffbfec00, argc=2, p=0x1c365c 
) at git.c:353

#10 handle_builtin (argc=2, argv=0xffbfec00) at git.c:540
#11 0x00168ecc in run_argv (argv=0xffbfeb30, argcp=0xffbfebdc) at git.c:594
#12 main (argc=2, av=) at git.c:701
(gdb)


-tgc
--
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] builtin/log.c: fixup format-patch --base segfault

2016-04-09 Thread Ye Xiaolong
On Sun, Apr 03, 2016 at 02:19:53AM +0100, Ramsay Jones wrote:
>
>Signed-off-by: Ramsay Jones 
>---
>
>Hi Xiaolong,
>
>When you next re-roll your 'xy/format-patch-base' branch could you
>please squash this (or something like it) into the relevant patch.
>(commit 50ff6afd, "format-patch: add '--base' option to record base
>tree info", 31-03-2016).
>
>The pu branch, for me, fails a shed load of tests in the following:
>
>t3301-notes.sh
>t3901-i18n-patch.sh
>t4014-format-patch.sh
>t4021-format-patch-numbered.sh
>t4028-format-patch-mime-headers.sh
>t4030-diff-textconv.sh
>t4036-format-patch-signer-mime.sh
>t4052-stat-output.sh
>t4122-apply-symlink-inside.sh
>t4150-am.sh
>t4151-am-abort.sh
>t4152-am-subjects.sh
>t4255-am-submodule.sh
>t7400-submodule-basic.sh
>t7512-status-help.sh
>t9001-send-email.sh
>
>Looking at the first failure, the cause was a segfault while running
>git-format-patch. A quick trip to the debugger showed that the segfault
>was in print_bases(). Furthermore, the contents of the bases structure
>passed in looked very dodgy (bases->nr_patch_id was 32767 and 
>bases->patch_id[0]
>was 0xc). Indeed, it looked like it had not been initialized ...
>
>[NOTE: t6038-merge-text-auto.sh also fails for me, but it has nothing
>to do with your patch series. ;-)]
>
>This patch was just a quick fix, you may chose a different approach to
>fix the problem (eg don't call print_bases() unconditionally ...).

Thanks for the report, I will squash this to avoid segfault.

Best Regards,
Xiaolong.
>
>ATB,
>Ramsay Jones
>
> builtin/log.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/builtin/log.c b/builtin/log.c
>index 48c74f5..fed0f99 100644
>--- a/builtin/log.c
>+++ b/builtin/log.c
>@@ -1625,8 +1625,8 @@ int cmd_format_patch(int argc, const char **argv, const 
>char *prefix)
>   signature = strbuf_detach(, NULL);
>   }
> 
>+  memset(, 0, sizeof(bases));
>   if (base_commit || config_base_commit) {
>-  memset(, 0, sizeof(bases));
>   reset_revision_walk();
>   prepare_bases(, base_commit, list, nr);
>   }
>-- 
>2.8.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] Fixed grammar mistake in the french localization

2016-04-09 Thread Antonin
"tous le dépôts distants" -> "tous les dépôts distants"
---
 po/fr.po | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/po/fr.po b/po/fr.po
index 88b0b8a7..36c7c99 100644
--- a/po/fr.po
+++ b/po/fr.po
@@ -6135,7 +6135,7 @@ msgstr "git fetch --all []"
 
 #: builtin/fetch.c:92 builtin/pull.c:166
 msgid "fetch from all remotes"
-msgstr "récupérer depuis tous le dépôts distants"
+msgstr "récupérer depuis tous les dépôts distants"
 
 #: builtin/fetch.c:94 builtin/pull.c:169
 msgid "append to .git/FETCH_HEAD instead of overwriting"

--
https://github.com/git/git/pull/221
--
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 0/2] imap-send: fixes for CRAM-MD5 authentication

2016-04-09 Thread Hitoshi Mitake
At Fri, 8 Apr 2016 23:02:18 +0900,
Kazuki Yamaguchi wrote:
> 
> [1/2]
> Check for LOGINDISABLED capability only when using LOGIN command, as it
> is unrelated to authentication with CRAM-MD5.
> 
> [2/2]
> Remove extra + 1, which is probably mistakenly added. Without this patch
> I can't open my IMAP server (Dovecot 2.2).
> 
> Thanks,
> 
> Kazuki Yamaguchi (2):
>   imap-send: check for NOLOGIN capability only when using LOGIN command
>   imap-send: fix CRAM-MD5 response calculation
> 
>  imap-send.c | 12 ++--
>  1 file changed, 6 insertions(+), 6 deletions(-)

Yamaguchi-san, thanks for your patches and letting me know. The
CRAM-MD5 feature would have problems as you pointed. I just
implemented it for my own usecase years ago (at that time I used
Cyrus) and am not using it for now. The code is old but not tested
well yet (I'm not sure how many people are using it).

Unfortunately I can't test the patches because I don't have an IMAP
server that is suitable for testing. But I think the patches are worth
to apply because they are valuable for your usecase. Sorry for my
irresponible answer :(

--
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