Re: [PATCH v3] status: always show tracking branch even no change

2013-08-12 Thread Junio C Hamano
Jiang Xin worldhello@gmail.com writes:

 2013/8/10 Junio C Hamano gits...@pobox.com:
 Jiang Xin worldhello@gmail.com writes:

 So always show the remote tracking branch in the output of git status
 and other commands will help users to see where the current branch
 will push to and pull from. E.g.
 ...

 Hmmph.

 I do not know if this will help any case you described above, even
 though this might help some other cases.  The added output is to
 always show the current branch and its upstream, but the thing is,
 the original issue in $gmane/198703 was *not* that the current
 branch was pushed and up to date.  It was that there was no current
 branch to be pushed.  The same thing would happen if you are on a
 local branch that is not set to be pushed to the other side
 (e.g. the configuration is set to matching and there is no such
 branch on the other end).


 How about write the commit log like this:
 ...
 Then if there is no tracking info reported, the user may need to do
 something. Maybe the current branch is a new branch that needs to be
 pushed out, or maybe it's a branch which should add remote tracking
 settings.

Would that help anybody, though?

A user who does not notice the _lack_ of mention of the current
branch in the feedback from git push would not notice the lack of
ahead, behind or the same.

We could contemplate on saying your current branch is not set to be
pushed out to anywhere instead of being silent in the case where
the output with your patch is silent, but that would make status
output irritatingly chatty when you are on a private topic branch
that you never intend to push out except as a part of an integration
branch after merging into it, so it is not a good solution either,
but at least that would solve the original problem.

Isn't it the real solution to the original poster's problem to make
git push explain Everything is up to date, and nothing is pushed
case better?

Perhaps git push can learn an option to show what the command
would push out if there were something to push.  If push.default is
set to matching and the user is on a branch that does not exist on
the receiving end, matching branches will be listed as up to date
and the user could notice that his current branch is _not_ among the
ones that are listed.  When there is _no_ branch to be pushed out
(e.g. there is no matching branches, or you are on a detached HEAD)
that please explain option could really explain whey there is no
branch to be pushed out.

--
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] status: always show tracking branch even no change

2013-08-12 Thread Jiang Xin
2013/8/12 Junio C Hamano gits...@pobox.com:
 Jiang Xin worldhello@gmail.com writes:

 2013/8/10 Junio C Hamano gits...@pobox.com:
 Jiang Xin worldhello@gmail.com writes:

 So always show the remote tracking branch in the output of git status
 and other commands will help users to see where the current branch
 will push to and pull from. E.g.
 ...

 Hmmph.

 I do not know if this will help any case you described above, even
 though this might help some other cases.  The added output is to
 always show the current branch and its upstream, but the thing is,
 the original issue in $gmane/198703 was *not* that the current
 branch was pushed and up to date.  It was that there was no current
 branch to be pushed.  The same thing would happen if you are on a
 local branch that is not set to be pushed to the other side
 (e.g. the configuration is set to matching and there is no such
 branch on the other end).


 How about write the commit log like this:
 ...
 Then if there is no tracking info reported, the user may need to do
 something. Maybe the current branch is a new branch that needs to be
 pushed out, or maybe it's a branch which should add remote tracking
 settings.

 Would that help anybody, though?

I will split the patch into two. The 1st patch resolves a real problem:

branch: not report invalid tracking branch

Command git branch -vv will report tracking branches, but invalid
tracking branches are also reported. This is because the function
stat_tracking_info() can not distinguish whether the upstream branch
does not exist, or nothing is changed between one branch and its
upstream.

This patch changes the return value of function stat_tracking_info().
Only returns false when there is no tracking branch or the tracking
branch is invalid, otherwise true. If the caller does not like to
report tracking info when nothing changed between the branch and its
upstream, simply checks if num_theirs and num_ours are both 0.

And in the 2nd patch, I will not mention git push (current not be
pushed out ...) any more, and only focus on git status. It's just
a suggestion, may only fit small group of users' taste.


-- 
Jiang Xin
--
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] status: always show tracking branch even no change

2013-08-10 Thread Jiang Xin
2013/8/10 Junio C Hamano gits...@pobox.com:
 Jiang Xin worldhello@gmail.com writes:

 So always show the remote tracking branch in the output of git status
 and other commands will help users to see where the current branch
 will push to and pull from. E.g.
 ...

 Hmmph.

 I do not know if this will help any case you described above, even
 though this might help some other cases.  The added output is to
 always show the current branch and its upstream, but the thing is,
 the original issue in $gmane/198703 was *not* that the current
 branch was pushed and up to date.  It was that there was no current
 branch to be pushed.  The same thing would happen if you are on a
 local branch that is not set to be pushed to the other side
 (e.g. the configuration is set to matching and there is no such
 branch on the other end).


How about write the commit log like this:

-- 8 --
From: Jiang Xin worldhello@gmail.com
Date: Wed, 7 Aug 2013 21:45:01 +0800
Subject: [PATCH v4] status: always show tracking branch even no change

If the current branch has an upstream branch, and there are changes
between the current branch and its upstream, some commands (such as
git status, git status -bs, and git checkout) will report their
relationship. E.g.

$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
...

$ git status -bs
## master...origin/master [ahead 1]
...

$ git checkout master
Already on 'master'
Your branch is ahead of 'origin/master' by 1 commit.
...

With this patch, the relationship between the current branch its
upstream will be reported always even if there is no difference
between them. E.g.

$ git status
# On branch master
# Your branch is identical to 'origin/master'.
...

$ git status -bs
## master...origin/master
...

$ git checkout master
Already on 'master'
Your branch is identical to 'origin/master'.
...

Then if there is no tracking info reported, the user may need to do
something. Maybe the current branch is a new branch that needs to be
pushed out, or maybe it's a branch which should add remote tracking
settings.

This patch changes the return value of function stat_tracking_info()
from 0 (not report) to 1 (report), when the current branch and its
remote tracking branch point to the same commit. Also add some test
cases in t6040.

Signed-off-by: Jiang Xin worldhello@gmail.com
---
 builtin/branch.c | 18 +---
 remote.c | 18 +++-
 t/t6040-tracking-info.sh | 54 
 wt-status.c  |  5 +
 4 files changed, 73 insertions(+), 22 deletions(-)

diff --git a/builtin/branch.c b/builtin/branch.c
index 0836890..359e75d 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -424,19 +424,8 @@ static void fill_tracking_info(struct strbuf *stat, const 
char *branch_name,
struct branch *branch = branch_get(branch_name);
struct strbuf fancy = STRBUF_INIT;
 
-   if (!stat_tracking_info(branch, ours, theirs)) {
-   if (branch  branch-merge  branch-merge[0]-dst 
-   show_upstream_ref) {
-   ref = shorten_unambiguous_ref(branch-merge[0]-dst, 0);
-   if (want_color(branch_use_color))
-   strbuf_addf(stat, [%s%s%s] ,
-   
branch_get_color(BRANCH_COLOR_UPSTREAM),
-   ref, 
branch_get_color(BRANCH_COLOR_RESET));
-   else
-   strbuf_addf(stat, [%s] , ref);
-   }
+   if (!stat_tracking_info(branch, ours, theirs))
return;
-   }
 
if (show_upstream_ref) {
ref = shorten_unambiguous_ref(branch-merge[0]-dst, 0);
@@ -448,7 +437,10 @@ static void fill_tracking_info(struct strbuf *stat, const 
char *branch_name,
strbuf_addstr(fancy, ref);
}
 
-   if (!ours) {
+   if (!ours  !theirs) {
+   if (ref)
+   strbuf_addf(stat, _([%s]), fancy.buf);
+   } else if (!ours) {
if (ref)
strbuf_addf(stat, _([%s: behind %d]), fancy.buf, 
theirs);
else
diff --git a/remote.c b/remote.c
index 2433467..79766df 100644
--- a/remote.c
+++ b/remote.c
@@ -1740,6 +1740,10 @@ int stat_tracking_info(struct branch *branch, int 
*num_ours, int *num_theirs)
const char *rev_argv[10], *base;
int rev_argc;
 
+   /* Set both num_theirs and num_ours as undetermined. */
+   *num_theirs = -1;
+   *num_ours = -1;
+
/*
 * Nothing to report unless we are marked to build on top of
 * somebody else.
@@ -1758,16 +1762,18 @@ int stat_tracking_info(struct branch *branch, int 
*num_ours, int *num_theirs)
theirs = lookup_commit_reference(sha1);
if 

Re: [PATCH v3] status: always show tracking branch even no change

2013-08-09 Thread Junio C Hamano
Jiang Xin worldhello@gmail.com writes:

 If the current branch has an upstream branch, and there are changes
 between the current branch and its upstream, some commands (such as
 git status, git status -bs, and git checkout) will report their
 relationship. E.g.

 $ git status
 # On branch master
 # Your branch is ahead of 'origin/master' by 1 commit.
 #   (use git push to publish your local commits)
 #
 ...

 $ git status -bs
 ## master...origin/master [ahead 1]
 ...

 $ git checkout master
 Already on 'master'
 Your branch is ahead of 'origin/master' by 1 commit.
   (use git push to publish your local commits)

 But if there is no difference between the current branch and its
 upstream, the relationship will not be reported, and it's hard to
 tell whether the current branch has a tracking branch or not. And
 what's worse, when the 'push.default' config variable is set to
 `matching`, it's hard to tell whether the current branch has already
 been pushed out or not at all [1].

That description of the problem you are trying to solve makes (sort
of) sense.

 So always show the remote tracking branch in the output of git status
 and other commands will help users to see where the current branch
 will push to and pull from. E.g.

 $ git status
 # On branch master
 # Your branch is identical to 'origin/master'.
 #
 ...

 $ git status -bs
 ## master...origin/master
 ...

Hmmph.

I do not know if this will help any case you described above, even
though this might help some other cases.  The added output is to
always show the current branch and its upstream, but the thing is,
the original issue in $gmane/198703 was *not* that the current
branch was pushed and up to date.  It was that there was no current
branch to be pushed.  The same thing would happen if you are on a
local branch that is not set to be pushed to the other side
(e.g. the configuration is set to matching and there is no such
branch on the other end).

Your branch is identical to will be given only if your branch is
set to be pushed out, no?  For the user to tell what is going on,
the user has to notice the lack of this extra line in the output,
and noticing the lack of anything is much unlikely.
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3] status: always show tracking branch even no change

2013-08-08 Thread Jiang Xin
Changes since v2:

 * The return value of function stat_tracking_info() is changed.
   When the current branch and its remote tracking branch point
   to the same commit, will return 1, instead of 0. Because we
   want to report the tracking info for such case.

 * Remove duplicated codes in builtin/branch.c, and make it simpler.

Jiang Xin (1):
  status: always show tracking branch even no change

 builtin/branch.c | 18 +---
 remote.c | 18 +++-
 t/t6040-tracking-info.sh | 54 
 wt-status.c  |  5 +
 4 files changed, 73 insertions(+), 22 deletions(-)

-- 
1.8.4.rc1.430.g417e2f3

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


[PATCH v3] status: always show tracking branch even no change

2013-08-08 Thread Jiang Xin
If the current branch has an upstream branch, and there are changes
between the current branch and its upstream, some commands (such as
git status, git status -bs, and git checkout) will report their
relationship. E.g.

$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#   (use git push to publish your local commits)
#
...

$ git status -bs
## master...origin/master [ahead 1]
...

$ git checkout master
Already on 'master'
Your branch is ahead of 'origin/master' by 1 commit.
  (use git push to publish your local commits)

But if there is no difference between the current branch and its
upstream, the relationship will not be reported, and it's hard to
tell whether the current branch has a tracking branch or not. And
what's worse, when the 'push.default' config variable is set to
`matching`, it's hard to tell whether the current branch has already
been pushed out or not at all [1].

So always show the remote tracking branch in the output of git status
and other commands will help users to see where the current branch
will push to and pull from. E.g.

$ git status
# On branch master
# Your branch is identical to 'origin/master'.
#
...

$ git status -bs
## master...origin/master
...

$ git checkout master
Already on 'master'
Your branch is identical to 'origin/master'.

This patch changes the return value of function stat_tracking_info().
When the current branch and its remote tracking branch point to the
same commit, will return 1, instead of 0. Because we want to report
the tracking info for such case. Also add some test cases in t6040.

[1]: http://thread.gmane.org/gmane.comp.version-control.git/198703

Signed-off-by: Jiang Xin worldhello@gmail.com
---
 builtin/branch.c | 18 +---
 remote.c | 18 +++-
 t/t6040-tracking-info.sh | 54 
 wt-status.c  |  5 +
 4 files changed, 73 insertions(+), 22 deletions(-)

diff --git a/builtin/branch.c b/builtin/branch.c
index 0836890..359e75d 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -424,19 +424,8 @@ static void fill_tracking_info(struct strbuf *stat, const 
char *branch_name,
struct branch *branch = branch_get(branch_name);
struct strbuf fancy = STRBUF_INIT;
 
-   if (!stat_tracking_info(branch, ours, theirs)) {
-   if (branch  branch-merge  branch-merge[0]-dst 
-   show_upstream_ref) {
-   ref = shorten_unambiguous_ref(branch-merge[0]-dst, 0);
-   if (want_color(branch_use_color))
-   strbuf_addf(stat, [%s%s%s] ,
-   
branch_get_color(BRANCH_COLOR_UPSTREAM),
-   ref, 
branch_get_color(BRANCH_COLOR_RESET));
-   else
-   strbuf_addf(stat, [%s] , ref);
-   }
+   if (!stat_tracking_info(branch, ours, theirs))
return;
-   }
 
if (show_upstream_ref) {
ref = shorten_unambiguous_ref(branch-merge[0]-dst, 0);
@@ -448,7 +437,10 @@ static void fill_tracking_info(struct strbuf *stat, const 
char *branch_name,
strbuf_addstr(fancy, ref);
}
 
-   if (!ours) {
+   if (!ours  !theirs) {
+   if (ref)
+   strbuf_addf(stat, _([%s]), fancy.buf);
+   } else if (!ours) {
if (ref)
strbuf_addf(stat, _([%s: behind %d]), fancy.buf, 
theirs);
else
diff --git a/remote.c b/remote.c
index 2433467..79766df 100644
--- a/remote.c
+++ b/remote.c
@@ -1740,6 +1740,10 @@ int stat_tracking_info(struct branch *branch, int 
*num_ours, int *num_theirs)
const char *rev_argv[10], *base;
int rev_argc;
 
+   /* Set both num_theirs and num_ours as undetermined. */
+   *num_theirs = -1;
+   *num_ours = -1;
+
/*
 * Nothing to report unless we are marked to build on top of
 * somebody else.
@@ -1758,16 +1762,18 @@ int stat_tracking_info(struct branch *branch, int 
*num_ours, int *num_theirs)
theirs = lookup_commit_reference(sha1);
if (!theirs)
return 0;
+   *num_theirs = 0;
 
if (read_ref(branch-refname, sha1))
return 0;
ours = lookup_commit_reference(sha1);
if (!ours)
return 0;
+   *num_ours = 0;
 
-   /* are we the same? */
+   /* are we the same? both num_theirs and num_ours have been set to 0. */
if (theirs == ours)
-   return 0;
+   return 1;
 
/* Run rev-list --left-right ours...theirs internally... */
rev_argc = 0;
@@ -1786,8 +1792,6 @@ int stat_tracking_info(struct branch *branch, int 
*num_ours, int *num_theirs)