From: Jay Soffian <jaysoffian@gmail.com>
To: git@vger.kernel.org
Cc: Jay Soffian <jaysoffian@gmail.com>, Jeff King <peff@peff.net>,
Junio C Hamano <gitster@pobox.com>
Subject: [PATCH 17/21] builtin-remote: teach show to display remote HEAD
Date: Wed, 25 Feb 2009 03:32:24 -0500 [thread overview]
Message-ID: <7c45b430bb59a98a3bb0d7554e67ee549653ec30.1235546708.git.jaysoffian@gmail.com> (raw)
In-Reply-To: <cover.1235546707.git.jaysoffian@gmail.com>
This is in preparation for teaching remote how to set
refs/remotes/<remote>/HEAD to match what HEAD is set to at <remote>, but
is useful in its own right.
Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---
builtin-remote.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++----
t/t5505-remote.sh | 12 +++++++++-
2 files changed, 59 insertions(+), 7 deletions(-)
diff --git a/builtin-remote.c b/builtin-remote.c
index 963be6d..4543cf0 100644
--- a/builtin-remote.c
+++ b/builtin-remote.c
@@ -18,6 +18,9 @@ static const char * const builtin_remote_usage[] = {
NULL
};
+#define GET_REF_STATES (1<<0)
+#define GET_HEAD_NAMES (1<<1)
+
static int verbose;
static int show_all(void);
@@ -210,7 +213,7 @@ static void read_branches(void)
struct ref_states {
struct remote *remote;
- struct string_list new, stale, tracked;
+ struct string_list new, stale, tracked, heads;
};
static int handle_one_branch(const char *refname,
@@ -264,6 +267,28 @@ static int get_ref_states(const struct ref *remote_refs, struct ref_states *stat
return 0;
}
+static int get_head_names(const struct ref *remote_refs, struct ref_states *states)
+{
+ struct ref *ref, *matches;
+ struct ref *fetch_map = NULL, **fetch_map_tail = &fetch_map;
+ struct refspec refspec;
+
+ refspec.force = 0;
+ refspec.pattern = 1;
+ refspec.src = refspec.dst = "refs/heads/";
+ states->heads.strdup_strings = 1;
+ get_fetch_map(remote_refs, &refspec, &fetch_map_tail, 0);
+ matches = guess_remote_head(find_ref_by_name(remote_refs, "HEAD"),
+ fetch_map, 1);
+ for(ref = matches; ref; ref = ref->next)
+ string_list_append(abbrev_branch(ref->name), &states->heads);
+
+ free_refs(fetch_map);
+ free_refs(matches);
+
+ return 0;
+}
+
struct known_remote {
struct known_remote *next;
struct remote *remote;
@@ -630,6 +655,7 @@ static void free_remote_ref_states(struct ref_states *states)
string_list_clear(&states->new, 0);
string_list_clear(&states->stale, 0);
string_list_clear(&states->tracked, 0);
+ string_list_clear(&states->heads, 0);
}
static int append_ref_to_tracked_list(const char *refname,
@@ -668,7 +694,10 @@ static int get_remote_ref_states(const char *name,
remote_refs = transport_get_remote_refs(transport);
transport_disconnect(transport);
- get_ref_states(remote_refs, states);
+ if (query & GET_REF_STATES)
+ get_ref_states(remote_refs, states);
+ if (query & GET_HEAD_NAMES)
+ get_head_names(remote_refs, states);
} else {
for_each_ref(append_ref_to_tracked_list, states);
sort_string_list(&states->tracked);
@@ -679,7 +708,7 @@ static int get_remote_ref_states(const char *name,
static int show(int argc, const char **argv)
{
- int no_query = 0, result = 0;
+ int no_query = 0, result = 0, query_flag = 0;
struct option options[] = {
OPT_GROUP("show specific options"),
OPT_BOOLEAN('n', NULL, &no_query, "do not query remotes"),
@@ -692,15 +721,30 @@ static int show(int argc, const char **argv)
if (argc < 1)
return show_all();
+ if (!no_query)
+ query_flag = (GET_REF_STATES | GET_HEAD_NAMES);
+
memset(&states, 0, sizeof(states));
for (; argc; argc--, argv++) {
int i;
- get_remote_ref_states(*argv, &states, !no_query);
+ get_remote_ref_states(*argv, &states, query_flag);
printf("* remote %s\n URL: %s\n", *argv,
states.remote->url_nr > 0 ?
states.remote->url[0] : "(no URL)");
+ if (no_query)
+ printf(" HEAD branch: (not queried)\n");
+ else if (!states.heads.nr)
+ printf(" HEAD branch: (unknown)\n");
+ else if (states.heads.nr == 1)
+ printf(" HEAD branch: %s\n", states.heads.items[0].string);
+ else {
+ printf(" HEAD branch (remote HEAD is ambiguous,"
+ " may be one of the following):\n");
+ for (i = 0; i < states.heads.nr; i++)
+ printf(" %s\n", states.heads.items[i].string);
+ }
for (i = 0; i < branch_list.nr; i++) {
struct string_list_item *branch = branch_list.items + i;
@@ -772,7 +816,7 @@ static int prune(int argc, const char **argv)
for (; argc; argc--, argv++) {
int i;
- get_remote_ref_states(*argv, &states, 1);
+ get_remote_ref_states(*argv, &states, GET_REF_STATES);
if (states.stale.nr) {
printf("Pruning %s\n", *argv);
diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh
index a13d4b6..91525c3 100755
--- a/t/t5505-remote.sh
+++ b/t/t5505-remote.sh
@@ -136,6 +136,7 @@ EOF
cat > test/expect << EOF
* remote origin
URL: $(pwd)/one
+ HEAD branch: master
Remote branch merged with 'git pull' while on branch master
master
New remote branch (next fetch will store in remotes/origin)
@@ -146,6 +147,11 @@ cat > test/expect << EOF
Local branches pushed with 'git push'
master:upstream
+refs/tags/lastbackup
+* remote two
+ URL: ../two
+ HEAD branch (remote HEAD is ambiguous, may be one of the following):
+ another
+ master
EOF
test_expect_success 'show' '
@@ -154,6 +160,7 @@ test_expect_success 'show' '
refs/heads/master:refs/heads/upstream &&
git fetch &&
git branch -d -r origin/master &&
+ git config --add remote.two.url ../two &&
(cd ../one &&
echo 1 > file &&
test_tick &&
@@ -162,13 +169,14 @@ test_expect_success 'show' '
refs/heads/master:refs/heads/upstream &&
git config --add remote.origin.push \
+refs/tags/lastbackup &&
- git remote show origin > output &&
+ git remote show origin two > output &&
test_cmp expect output)
'
cat > test/expect << EOF
* remote origin
URL: $(pwd)/one
+ HEAD branch: (not queried)
Remote branch merged with 'git pull' while on branch master
master
Tracked remote branches
@@ -343,7 +351,7 @@ test_expect_success '"remote show" does not show symbolic refs' '
git clone one three &&
(cd three &&
git remote show origin > output &&
- ! grep HEAD < output &&
+ ! grep "^ *HEAD$" < output &&
! grep -i stale < output)
'
--
1.6.2.rc1.291.g83eb
next prev parent reply other threads:[~2009-02-25 8:35 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-25 8:32 [PATCH 00/21] git remote: set-head and new show output Jay Soffian
2009-02-25 8:32 ` [PATCH 01/21] test scripts: refactor start_httpd helper Jay Soffian
2009-02-25 8:32 ` [PATCH 02/21] add basic http clone/fetch tests Jay Soffian
2009-02-25 8:32 ` [PATCH 03/21] refactor find_ref_by_name() to accept const list Jay Soffian
2009-02-25 8:32 ` [PATCH 04/21] move duplicated get_local_heads() to remote.c Jay Soffian
2009-02-25 8:32 ` [PATCH 05/21] move duplicated ref_newer() " Jay Soffian
2009-02-25 8:32 ` [PATCH 06/21] move locate_head() " Jay Soffian
2009-02-25 8:32 ` [PATCH 07/21] remote: simplify guess_remote_head() Jay Soffian
2009-02-25 8:32 ` [PATCH 08/21] remote: let guess_remote_head() optionally return all matches Jay Soffian
2009-02-26 14:37 ` Jeff King
2009-02-26 14:40 ` Jeff King
2009-02-26 18:47 ` Jay Soffian
2009-02-27 11:43 ` Jeff King
2009-02-27 19:10 ` [PATCH 0/3] git remote: set-head and new show output (UPDATED) Jay Soffian
2009-02-28 6:33 ` Jeff King
2009-02-25 8:32 ` [PATCH 09/21] remote: make match_refs() copy src ref before assigning to peer_ref Jay Soffian
2009-02-25 8:32 ` [PATCH 10/21] remote: make match_refs() not short-circuit Jay Soffian
2009-02-25 8:32 ` [PATCH 11/21] string-list: new for_each_string_list() function Jay Soffian
2009-02-25 8:32 ` [PATCH 12/21] builtin-remote: refactor duplicated cleanup code Jay Soffian
2009-02-25 8:32 ` [PATCH 13/21] builtin-remote: remove unused code in get_ref_states Jay Soffian
2009-02-25 8:32 ` [PATCH 14/21] builtin-remote: rename variables and eliminate redundant function call Jay Soffian
2009-02-25 8:32 ` [PATCH 15/21] builtin-remote: make get_remote_ref_states() always populate states.tracked Jay Soffian
2009-02-25 8:32 ` [PATCH 16/21] builtin-remote: fix two inconsistencies in the output of "show <remote>" Jay Soffian
2009-02-25 8:32 ` Jay Soffian [this message]
2009-02-25 8:32 ` [PATCH 18/21] builtin-remote: add set-head subcommand Jay Soffian
2009-02-25 8:32 ` [PATCH 19/21] remote: make guess_remote_head() use exact HEAD lookup if it is available Jay Soffian
2009-02-25 8:32 ` [PATCH 20/21] builtin-remote: new show output style Jay Soffian
2009-02-25 8:32 ` [PATCH 21/21] builtin-remote: new show output style for push refspecs Jay Soffian
2009-02-26 14:53 ` [PATCH 00/21] git remote: set-head and new show output Jeff King
2009-02-26 17:04 ` Junio C Hamano
2009-02-27 19:10 ` [PATCH 07a/21] remote: make copy_ref() perform a deep copy Jay Soffian
2009-02-27 19:10 ` [PATCH 08/21] remote: let guess_remote_head() optionally return all matches Jay Soffian
2009-02-27 19:10 ` [PATCH 19/21] remote: make guess_remote_head() use exact HEAD lookup if it is available Jay Soffian
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7c45b430bb59a98a3bb0d7554e67ee549653ec30.1235546708.git.jaysoffian@gmail.com \
--to=jaysoffian@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).