* [PATCH 01/23] builtin-clone: move locate_head() to remote.c so it can be re-used
[not found] <cover.1235467368.git.jaysoffian@gmail.com>
@ 2009-02-24 9:50 ` Jay Soffian
2009-02-24 9:50 ` [PATCH 02/23] builtin-remote: move duplicated cleanup code its own function Jay Soffian
` (21 subsequent siblings)
22 siblings, 0 replies; 23+ messages in thread
From: Jay Soffian @ 2009-02-24 9:50 UTC (permalink / raw)
To: git; +Cc: Jay Soffian, Jeff King, Junio C Hamano
Move locate_head() to remote.c and rename it to guess_remote_head() to
more accurately reflect what it does. This is in preparation for being
able to call it from builtin-remote.c
Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---
builtin-clone.c | 41 +++--------------------------------------
remote.c | 37 +++++++++++++++++++++++++++++++++++++
remote.h | 9 +++++++++
3 files changed, 49 insertions(+), 38 deletions(-)
diff --git a/builtin-clone.c b/builtin-clone.c
index c338910..d179d1c 100644
--- a/builtin-clone.c
+++ b/builtin-clone.c
@@ -20,6 +20,7 @@
#include "dir.h"
#include "pack-refs.h"
#include "sigchain.h"
+#include "remote.h"
/*
* Overall FIXMEs:
@@ -293,43 +294,6 @@ static void remove_junk_on_signal(int signo)
raise(signo);
}
-static const struct ref *locate_head(const struct ref *refs,
- const struct ref *mapped_refs,
- const struct ref **remote_head_p)
-{
- const struct ref *remote_head = NULL;
- const struct ref *remote_master = NULL;
- const struct ref *r;
- for (r = refs; r; r = r->next)
- if (!strcmp(r->name, "HEAD"))
- remote_head = r;
-
- for (r = mapped_refs; r; r = r->next)
- if (!strcmp(r->name, "refs/heads/master"))
- remote_master = r;
-
- if (remote_head_p)
- *remote_head_p = remote_head;
-
- /* If there's no HEAD value at all, never mind. */
- if (!remote_head)
- return NULL;
-
- /* If refs/heads/master could be right, it is. */
- if (remote_master && !hashcmp(remote_master->old_sha1,
- remote_head->old_sha1))
- return remote_master;
-
- /* Look for another ref that points there */
- for (r = mapped_refs; r; r = r->next)
- if (r != remote_head &&
- !hashcmp(r->old_sha1, remote_head->old_sha1))
- return r;
-
- /* Nothing is the same */
- return NULL;
-}
-
static struct ref *write_remote_refs(const struct ref *refs,
struct refspec *refspec, const char *reflog)
{
@@ -545,7 +509,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
mapped_refs = write_remote_refs(refs, &refspec, reflog_msg.buf);
- head_points_at = locate_head(refs, mapped_refs, &remote_head);
+ head_points_at = guess_remote_head(refs, mapped_refs,
+ &remote_head);
}
else {
warning("You appear to have cloned an empty repository.");
diff --git a/remote.c b/remote.c
index d7079c6..447f091 100644
--- a/remote.c
+++ b/remote.c
@@ -1376,3 +1376,40 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb)
base, num_ours, num_theirs);
return 1;
}
+
+const struct ref *guess_remote_head(const struct ref *refs,
+ const struct ref *mapped_refs,
+ const struct ref **remote_head_p)
+{
+ const struct ref *remote_head = NULL;
+ const struct ref *remote_master = NULL;
+ const struct ref *r;
+ for (r = refs; r; r = r->next)
+ if (!strcmp(r->name, "HEAD"))
+ remote_head = r;
+
+ for (r = mapped_refs; r; r = r->next)
+ if (!strcmp(r->name, "refs/heads/master"))
+ remote_master = r;
+
+ if (remote_head_p)
+ *remote_head_p = remote_head;
+
+ /* If there's no HEAD value at all, never mind. */
+ if (!remote_head)
+ return NULL;
+
+ /* If refs/heads/master could be right, it is. */
+ if (remote_master && !hashcmp(remote_master->old_sha1,
+ remote_head->old_sha1))
+ return remote_master;
+
+ /* Look for another ref that points there */
+ for (r = mapped_refs; r; r = r->next)
+ if (r != remote_head &&
+ !hashcmp(r->old_sha1, remote_head->old_sha1))
+ return r;
+
+ /* Nothing is the same */
+ return NULL;
+}
diff --git a/remote.h b/remote.h
index a46a5be..cabb14a 100644
--- a/remote.h
+++ b/remote.h
@@ -137,4 +137,13 @@ enum match_refs_flags {
int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs);
int format_tracking_info(struct branch *branch, struct strbuf *sb);
+/*
+ * Look in refs for HEAD. Then look for a matching SHA1 in mapped_refs,
+ * first checking if refs/heads/master matches. Return NULL if nothing matches
+ * or if there is no HEAD in refs. remote_head_p is assigned HEAD if not NULL.
+ */
+const struct ref *guess_remote_head(const struct ref *refs,
+ const struct ref *mapped_refs,
+ const struct ref **remote_head_p);
+
#endif
--
1.6.2.rc1.291.g83eb
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH 02/23] builtin-remote: move duplicated cleanup code its own function
[not found] <cover.1235467368.git.jaysoffian@gmail.com>
2009-02-24 9:50 ` [PATCH 01/23] builtin-clone: move locate_head() to remote.c so it can be re-used Jay Soffian
@ 2009-02-24 9:50 ` Jay Soffian
2009-02-24 9:50 ` [PATCH 03/23] builtin-remote: teach show to display remote HEAD Jay Soffian
` (20 subsequent siblings)
22 siblings, 0 replies; 23+ messages in thread
From: Jay Soffian @ 2009-02-24 9:50 UTC (permalink / raw)
To: git; +Cc: Jay Soffian, Jeff King, Junio C Hamano
Moved some identical lines of code into their own function in
preparation for adding additional functionality which will use this
function as well.
Also removed a bogus NEEDSWORK comment per Daniel Barkalow:
Actually, the comment is wrong; "remote" comes from remote_get(),
which returns things from a cache in remote.c; there could be a
remote_put() to let the code know that the caller is done with the
object, but it wouldn't presently do anything.
Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---
builtin-remote.c | 17 +++++++++--------
1 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/builtin-remote.c b/builtin-remote.c
index ac69d37..b89a353 100644
--- a/builtin-remote.c
+++ b/builtin-remote.c
@@ -632,6 +632,13 @@ static void show_list(const char *title, struct string_list *list,
printf(" %s\n", list->items[i].string);
}
+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);
+}
+
static int get_remote_ref_states(const char *name,
struct ref_states *states,
int query)
@@ -738,10 +745,7 @@ static int show(int argc, const char **argv)
}
}
- /* NEEDSWORK: free remote */
- string_list_clear(&states.new, 0);
- string_list_clear(&states.stale, 0);
- string_list_clear(&states.tracked, 0);
+ free_remote_ref_states(&states);
}
return result;
@@ -792,10 +796,7 @@ static int prune(int argc, const char **argv)
warn_dangling_symref(dangling_msg, refname);
}
- /* NEEDSWORK: free remote */
- string_list_clear(&states.new, 0);
- string_list_clear(&states.stale, 0);
- string_list_clear(&states.tracked, 0);
+ free_remote_ref_states(&states);
}
return result;
--
1.6.2.rc1.291.g83eb
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH 03/23] builtin-remote: teach show to display remote HEAD
[not found] <cover.1235467368.git.jaysoffian@gmail.com>
2009-02-24 9:50 ` [PATCH 01/23] builtin-clone: move locate_head() to remote.c so it can be re-used Jay Soffian
2009-02-24 9:50 ` [PATCH 02/23] builtin-remote: move duplicated cleanup code its own function Jay Soffian
@ 2009-02-24 9:50 ` Jay Soffian
2009-02-24 9:50 ` [PATCH 04/23] builtin-remote: add set-head subcommand Jay Soffian
` (19 subsequent siblings)
22 siblings, 0 replies; 23+ messages in thread
From: Jay Soffian @ 2009-02-24 9:50 UTC (permalink / raw)
To: git; +Cc: Jay Soffian, Jeff King, Junio C Hamano
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 | 26 ++++++++++++++++++++++++++
t/t5505-remote.sh | 3 ++-
2 files changed, 28 insertions(+), 1 deletions(-)
diff --git a/builtin-remote.c b/builtin-remote.c
index b89a353..465c87a 100644
--- a/builtin-remote.c
+++ b/builtin-remote.c
@@ -212,6 +212,7 @@ static void read_branches(void)
struct ref_states {
struct remote *remote;
struct string_list new, stale, tracked;
+ char *head_name;
};
static int handle_one_branch(const char *refname,
@@ -271,6 +272,26 @@ static int get_ref_states(const struct ref *ref, struct ref_states *states)
return 0;
}
+static char *get_head_name(const struct ref *refs)
+{
+ const struct ref *head_points_at;
+ struct ref *mapped_refs = NULL;
+ struct ref **tail = &mapped_refs;
+ struct refspec refspec;
+
+ refspec.force = 0;
+ refspec.pattern = 1;
+ refspec.src = refspec.dst = "refs/heads/";
+
+ get_fetch_map(refs, &refspec, &tail, 0);
+
+ head_points_at = guess_remote_head(refs, mapped_refs, NULL);
+ if (head_points_at)
+ return xstrdup(abbrev_branch(head_points_at->name));
+
+ return NULL;
+}
+
struct known_remote {
struct known_remote *next;
struct remote *remote;
@@ -637,6 +658,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);
+ free(states->head_name);
}
static int get_remote_ref_states(const char *name,
@@ -658,6 +680,7 @@ static int get_remote_ref_states(const char *name,
ref = transport_get_remote_refs(transport);
transport_disconnect(transport);
+ states->head_name = get_head_name(ref);
get_ref_states(ref, states);
}
@@ -702,6 +725,9 @@ static int show(int argc, const char **argv)
printf("* remote %s\n URL: %s\n", *argv,
states.remote->url_nr > 0 ?
states.remote->url[0] : "(no URL)");
+ if (!no_query)
+ printf(" HEAD: %s\n", states.head_name ?
+ states.head_name : "(unknown)");
for (i = 0; i < branch_list.nr; i++) {
struct string_list_item *branch = branch_list.items + i;
diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh
index eb63718..826d0c3 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: master
Remote branch merged with 'git pull' while on branch master
master
New remote branch (next fetch will store in remotes/origin)
@@ -343,7 +344,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
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH 04/23] builtin-remote: add set-head subcommand
[not found] <cover.1235467368.git.jaysoffian@gmail.com>
` (2 preceding siblings ...)
2009-02-24 9:50 ` [PATCH 03/23] builtin-remote: teach show to display remote HEAD Jay Soffian
@ 2009-02-24 9:50 ` Jay Soffian
2009-02-24 9:50 ` [PATCH 05/23] builtin-remote: better handling of multiple remote HEADs Jay Soffian
` (18 subsequent siblings)
22 siblings, 0 replies; 23+ messages in thread
From: Jay Soffian @ 2009-02-24 9:50 UTC (permalink / raw)
To: git; +Cc: Jay Soffian, Jeff King, Junio C Hamano
Provide a porcelain command for setting and deleting
$GIT_DIR/remotes/<remote>/HEAD.
While we're at it, document what $GIT_DIR/remotes/<remote>/HEAD is all
about.
Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---
Documentation/git-remote.txt | 28 ++++++++++++++++-
builtin-remote.c | 51 ++++++++++++++++++++++++++++++++
contrib/completion/git-completion.bash | 2 +-
3 files changed, 78 insertions(+), 3 deletions(-)
diff --git a/Documentation/git-remote.txt b/Documentation/git-remote.txt
index fad983e..c9c0e6f 100644
--- a/Documentation/git-remote.txt
+++ b/Documentation/git-remote.txt
@@ -13,6 +13,7 @@ SYNOPSIS
'git remote add' [-t <branch>] [-m <master>] [-f] [--mirror] <name> <url>
'git remote rename' <old> <new>
'git remote rm' <name>
+'git remote set-head' <name> [-a | -d | <branch>]
'git remote show' [-n] <name>
'git remote prune' [-n | --dry-run] <name>
'git remote update' [group]
@@ -53,8 +54,7 @@ is created. You can give more than one `-t <branch>` to track
multiple branches without grabbing all branches.
+
With `-m <master>` option, `$GIT_DIR/remotes/<name>/HEAD` is set
-up to point at remote's `<master>` branch instead of whatever
-branch the `HEAD` at the remote repository actually points at.
+up to point at remote's `<master>` branch. See also the set-head command.
+
In mirror mode, enabled with `\--mirror`, the refs will not be stored
in the 'refs/remotes/' namespace, but in 'refs/heads/'. This option
@@ -76,6 +76,30 @@ the configuration file format.
Remove the remote named <name>. All remote tracking branches and
configuration settings for the remote are removed.
+'set-head'::
+
+Sets or deletes the default branch (`$GIT_DIR/remotes/<name>/HEAD`) for
+the named remote. Having a default branch for a remote is not required,
+but allows the name of the remote to be specified in lieu of a specific
+branch. For example, if the default branch for `origin` is set to
+`master`, then `origin` may be specified wherever you would normally
+specify `origin/master`.
++
+With `-d`, `$GIT_DIR/remotes/<name>/HEAD` is deleted.
++
+With `-a`, the remote is queried to determine its `HEAD`, then
+`$GIT_DIR/remotes/<name>/HEAD` is set to the same branch. e.g., if the remote
+`HEAD` is pointed at `next`, "`git remote set-head origin -a`" will set
+`$GIT_DIR/refs/remotes/origin/HEAD` to `refs/remotes/origin/next`. This will
+only work if `refs/remotes/origin/next` already exists; if not it must be
+fetched first.
++
+Use `<branch>` to set `$GIT_DIR/remotes/<name>/HEAD` explicitly. e.g., "git
+remote set-head origin master" will set `$GIT_DIR/refs/remotes/origin/HEAD` to
+`refs/remotes/origin/master`. This will only work if
+`refs/remotes/origin/master` already exists; if not it must be fetched first.
++
+
'show'::
Gives some information about the remote <name>.
diff --git a/builtin-remote.c b/builtin-remote.c
index 465c87a..fcb166b 100644
--- a/builtin-remote.c
+++ b/builtin-remote.c
@@ -12,6 +12,7 @@ static const char * const builtin_remote_usage[] = {
"git remote add [-t <branch>] [-m <master>] [-f] [--mirror] <name> <url>",
"git remote rename <old> <new>",
"git remote rm <name>",
+ "git remote set-head <name> [-a | -d | <branch>]",
"git remote show [-n] <name>",
"git remote prune [-n | --dry-run] <name>",
"git remote [-v | --verbose] update [group]",
@@ -777,6 +778,54 @@ static int show(int argc, const char **argv)
return result;
}
+static int set_head(int argc, const char **argv)
+{
+ int opt_a = 0, opt_d = 0, result = 0;
+ struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT;
+ char *head_name = NULL;
+
+ struct option options[] = {
+ OPT_GROUP("set-head specific options"),
+ OPT_BOOLEAN('a', "auto", &opt_a,
+ "set refs/remotes/<name>/HEAD according to remote"),
+ OPT_BOOLEAN('d', "delete", &opt_d,
+ "delete refs/remotes/<name>/HEAD"),
+ OPT_END()
+ };
+ argc = parse_options(argc, argv, options, builtin_remote_usage, 0);
+ if (argc)
+ strbuf_addf(&buf, "refs/remotes/%s/HEAD", argv[0]);
+
+ if (!opt_a && !opt_d && argc == 2) {
+ head_name = xstrdup(argv[1]);
+ } else if (opt_a && !opt_d && argc == 1) {
+ struct ref_states states;
+ memset(&states, 0, sizeof(states));
+ get_remote_ref_states(argv[0], &states, 1);
+ head_name = xstrdup(states.head_name);
+ free_remote_ref_states(&states);
+ } else if (opt_d && !opt_a && argc == 1) {
+ if (delete_ref(buf.buf, NULL, REF_NODEREF))
+ result |= error("Could not delete %s", buf.buf);
+ } else
+ usage_with_options(builtin_remote_usage, options);
+
+ if (head_name) {
+ unsigned char sha1[20];
+ strbuf_addf(&buf2, "refs/remotes/%s/%s", argv[0], head_name);
+ /* make sure it's valid */
+ if (!resolve_ref(buf2.buf, sha1, 1, NULL))
+ result |= error("Not a valid ref: %s", buf2.buf);
+ else if (create_symref(buf.buf, buf2.buf, "remote set-head"))
+ result |= error("Could not setup %s", buf.buf);
+ free(head_name);
+ }
+
+ strbuf_release(&buf);
+ strbuf_release(&buf2);
+ return result;
+}
+
static int prune(int argc, const char **argv)
{
int dry_run = 0, result = 0;
@@ -947,6 +996,8 @@ int cmd_remote(int argc, const char **argv, const char *prefix)
result = mv(argc, argv);
else if (!strcmp(argv[0], "rm"))
result = rm(argc, argv);
+ else if (!strcmp(argv[0], "set-head"))
+ result = set_head(argc, argv);
else if (!strcmp(argv[0], "show"))
result = show(argc, argv);
else if (!strcmp(argv[0], "prune"))
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 0a3092f..15b938b 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1443,7 +1443,7 @@ _git_config ()
_git_remote ()
{
- local subcommands="add rename rm show prune update"
+ local subcommands="add rename rm show prune update set-head"
local subcommand="$(__git_find_subcommand "$subcommands")"
if [ -z "$subcommand" ]; then
__gitcomp "$subcommands"
--
1.6.2.rc1.291.g83eb
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH 05/23] builtin-remote: better handling of multiple remote HEADs
[not found] <cover.1235467368.git.jaysoffian@gmail.com>
` (3 preceding siblings ...)
2009-02-24 9:50 ` [PATCH 04/23] builtin-remote: add set-head subcommand Jay Soffian
@ 2009-02-24 9:50 ` Jay Soffian
2009-02-24 9:50 ` [PATCH 06/23] remote.c: make match_refs() copy src ref before assigning to peer_ref Jay Soffian
` (17 subsequent siblings)
22 siblings, 0 replies; 23+ messages in thread
From: Jay Soffian @ 2009-02-24 9:50 UTC (permalink / raw)
To: git; +Cc: Jay Soffian, Jeff King, Junio C Hamano
It is not currently possible to determine the remote HEAD unambiguously
when multiple remote branches share the same SHA1 as the remote HEAD.
In this situation, git remote set-head --auto should not try to guess
which HEAD the user wants. This patch causes set-head to provide a
useful error instead:
$ git remote set-head origin --auto
error: Multiple remote HEAD branches. Please choose one explicitly with:
git remote set-head origin another
git remote set-head origin master
Also, the output of git remote show now shows the multiple HEADs:
$ git remote show origin
* remote origin
URL: ...
HEAD branches:
another
master
Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---
builtin-clone.c | 2 +-
builtin-remote.c | 56 +++++++++++++++++++++++++++++++++++------------------
remote.c | 28 ++++++++++++++++++-------
remote.h | 6 ++++-
t/t5505-remote.sh | 51 ++++++++++++++++++++++++++++++++++++++++++++++-
5 files changed, 112 insertions(+), 31 deletions(-)
diff --git a/builtin-clone.c b/builtin-clone.c
index d179d1c..d57818c 100644
--- a/builtin-clone.c
+++ b/builtin-clone.c
@@ -510,7 +510,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
mapped_refs = write_remote_refs(refs, &refspec, reflog_msg.buf);
head_points_at = guess_remote_head(refs, mapped_refs,
- &remote_head);
+ &remote_head, NULL);
}
else {
warning("You appear to have cloned an empty repository.");
diff --git a/builtin-remote.c b/builtin-remote.c
index fcb166b..608c0f3 100644
--- a/builtin-remote.c
+++ b/builtin-remote.c
@@ -212,8 +212,7 @@ static void read_branches(void)
struct ref_states {
struct remote *remote;
- struct string_list new, stale, tracked;
- char *head_name;
+ struct string_list new, stale, tracked, heads;
};
static int handle_one_branch(const char *refname,
@@ -273,24 +272,26 @@ static int get_ref_states(const struct ref *ref, struct ref_states *states)
return 0;
}
-static char *get_head_name(const struct ref *refs)
+static int get_head_names(const struct ref *refs,
+ const char *remote_name, struct ref_states *states)
{
- const struct ref *head_points_at;
- struct ref *mapped_refs = NULL;
- struct ref **tail = &mapped_refs;
+ struct ref *ref, *matches = NULL;
+ 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(refs, &refspec, &fetch_map_tail, 0);
+ guess_remote_head(refs, fetch_map, NULL, &matches);
+ for(ref = matches; ref; ref = ref->next)
+ string_list_append(abbrev_branch(ref->name), &states->heads);
- get_fetch_map(refs, &refspec, &tail, 0);
-
- head_points_at = guess_remote_head(refs, mapped_refs, NULL);
- if (head_points_at)
- return xstrdup(abbrev_branch(head_points_at->name));
+ free_refs(fetch_map);
+ free_refs(matches);
- return NULL;
+ return 0;
}
struct known_remote {
@@ -659,7 +660,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);
- free(states->head_name);
+ string_list_clear(&states->heads, 0);
}
static int get_remote_ref_states(const char *name,
@@ -681,7 +682,7 @@ static int get_remote_ref_states(const char *name,
ref = transport_get_remote_refs(transport);
transport_disconnect(transport);
- states->head_name = get_head_name(ref);
+ get_head_names(ref, name, states);
get_ref_states(ref, states);
}
@@ -726,9 +727,15 @@ static int show(int argc, const char **argv)
printf("* remote %s\n URL: %s\n", *argv,
states.remote->url_nr > 0 ?
states.remote->url[0] : "(no URL)");
- if (!no_query)
- printf(" HEAD: %s\n", states.head_name ?
- states.head_name : "(unknown)");
+ 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
+ show_list(" HEAD branch%s:", &states.heads, "");
for (i = 0; i < branch_list.nr; i++) {
struct string_list_item *branch = branch_list.items + i;
@@ -780,7 +787,7 @@ static int show(int argc, const char **argv)
static int set_head(int argc, const char **argv)
{
- int opt_a = 0, opt_d = 0, result = 0;
+ int i, opt_a = 0, opt_d = 0, result = 0;
struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT;
char *head_name = NULL;
@@ -802,7 +809,16 @@ static int set_head(int argc, const char **argv)
struct ref_states states;
memset(&states, 0, sizeof(states));
get_remote_ref_states(argv[0], &states, 1);
- head_name = xstrdup(states.head_name);
+ if (!states.heads.nr)
+ result |= error("Cannot determine remote HEAD");
+ else if (states.heads.nr > 1) {
+ result |= error("Multiple remote HEAD branches. "
+ "Please choose one explicitly with:");
+ for (i = 0; i < states.heads.nr; i++)
+ fprintf(stderr, " git remote set-head %s %s\n",
+ argv[0], states.heads.items[i].string);
+ } else
+ head_name = xstrdup(states.heads.items[0].string);
free_remote_ref_states(&states);
} else if (opt_d && !opt_a && argc == 1) {
if (delete_ref(buf.buf, NULL, REF_NODEREF))
@@ -818,6 +834,8 @@ static int set_head(int argc, const char **argv)
result |= error("Not a valid ref: %s", buf2.buf);
else if (create_symref(buf.buf, buf2.buf, "remote set-head"))
result |= error("Could not setup %s", buf.buf);
+ if (opt_a)
+ printf("%s/HEAD set to %s\n", argv[0], head_name);
free(head_name);
}
diff --git a/remote.c b/remote.c
index 447f091..6385a22 100644
--- a/remote.c
+++ b/remote.c
@@ -1379,18 +1379,23 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb)
const struct ref *guess_remote_head(const struct ref *refs,
const struct ref *mapped_refs,
- const struct ref **remote_head_p)
+ const struct ref **remote_head_p,
+ struct ref **all_matches_p)
{
const struct ref *remote_head = NULL;
const struct ref *remote_master = NULL;
+ const struct ref *ret = NULL;
const struct ref *r;
+ struct ref **tail = all_matches_p;
+
for (r = refs; r; r = r->next)
if (!strcmp(r->name, "HEAD"))
remote_head = r;
- for (r = mapped_refs; r; r = r->next)
- if (!strcmp(r->name, "refs/heads/master"))
- remote_master = r;
+ if (!all_matches_p)
+ for (r = mapped_refs; r; r = r->next)
+ if (!strcmp(r->name, "refs/heads/master"))
+ remote_master = r;
if (remote_head_p)
*remote_head_p = remote_head;
@@ -1407,9 +1412,16 @@ const struct ref *guess_remote_head(const struct ref *refs,
/* Look for another ref that points there */
for (r = mapped_refs; r; r = r->next)
if (r != remote_head &&
- !hashcmp(r->old_sha1, remote_head->old_sha1))
- return r;
+ !hashcmp(r->old_sha1, remote_head->old_sha1)) {
+ struct ref *cpy;
+ if (!ret)
+ ret = r;
+ if (!all_matches_p)
+ break;
+ *tail = cpy = copy_ref(r);
+ cpy->peer_ref = NULL;
+ tail = &cpy->next;
+ }
- /* Nothing is the same */
- return NULL;
+ return ret;
}
diff --git a/remote.h b/remote.h
index cabb14a..8409d42 100644
--- a/remote.h
+++ b/remote.h
@@ -141,9 +141,13 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb);
* Look in refs for HEAD. Then look for a matching SHA1 in mapped_refs,
* first checking if refs/heads/master matches. Return NULL if nothing matches
* or if there is no HEAD in refs. remote_head_p is assigned HEAD if not NULL.
+ * If all_matches_p is NULL, return after the first possible match. Otherwise
+ * all_matches_p is set to a ref list of each branch head with the same SHA1 as
+ * HEAD.
*/
const struct ref *guess_remote_head(const struct ref *refs,
const struct ref *mapped_refs,
- const struct ref **remote_head_p);
+ const struct ref **remote_head_p,
+ struct ref **all_matches_p);
#endif
diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh
index 826d0c3..9ea923b 100755
--- a/t/t5505-remote.sh
+++ b/t/t5505-remote.sh
@@ -136,7 +136,7 @@ EOF
cat > test/expect << EOF
* remote origin
URL: $(pwd)/one
- HEAD: master
+ HEAD branch: master
Remote branch merged with 'git pull' while on branch master
master
New remote branch (next fetch will store in remotes/origin)
@@ -147,6 +147,11 @@ cat > test/expect << EOF
Local branches pushed with 'git push'
master:upstream
+refs/tags/lastbackup
+* remote two
+ URL: ../two
+ HEAD branches:
+ another
+ master
EOF
test_expect_success 'show' '
@@ -155,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 &&
@@ -163,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
@@ -198,6 +205,46 @@ test_expect_success 'prune' '
test_must_fail git rev-parse refs/remotes/origin/side)
'
+test_expect_success 'set-head --delete' '
+ (cd test &&
+ git symbolic-ref refs/remotes/origin/HEAD &&
+ git remote set-head --delete origin &&
+ test_must_fail git symbolic-ref refs/remotes/origin/HEAD)
+'
+
+test_expect_success 'set-head --auto' '
+ (cd test &&
+ git remote set-head --auto origin &&
+ echo refs/remotes/origin/master >expect &&
+ git symbolic-ref refs/remotes/origin/HEAD >output &&
+ test_cmp expect output
+ )
+'
+
+cat >test/expect <<EOF
+error: Multiple remote HEAD branches. Please choose one explicitly with:
+ git remote set-head two another
+ git remote set-head two master
+EOF
+
+test_expect_success 'set-head --auto fails w/multiple HEADs' '
+ (cd test &&
+ test_must_fail git remote set-head --auto two >output 2>&1 &&
+ test_cmp expect output)
+'
+
+cat >test/expect <<EOF
+refs/remotes/origin/side2
+EOF
+
+test_expect_success 'set-head explicit' '
+ (cd test &&
+ git remote set-head origin side2 &&
+ git symbolic-ref refs/remotes/origin/HEAD >output &&
+ git remote set-head origin master &&
+ test_cmp expect output)
+'
+
cat > test/expect << EOF
Pruning origin
URL: $(pwd)/one
--
1.6.2.rc1.291.g83eb
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH 06/23] remote.c: make match_refs() copy src ref before assigning to peer_ref
[not found] <cover.1235467368.git.jaysoffian@gmail.com>
` (4 preceding siblings ...)
2009-02-24 9:50 ` [PATCH 05/23] builtin-remote: better handling of multiple remote HEADs Jay Soffian
@ 2009-02-24 9:50 ` Jay Soffian
2009-02-24 9:50 ` [PATCH 07/23] remote.c: don't short-circuit match_refs() when error in match_explicit_refs() Jay Soffian
` (16 subsequent siblings)
22 siblings, 0 replies; 23+ messages in thread
From: Jay Soffian @ 2009-02-24 9:50 UTC (permalink / raw)
To: git; +Cc: Jay Soffian, Jeff King, Junio C Hamano
In some instances, match_refs() sets the peer_ref field of refs in the
dst list such that it points to a ref in the src list. This prevents
callers from freeing both the src and dst lists, as doing so would cause
a double-free since free_refs() frees the peer_ref.
As well, the following configuration causes two refs in the dst list to
have the same peer_ref, which can also lead to a double-free:
push = refs/heads/master:refs/heads/backup
push = refs/heads/master:refs/heads/master
Existing callers of match_heads() call it only once and then terminate,
w/o ever bothering to free the src or dst lists, so this is not
currently a problem.
This patch modifies match_refs() to first copy any refs it plucks from
the src list before assigning them as a peer_ref, thus future-proofing
the function against callers who might wish to free the src and/or dst
lists.
Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---
remote.c | 7 +++++--
1 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/remote.c b/remote.c
index 6385a22..64879ce 100644
--- a/remote.c
+++ b/remote.c
@@ -927,6 +927,7 @@ static int match_explicit(struct ref *src, struct ref *dst,
struct refspec *rs)
{
struct ref *matched_src, *matched_dst;
+ int copy_src;
const char *dst_value = rs->dst;
char *dst_guess;
@@ -937,6 +938,7 @@ static int match_explicit(struct ref *src, struct ref *dst,
matched_src = matched_dst = NULL;
switch (count_refspec_match(rs->src, src, &matched_src)) {
case 1:
+ copy_src = 1;
break;
case 0:
/* The source could be in the get_sha1() format
@@ -946,6 +948,7 @@ static int match_explicit(struct ref *src, struct ref *dst,
matched_src = try_explicit_object_name(rs->src);
if (!matched_src)
return error("src refspec %s does not match any.", rs->src);
+ copy_src = 0;
break;
default:
return error("src refspec %s matches more than one.", rs->src);
@@ -991,7 +994,7 @@ static int match_explicit(struct ref *src, struct ref *dst,
return error("dst ref %s receives from more than one src.",
matched_dst->name);
else {
- matched_dst->peer_ref = matched_src;
+ matched_dst->peer_ref = copy_src ? copy_ref(matched_src) : matched_src;
matched_dst->force = rs->force;
}
return 0;
@@ -1099,7 +1102,7 @@ int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail,
dst_peer = make_linked_ref(dst_name, dst_tail);
hashcpy(dst_peer->new_sha1, src->new_sha1);
}
- dst_peer->peer_ref = src;
+ dst_peer->peer_ref = copy_ref(src);
dst_peer->force = pat->force;
free_name:
free(dst_name);
--
1.6.2.rc1.291.g83eb
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH 07/23] remote.c: don't short-circuit match_refs() when error in match_explicit_refs()
[not found] <cover.1235467368.git.jaysoffian@gmail.com>
` (5 preceding siblings ...)
2009-02-24 9:50 ` [PATCH 06/23] remote.c: make match_refs() copy src ref before assigning to peer_ref Jay Soffian
@ 2009-02-24 9:50 ` Jay Soffian
2009-02-24 9:50 ` [PATCH 08/23] refactor duplicated get_local_heads() to remote.c Jay Soffian
` (15 subsequent siblings)
22 siblings, 0 replies; 23+ messages in thread
From: Jay Soffian @ 2009-02-24 9:50 UTC (permalink / raw)
To: git; +Cc: Jay Soffian, Jeff King, Junio C Hamano
match_refs() returns non-zero if there is an error in
match_explicit_refs(), without handling any remaining pattern ref specs.
Its existing callers exit upon receiving non-zero, so a partial result
is of no consequence to them; however it is about to have a new caller
that is interested in the complete result even if there are errors in
match_explicit_refs().
Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---
remote.c | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/remote.c b/remote.c
index 64879ce..9f22aaf 100644
--- a/remote.c
+++ b/remote.c
@@ -1043,6 +1043,7 @@ int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail,
struct refspec *rs;
int send_all = flags & MATCH_REFS_ALL;
int send_mirror = flags & MATCH_REFS_MIRROR;
+ int errs;
static const char *default_refspec[] = { ":", 0 };
if (!nr_refspec) {
@@ -1050,8 +1051,7 @@ int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail,
refspec = default_refspec;
}
rs = parse_push_refspec(nr_refspec, (const char **) refspec);
- if (match_explicit_refs(src, dst, dst_tail, rs, nr_refspec))
- return -1;
+ errs = match_explicit_refs(src, dst, dst_tail, rs, nr_refspec);
/* pick the remainder */
for ( ; src; src = src->next) {
@@ -1107,6 +1107,8 @@ int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail,
free_name:
free(dst_name);
}
+ if (errs)
+ return -1;
return 0;
}
--
1.6.2.rc1.291.g83eb
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH 08/23] refactor duplicated get_local_heads() to remote.c
[not found] <cover.1235467368.git.jaysoffian@gmail.com>
` (6 preceding siblings ...)
2009-02-24 9:50 ` [PATCH 07/23] remote.c: don't short-circuit match_refs() when error in match_explicit_refs() Jay Soffian
@ 2009-02-24 9:50 ` Jay Soffian
2009-02-24 9:50 ` [PATCH 09/23] refactor duplicated ref_newer() " Jay Soffian
` (14 subsequent siblings)
22 siblings, 0 replies; 23+ messages in thread
From: Jay Soffian @ 2009-02-24 9:50 UTC (permalink / raw)
To: git; +Cc: Jay Soffian, Jeff King, Junio C Hamano
get_local_heads() appears to have been copied from builtin-send-pack.c
to http-push.c via cut and paste. This patch moves the function and its
helper one_local_ref() to remote.c.
The two copies of one_local_ref() were not identical. I used the more
recent version from builtin-send-pack.c after confirming with Jeff King
that it was an oversight that commit 30affa1e did not update both
copies.
Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---
builtin-send-pack.c | 29 ++---------------------------
http-push.c | 23 ++---------------------
remote.c | 26 ++++++++++++++++++++++++++
remote.h | 1 +
4 files changed, 31 insertions(+), 48 deletions(-)
diff --git a/builtin-send-pack.c b/builtin-send-pack.c
index d65d019..2fbfc29 100644
--- a/builtin-send-pack.c
+++ b/builtin-send-pack.c
@@ -133,33 +133,8 @@ static int ref_newer(const unsigned char *new_sha1,
return found;
}
-static struct ref *local_refs, **local_tail;
static struct ref *remote_refs, **remote_tail;
-static int one_local_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
-{
- struct ref *ref;
- int len;
-
- /* we already know it starts with refs/ to get here */
- if (check_ref_format(refname + 5))
- return 0;
-
- len = strlen(refname) + 1;
- ref = xcalloc(1, sizeof(*ref) + len);
- hashcpy(ref->new_sha1, sha1);
- memcpy(ref->name, refname, len);
- *local_tail = ref;
- local_tail = &ref->next;
- return 0;
-}
-
-static void get_local_heads(void)
-{
- local_tail = &local_refs;
- for_each_ref(one_local_ref, NULL);
-}
-
static int receive_status(int in, struct ref *refs)
{
struct ref *hint;
@@ -387,7 +362,7 @@ static int refs_pushed(struct ref *ref)
static int do_send_pack(int in, int out, struct remote *remote, const char *dest, int nr_refspec, const char **refspec)
{
- struct ref *ref;
+ struct ref *ref, *local_refs;
int new_refs;
int ask_for_status_report = 0;
int allow_deleting_refs = 0;
@@ -405,7 +380,7 @@ static int do_send_pack(int in, int out, struct remote *remote, const char *dest
/* No funny business with the matcher */
remote_tail = get_remote_heads(in, &remote_refs, 0, NULL, REF_NORMAL,
&extra_have);
- get_local_heads();
+ local_refs = get_local_heads();
/* Does the other end support the reporting? */
if (server_supports("report-status"))
diff --git a/http-push.c b/http-push.c
index 30d2d34..cfeed81 100644
--- a/http-push.c
+++ b/http-push.c
@@ -1792,21 +1792,8 @@ static int update_remote(unsigned char *sha1, struct remote_lock *lock)
return 1;
}
-static struct ref *local_refs, **local_tail;
static struct ref *remote_refs, **remote_tail;
-static int one_local_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
-{
- struct ref *ref;
- int len = strlen(refname) + 1;
- ref = xcalloc(1, sizeof(*ref) + len);
- hashcpy(ref->new_sha1, sha1);
- memcpy(ref->name, refname, len);
- *local_tail = ref;
- local_tail = &ref->next;
- return 0;
-}
-
static void one_remote_ref(char *refname)
{
struct ref *ref;
@@ -1839,12 +1826,6 @@ static void one_remote_ref(char *refname)
remote_tail = &ref->next;
}
-static void get_local_heads(void)
-{
- local_tail = &local_refs;
- for_each_ref(one_local_ref, NULL);
-}
-
static void get_dav_remote_heads(void)
{
remote_tail = &remote_refs;
@@ -2195,7 +2176,7 @@ int main(int argc, char **argv)
int rc = 0;
int i;
int new_refs;
- struct ref *ref;
+ struct ref *ref, *local_refs;
char *rewritten_url = NULL;
git_extract_argv0_path(argv[0]);
@@ -2302,7 +2283,7 @@ int main(int argc, char **argv)
fetch_indices();
/* Get a list of all local and remote heads to validate refspecs */
- get_local_heads();
+ local_refs = get_local_heads();
fprintf(stderr, "Fetching remote heads...\n");
get_dav_remote_heads();
diff --git a/remote.c b/remote.c
index 9f22aaf..8fd8d23 100644
--- a/remote.c
+++ b/remote.c
@@ -1430,3 +1430,29 @@ const struct ref *guess_remote_head(const struct ref *refs,
return ret;
}
+
+static int one_local_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
+{
+ struct ref ***local_tail = cb_data;
+ struct ref *ref;
+ int len;
+
+ /* we already know it starts with refs/ to get here */
+ if (check_ref_format(refname + 5))
+ return 0;
+
+ len = strlen(refname) + 1;
+ ref = xcalloc(1, sizeof(*ref) + len);
+ hashcpy(ref->new_sha1, sha1);
+ memcpy(ref->name, refname, len);
+ **local_tail = ref;
+ *local_tail = &ref->next;
+ return 0;
+}
+
+struct ref *get_local_heads(void)
+{
+ struct ref *local_refs, **local_tail = &local_refs;
+ for_each_ref(one_local_ref, &local_tail);
+ return local_refs;
+}
diff --git a/remote.h b/remote.h
index 8409d42..6ff0cda 100644
--- a/remote.h
+++ b/remote.h
@@ -150,4 +150,5 @@ const struct ref *guess_remote_head(const struct ref *refs,
const struct ref **remote_head_p,
struct ref **all_matches_p);
+struct ref *get_local_heads(void);
#endif
--
1.6.2.rc1.291.g83eb
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH 09/23] refactor duplicated ref_newer() to remote.c
[not found] <cover.1235467368.git.jaysoffian@gmail.com>
` (7 preceding siblings ...)
2009-02-24 9:50 ` [PATCH 08/23] refactor duplicated get_local_heads() to remote.c Jay Soffian
@ 2009-02-24 9:50 ` Jay Soffian
2009-02-24 9:50 ` [PATCH 10/23] string-list: new for_each_string_list() function Jay Soffian
` (13 subsequent siblings)
22 siblings, 0 replies; 23+ messages in thread
From: Jay Soffian @ 2009-02-24 9:50 UTC (permalink / raw)
To: git; +Cc: Jay Soffian, Jeff King, Junio C Hamano
ref_newer() appears to have been copied from builtin-send-pack.c to
http-push.c via cut and paste. This patch moves the function and its
helper unmark_and_free() to remote.c. There was a slight difference
between the two implementations, one used TMP_MARK for the mark, the
other used 1. Per Jeff King, I went with TMP_MARK as more correct.
Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---
builtin-send-pack.c | 50 --------------------------------------------------
http-push.c | 49 -------------------------------------------------
remote.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
remote.h | 1 +
4 files changed, 50 insertions(+), 99 deletions(-)
diff --git a/builtin-send-pack.c b/builtin-send-pack.c
index 2fbfc29..9072905 100644
--- a/builtin-send-pack.c
+++ b/builtin-send-pack.c
@@ -1,6 +1,5 @@
#include "cache.h"
#include "commit.h"
-#include "tag.h"
#include "refs.h"
#include "pkt-line.h"
#include "run-command.h"
@@ -84,55 +83,6 @@ static int pack_objects(int fd, struct ref *refs, struct extra_have_objects *ext
return 0;
}
-static void unmark_and_free(struct commit_list *list, unsigned int mark)
-{
- while (list) {
- struct commit_list *temp = list;
- temp->item->object.flags &= ~mark;
- list = temp->next;
- free(temp);
- }
-}
-
-static int ref_newer(const unsigned char *new_sha1,
- const unsigned char *old_sha1)
-{
- struct object *o;
- struct commit *old, *new;
- struct commit_list *list, *used;
- int found = 0;
-
- /* Both new and old must be commit-ish and new is descendant of
- * old. Otherwise we require --force.
- */
- o = deref_tag(parse_object(old_sha1), NULL, 0);
- if (!o || o->type != OBJ_COMMIT)
- return 0;
- old = (struct commit *) o;
-
- o = deref_tag(parse_object(new_sha1), NULL, 0);
- if (!o || o->type != OBJ_COMMIT)
- return 0;
- new = (struct commit *) o;
-
- if (parse_commit(new) < 0)
- return 0;
-
- used = list = NULL;
- commit_list_insert(new, &list);
- while (list) {
- new = pop_most_recent_commit(&list, 1);
- commit_list_insert(new, &used);
- if (new == old) {
- found = 1;
- break;
- }
- }
- unmark_and_free(list, 1);
- unmark_and_free(used, 1);
- return found;
-}
-
static struct ref *remote_refs, **remote_tail;
static int receive_status(int in, struct ref *refs)
diff --git a/http-push.c b/http-push.c
index cfeed81..392533a 100644
--- a/http-push.c
+++ b/http-push.c
@@ -1843,55 +1843,6 @@ static int is_zero_sha1(const unsigned char *sha1)
return 1;
}
-static void unmark_and_free(struct commit_list *list, unsigned int mark)
-{
- while (list) {
- struct commit_list *temp = list;
- temp->item->object.flags &= ~mark;
- list = temp->next;
- free(temp);
- }
-}
-
-static int ref_newer(const unsigned char *new_sha1,
- const unsigned char *old_sha1)
-{
- struct object *o;
- struct commit *old, *new;
- struct commit_list *list, *used;
- int found = 0;
-
- /* Both new and old must be commit-ish and new is descendant of
- * old. Otherwise we require --force.
- */
- o = deref_tag(parse_object(old_sha1), NULL, 0);
- if (!o || o->type != OBJ_COMMIT)
- return 0;
- old = (struct commit *) o;
-
- o = deref_tag(parse_object(new_sha1), NULL, 0);
- if (!o || o->type != OBJ_COMMIT)
- return 0;
- new = (struct commit *) o;
-
- if (parse_commit(new) < 0)
- return 0;
-
- used = list = NULL;
- commit_list_insert(new, &list);
- while (list) {
- new = pop_most_recent_commit(&list, TMP_MARK);
- commit_list_insert(new, &used);
- if (new == old) {
- found = 1;
- break;
- }
- }
- unmark_and_free(list, TMP_MARK);
- unmark_and_free(used, TMP_MARK);
- return found;
-}
-
static void add_remote_info_ref(struct remote_ls_ctx *ls)
{
struct strbuf *buf = (struct strbuf *)ls->userData;
diff --git a/remote.c b/remote.c
index 8fd8d23..f07ecf4 100644
--- a/remote.c
+++ b/remote.c
@@ -5,6 +5,7 @@
#include "diff.h"
#include "revision.h"
#include "dir.h"
+#include "tag.h"
static struct refspec s_tag_refspec = {
0,
@@ -1274,6 +1275,54 @@ int resolve_remote_symref(struct ref *ref, struct ref *list)
return 1;
}
+static void unmark_and_free(struct commit_list *list, unsigned int mark)
+{
+ while (list) {
+ struct commit_list *temp = list;
+ temp->item->object.flags &= ~mark;
+ list = temp->next;
+ free(temp);
+ }
+}
+
+int ref_newer(const unsigned char *new_sha1, const unsigned char *old_sha1)
+{
+ struct object *o;
+ struct commit *old, *new;
+ struct commit_list *list, *used;
+ int found = 0;
+
+ /* Both new and old must be commit-ish and new is descendant of
+ * old. Otherwise we require --force.
+ */
+ o = deref_tag(parse_object(old_sha1), NULL, 0);
+ if (!o || o->type != OBJ_COMMIT)
+ return 0;
+ old = (struct commit *) o;
+
+ o = deref_tag(parse_object(new_sha1), NULL, 0);
+ if (!o || o->type != OBJ_COMMIT)
+ return 0;
+ new = (struct commit *) o;
+
+ if (parse_commit(new) < 0)
+ return 0;
+
+ used = list = NULL;
+ commit_list_insert(new, &list);
+ while (list) {
+ new = pop_most_recent_commit(&list, TMP_MARK);
+ commit_list_insert(new, &used);
+ if (new == old) {
+ found = 1;
+ break;
+ }
+ }
+ unmark_and_free(list, TMP_MARK);
+ unmark_and_free(used, TMP_MARK);
+ return found;
+}
+
/*
* Return true if there is anything to report, otherwise false.
*/
diff --git a/remote.h b/remote.h
index 6ff0cda..1f78a0a 100644
--- a/remote.h
+++ b/remote.h
@@ -74,6 +74,7 @@ int check_ref_type(const struct ref *ref, int flags);
void free_refs(struct ref *ref);
int resolve_remote_symref(struct ref *ref, struct ref *list);
+int ref_newer(const unsigned char *new_sha1, const unsigned char *old_sha1);
/*
* Removes and frees any duplicate refs in the map.
--
1.6.2.rc1.291.g83eb
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH 10/23] string-list: new for_each_string_list() function
[not found] <cover.1235467368.git.jaysoffian@gmail.com>
` (8 preceding siblings ...)
2009-02-24 9:50 ` [PATCH 09/23] refactor duplicated ref_newer() " Jay Soffian
@ 2009-02-24 9:50 ` Jay Soffian
2009-02-24 9:50 ` [PATCH 11/23] builtin-remote: rename variable and eliminate redundant function call Jay Soffian
` (12 subsequent siblings)
22 siblings, 0 replies; 23+ messages in thread
From: Jay Soffian @ 2009-02-24 9:50 UTC (permalink / raw)
To: git; +Cc: Jay Soffian, Jeff King, Junio C Hamano
Add a convenience function for iterating over a string_list's items via
a callback.
Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---
string-list.c | 10 ++++++++++
string-list.h | 5 +++++
2 files changed, 15 insertions(+), 0 deletions(-)
diff --git a/string-list.c b/string-list.c
index 15e14cf..1ac536e 100644
--- a/string-list.c
+++ b/string-list.c
@@ -92,6 +92,16 @@ struct string_list_item *string_list_lookup(const char *string, struct string_li
return list->items + i;
}
+int for_each_string_list(string_list_each_func_t fn,
+ struct string_list *list, void *cb_data)
+{
+ int i, ret = 0;
+ for (i = 0; i < list->nr; i++)
+ if ((ret = fn(&list->items[i], cb_data)))
+ break;
+ return ret;
+}
+
void string_list_clear(struct string_list *list, int free_util)
{
if (list->items) {
diff --git a/string-list.h b/string-list.h
index d32ba05..14bbc47 100644
--- a/string-list.h
+++ b/string-list.h
@@ -20,6 +20,11 @@ void string_list_clear(struct string_list *list, int free_util);
typedef void (*string_list_clear_func_t)(void *p, const char *str);
void string_list_clear_func(struct string_list *list, string_list_clear_func_t clearfunc);
+/* Use this function to iterate over each item */
+typedef int (*string_list_each_func_t)(struct string_list_item *, void *);
+int for_each_string_list(string_list_each_func_t,
+ struct string_list *list, void *cb_data);
+
/* Use these functions only on sorted lists: */
int string_list_has_string(const struct string_list *list, const char *string);
int string_list_find_insert_index(const struct string_list *list, const char *string,
--
1.6.2.rc1.291.g83eb
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH 11/23] builtin-remote: rename variable and eliminate redundant function call
[not found] <cover.1235467368.git.jaysoffian@gmail.com>
` (9 preceding siblings ...)
2009-02-24 9:50 ` [PATCH 10/23] string-list: new for_each_string_list() function Jay Soffian
@ 2009-02-24 9:50 ` Jay Soffian
2009-02-24 9:51 ` [PATCH 12/23] builtin-remote: name remote_refs consistently Jay Soffian
` (11 subsequent siblings)
22 siblings, 0 replies; 23+ messages in thread
From: Jay Soffian @ 2009-02-24 9:50 UTC (permalink / raw)
To: git; +Cc: Jay Soffian, Jeff King, Junio C Hamano
The variable name "remote" is used as both a "char *" and as a "struct
remote *"; this is confusing, so rename the former to remote_name.
There is no need to call "sort_string_list(&branch_list)" as branch_list
is populated via string_list_insert(), which maintains its order.
Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---
builtin-remote.c | 13 ++++++-------
1 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/builtin-remote.c b/builtin-remote.c
index 608c0f3..48d668e 100644
--- a/builtin-remote.c
+++ b/builtin-remote.c
@@ -144,7 +144,7 @@ static int add(int argc, const char **argv)
}
struct branch_info {
- char *remote;
+ char *remote_name;
struct string_list merge;
};
@@ -183,9 +183,9 @@ static int config_read_branches(const char *key, const char *value, void *cb)
item->util = xcalloc(sizeof(struct branch_info), 1);
info = item->util;
if (type == REMOTE) {
- if (info->remote)
+ if (info->remote_name)
warning("more than one branch.%s", key);
- info->remote = xstrdup(value);
+ info->remote_name = xstrdup(value);
} else {
char *space = strchr(value, ' ');
value = abbrev_branch(value);
@@ -207,7 +207,6 @@ static void read_branches(void)
if (branch_list.nr)
return;
git_config(config_read_branches, NULL);
- sort_string_list(&branch_list);
}
struct ref_states {
@@ -489,7 +488,7 @@ static int mv(int argc, const char **argv)
for (i = 0; i < branch_list.nr; i++) {
struct string_list_item *item = branch_list.items + i;
struct branch_info *info = item->util;
- if (info->remote && !strcmp(info->remote, rename.old)) {
+ if (info->remote_name && !strcmp(info->remote_name, rename.old)) {
strbuf_reset(&buf);
strbuf_addf(&buf, "branch.%s.remote", item->string);
if (git_config_set(buf.buf, rename.new)) {
@@ -599,7 +598,7 @@ static int rm(int argc, const char **argv)
for (i = 0; i < branch_list.nr; i++) {
struct string_list_item *item = branch_list.items + i;
struct branch_info *info = item->util;
- if (info->remote && !strcmp(info->remote, remote->name)) {
+ if (info->remote_name && !strcmp(info->remote_name, remote->name)) {
const char *keys[] = { "remote", "merge", NULL }, **k;
for (k = keys; *k; k++) {
strbuf_reset(&buf);
@@ -742,7 +741,7 @@ static int show(int argc, const char **argv)
struct branch_info *info = branch->util;
int j;
- if (!info->merge.nr || strcmp(*argv, info->remote))
+ if (!info->merge.nr || strcmp(*argv, info->remote_name))
continue;
printf(" Remote branch%s merged with 'git pull' "
"while on branch %s\n ",
--
1.6.2.rc1.291.g83eb
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH 12/23] builtin-remote: name remote_refs consistently
[not found] <cover.1235467368.git.jaysoffian@gmail.com>
` (10 preceding siblings ...)
2009-02-24 9:50 ` [PATCH 11/23] builtin-remote: rename variable and eliminate redundant function call Jay Soffian
@ 2009-02-24 9:51 ` Jay Soffian
2009-02-24 9:51 ` [PATCH 13/23] builtin-remote: remove unused code in get_ref_states Jay Soffian
` (10 subsequent siblings)
22 siblings, 0 replies; 23+ messages in thread
From: Jay Soffian @ 2009-02-24 9:51 UTC (permalink / raw)
To: git; +Cc: Jay Soffian, Jeff King, Junio C Hamano
Clarify the code a bit by consistently referring to the remote refs
returned by transport_get_remote_refs() as remote_refs.
Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---
builtin-remote.c | 19 ++++++++++---------
1 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/builtin-remote.c b/builtin-remote.c
index 48d668e..d5c808c 100644
--- a/builtin-remote.c
+++ b/builtin-remote.c
@@ -238,13 +238,14 @@ static int handle_one_branch(const char *refname,
return 0;
}
-static int get_ref_states(const struct ref *ref, struct ref_states *states)
+static int get_ref_states(const struct ref *remote_refs, struct ref_states *states)
{
struct ref *fetch_map = NULL, **tail = &fetch_map;
+ struct ref *ref;
int i;
for (i = 0; i < states->remote->fetch_refspec_nr; i++)
- if (get_fetch_map(ref, states->remote->fetch + i, &tail, 1))
+ if (get_fetch_map(remote_refs, states->remote->fetch + i, &tail, 1))
die("Could not get fetch map for refspec %s",
states->remote->fetch_refspec[i]);
@@ -271,7 +272,7 @@ static int get_ref_states(const struct ref *ref, struct ref_states *states)
return 0;
}
-static int get_head_names(const struct ref *refs,
+static int get_head_names(const struct ref *remote_refs,
const char *remote_name, struct ref_states *states)
{
struct ref *ref, *matches = NULL;
@@ -282,8 +283,8 @@ static int get_head_names(const struct ref *refs,
refspec.pattern = 1;
refspec.src = refspec.dst = "refs/heads/";
states->heads.strdup_strings = 1;
- get_fetch_map(refs, &refspec, &fetch_map_tail, 0);
- guess_remote_head(refs, fetch_map, NULL, &matches);
+ get_fetch_map(remote_refs, &refspec, &fetch_map_tail, 0);
+ guess_remote_head(remote_refs, fetch_map, NULL, &matches);
for(ref = matches; ref; ref = ref->next)
string_list_append(abbrev_branch(ref->name), &states->heads);
@@ -667,7 +668,7 @@ static int get_remote_ref_states(const char *name,
int query)
{
struct transport *transport;
- const struct ref *ref;
+ const struct ref *remote_refs;
states->remote = remote_get(name);
if (!states->remote)
@@ -678,11 +679,11 @@ static int get_remote_ref_states(const char *name,
if (query) {
transport = transport_get(NULL, states->remote->url_nr > 0 ?
states->remote->url[0] : NULL);
- ref = transport_get_remote_refs(transport);
+ remote_refs = transport_get_remote_refs(transport);
transport_disconnect(transport);
- get_head_names(ref, name, states);
- get_ref_states(ref, states);
+ get_head_names(remote_refs, name, states);
+ get_ref_states(remote_refs, states);
}
return 0;
--
1.6.2.rc1.291.g83eb
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH 13/23] builtin-remote: remove unused code in get_ref_states
[not found] <cover.1235467368.git.jaysoffian@gmail.com>
` (11 preceding siblings ...)
2009-02-24 9:51 ` [PATCH 12/23] builtin-remote: name remote_refs consistently Jay Soffian
@ 2009-02-24 9:51 ` Jay Soffian
2009-02-24 9:51 ` [PATCH 14/23] builtin-remote: fix two inconsistencies in the output of "show <remote>" Jay Soffian
` (9 subsequent siblings)
22 siblings, 0 replies; 23+ messages in thread
From: Jay Soffian @ 2009-02-24 9:51 UTC (permalink / raw)
To: git; +Cc: Jay Soffian, Jeff King, Junio C Hamano
get_ref_states() populates the util pointer of the string_list_item's
that it adds to states->new and states->tracked, but nothing ever uses
the pointer, so we can get rid of the extra code.
Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---
builtin-remote.c | 13 +++----------
1 files changed, 3 insertions(+), 10 deletions(-)
diff --git a/builtin-remote.c b/builtin-remote.c
index d5c808c..56d73c8 100644
--- a/builtin-remote.c
+++ b/builtin-remote.c
@@ -251,18 +251,11 @@ static int get_ref_states(const struct ref *remote_refs, struct ref_states *stat
states->new.strdup_strings = states->tracked.strdup_strings = 1;
for (ref = fetch_map; ref; ref = ref->next) {
- struct string_list *target = &states->tracked;
unsigned char sha1[20];
- void *util = NULL;
-
if (!ref->peer_ref || read_ref(ref->peer_ref->name, sha1))
- target = &states->new;
- else {
- target = &states->tracked;
- if (hashcmp(sha1, ref->new_sha1))
- util = &states;
- }
- string_list_append(abbrev_branch(ref->name), target)->util = util;
+ string_list_append(abbrev_branch(ref->name), &states->new);
+ else
+ string_list_append(abbrev_branch(ref->name), &states->tracked);
}
free_refs(fetch_map);
--
1.6.2.rc1.291.g83eb
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH 14/23] builtin-remote: fix two inconsistencies in the output of "show <remote>"
[not found] <cover.1235467368.git.jaysoffian@gmail.com>
` (12 preceding siblings ...)
2009-02-24 9:51 ` [PATCH 13/23] builtin-remote: remove unused code in get_ref_states Jay Soffian
@ 2009-02-24 9:51 ` Jay Soffian
2009-02-24 9:51 ` [PATCH 15/23] builtin-remote: make get_remote_ref_states() always populate states.tracked Jay Soffian
` (8 subsequent siblings)
22 siblings, 0 replies; 23+ messages in thread
From: Jay Soffian @ 2009-02-24 9:51 UTC (permalink / raw)
To: git; +Cc: Jay Soffian, Jeff King, Junio C Hamano
Remote and stale branches are emitted in alphabetical order, but new and
tracked branches are not. So sort the latter to be consistent with the
former. This also lets us use more efficient string_list_has_string()
instead of unsorted_string_list_has_string().
"show <remote>" prunes symrefs, but "show <remote> -n" does not. Fix the
latter to match the former.
Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---
builtin-remote.c | 15 ++++++++++-----
t/t5505-remote.sh | 2 +-
2 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/builtin-remote.c b/builtin-remote.c
index 56d73c8..cb56565 100644
--- a/builtin-remote.c
+++ b/builtin-remote.c
@@ -227,10 +227,8 @@ static int handle_one_branch(const char *refname,
const char *name = abbrev_branch(refspec.src);
/* symbolic refs pointing nowhere were handled already */
if ((flags & REF_ISSYMREF) ||
- unsorted_string_list_has_string(&states->tracked,
- name) ||
- unsorted_string_list_has_string(&states->new,
- name))
+ string_list_has_string(&states->tracked, name) ||
+ string_list_has_string(&states->new, name))
return 0;
item = string_list_append(name, &states->stale);
item->util = xstrdup(refname);
@@ -259,6 +257,8 @@ static int get_ref_states(const struct ref *remote_refs, struct ref_states *stat
}
free_refs(fetch_map);
+ sort_string_list(&states->new);
+ sort_string_list(&states->tracked);
for_each_ref(handle_one_branch, states);
sort_string_list(&states->stale);
@@ -688,6 +688,9 @@ static int append_ref_to_tracked_list(const char *refname,
struct ref_states *states = cb_data;
struct refspec refspec;
+ if (flags & REF_ISSYMREF)
+ return 0;
+
memset(&refspec, 0, sizeof(refspec));
refspec.dst = (char *)refname;
if (!remote_find_tracking(states->remote, &refspec))
@@ -754,8 +757,10 @@ static int show(int argc, const char **argv)
"prune')", &states.stale, "");
}
- if (no_query)
+ if (no_query) {
for_each_ref(append_ref_to_tracked_list, &states);
+ sort_string_list(&states.tracked);
+ }
show_list(" Tracked remote branch%s", &states.tracked, "");
if (states.remote->push_refspec_nr) {
diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh
index 9ea923b..56146eb 100755
--- a/t/t5505-remote.sh
+++ b/t/t5505-remote.sh
@@ -142,8 +142,8 @@ cat > test/expect << EOF
New remote branch (next fetch will store in remotes/origin)
master
Tracked remote branches
- side
master
+ side
Local branches pushed with 'git push'
master:upstream
+refs/tags/lastbackup
--
1.6.2.rc1.291.g83eb
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH 15/23] builtin-remote: make get_remote_ref_states() always populate states.tracked
[not found] <cover.1235467368.git.jaysoffian@gmail.com>
` (13 preceding siblings ...)
2009-02-24 9:51 ` [PATCH 14/23] builtin-remote: fix two inconsistencies in the output of "show <remote>" Jay Soffian
@ 2009-02-24 9:51 ` Jay Soffian
2009-02-24 9:51 ` [PATCH 16/23] builtin-remote: refactor get_remote_ref_states() Jay Soffian
` (7 subsequent siblings)
22 siblings, 0 replies; 23+ messages in thread
From: Jay Soffian @ 2009-02-24 9:51 UTC (permalink / raw)
To: git; +Cc: Jay Soffian, Jeff King, Junio C Hamano
When not querying the remote, show() was having to populate
states.tracked itself. It makes more sense for get_remote_ref_states()
to do this consistently. Since show() is the only caller of
get_remote_ref_states() with query=0, this change does not affect the
other call sites.
Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---
builtin-remote.c | 41 ++++++++++++++++++++---------------------
1 files changed, 20 insertions(+), 21 deletions(-)
diff --git a/builtin-remote.c b/builtin-remote.c
index cb56565..5ef8163 100644
--- a/builtin-remote.c
+++ b/builtin-remote.c
@@ -656,6 +656,23 @@ static void free_remote_ref_states(struct ref_states *states)
string_list_clear(&states->heads, 0);
}
+static int append_ref_to_tracked_list(const char *refname,
+ const unsigned char *sha1, int flags, void *cb_data)
+{
+ struct ref_states *states = cb_data;
+ struct refspec refspec;
+
+ if (flags & REF_ISSYMREF)
+ return 0;
+
+ memset(&refspec, 0, sizeof(refspec));
+ refspec.dst = (char *)refname;
+ if (!remote_find_tracking(states->remote, &refspec))
+ string_list_append(abbrev_branch(refspec.src), &states->tracked);
+
+ return 0;
+}
+
static int get_remote_ref_states(const char *name,
struct ref_states *states,
int query)
@@ -677,28 +694,14 @@ static int get_remote_ref_states(const char *name,
get_head_names(remote_refs, name, states);
get_ref_states(remote_refs, states);
+ } else {
+ for_each_ref(append_ref_to_tracked_list, states);
+ sort_string_list(&states->tracked);
}
return 0;
}
-static int append_ref_to_tracked_list(const char *refname,
- const unsigned char *sha1, int flags, void *cb_data)
-{
- struct ref_states *states = cb_data;
- struct refspec refspec;
-
- if (flags & REF_ISSYMREF)
- return 0;
-
- memset(&refspec, 0, sizeof(refspec));
- refspec.dst = (char *)refname;
- if (!remote_find_tracking(states->remote, &refspec))
- string_list_append(abbrev_branch(refspec.src), &states->tracked);
-
- return 0;
-}
-
static int show(int argc, const char **argv)
{
int no_query = 0, result = 0;
@@ -757,10 +760,6 @@ static int show(int argc, const char **argv)
"prune')", &states.stale, "");
}
- if (no_query) {
- for_each_ref(append_ref_to_tracked_list, &states);
- sort_string_list(&states.tracked);
- }
show_list(" Tracked remote branch%s", &states.tracked, "");
if (states.remote->push_refspec_nr) {
--
1.6.2.rc1.291.g83eb
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH 16/23] builtin-remote: refactor get_remote_ref_states()
[not found] <cover.1235467368.git.jaysoffian@gmail.com>
` (14 preceding siblings ...)
2009-02-24 9:51 ` [PATCH 15/23] builtin-remote: make get_remote_ref_states() always populate states.tracked Jay Soffian
@ 2009-02-24 9:51 ` Jay Soffian
2009-02-24 9:51 ` [PATCH 17/23] builtin-remote: new show output style Jay Soffian
` (6 subsequent siblings)
22 siblings, 0 replies; 23+ messages in thread
From: Jay Soffian @ 2009-02-24 9:51 UTC (permalink / raw)
To: git; +Cc: Jay Soffian, Jeff King, Junio C Hamano
get_remote_ref_states() has three callers, but each is interested in
slightly different information. Give it a bit-field flag so that callers
can specify which pieces of information they need.
Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---
builtin-remote.c | 21 ++++++++++++++-------
1 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/builtin-remote.c b/builtin-remote.c
index 5ef8163..a822bd5 100644
--- a/builtin-remote.c
+++ b/builtin-remote.c
@@ -19,6 +19,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);
@@ -691,9 +694,10 @@ static int get_remote_ref_states(const char *name,
states->remote->url[0] : NULL);
remote_refs = transport_get_remote_refs(transport);
transport_disconnect(transport);
-
- get_head_names(remote_refs, name, states);
- 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, name, states);
} else {
for_each_ref(append_ref_to_tracked_list, states);
sort_string_list(&states->tracked);
@@ -704,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"),
@@ -717,11 +721,14 @@ 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 ?
@@ -805,7 +812,7 @@ static int set_head(int argc, const char **argv)
} else if (opt_a && !opt_d && argc == 1) {
struct ref_states states;
memset(&states, 0, sizeof(states));
- get_remote_ref_states(argv[0], &states, 1);
+ get_remote_ref_states(argv[0], &states, GET_HEAD_NAMES);
if (!states.heads.nr)
result |= error("Cannot determine remote HEAD");
else if (states.heads.nr > 1) {
@@ -865,7 +872,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);
--
1.6.2.rc1.291.g83eb
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH 17/23] builtin-remote: new show output style
[not found] <cover.1235467368.git.jaysoffian@gmail.com>
` (15 preceding siblings ...)
2009-02-24 9:51 ` [PATCH 16/23] builtin-remote: refactor get_remote_ref_states() Jay Soffian
@ 2009-02-24 9:51 ` Jay Soffian
2009-02-24 9:51 ` [PATCH 18/23] builtin-remote: new show output style for push refspecs Jay Soffian
` (5 subsequent siblings)
22 siblings, 0 replies; 23+ messages in thread
From: Jay Soffian @ 2009-02-24 9:51 UTC (permalink / raw)
To: git; +Cc: Jay Soffian, Jeff King, Junio C Hamano
The existing output of "git remote show <remote>" is too verbose for the
information it provides. This patch teaches it to provide more
information in less space.
The output for push refspecs is addressed in followup patch.
Before the patch:
$ git remote show origin
* remote origin
URL: git://git.kernel.org/pub/scm/git/git.git
HEAD branch: master
Remote branch merged with 'git pull' while on branch master
master
Remote branch merged with 'git pull' while on branch next
next
Remote branches merged with 'git pull' while on branch octopus
foo bar baz frotz
New remote branch (next fetch will store in remotes/origin)
html
Stale tracking branch (use 'git remote prune')
bogus
Tracked remote branches
maint
man
master
next
pu
todo
After this patch:
$ git remote show origin
* remote origin
URL: git://git.kernel.org/pub/scm/git/git.git
HEAD branch: master
Remote branches:
bogus stale (use 'git remote prune' to remove)
html new (next fetch will store in remotes/origin)
maint tracked
man tracked
master tracked
next tracked
pu tracked
todo tracked
Local branches configured for 'git pull':
master rebases onto remote master
next rebases onto remote next
octopus merges with remote foo
and with remote bar
and with remote baz
and with remote frotz
$ git remote show origin -n
* remote origin
URL: git://git.kernel.org/pub/scm/git/git.git
HEAD branch: (not queried)
Remote branches: (status not queried)
bogus
maint
man
master
next
pu
todo
Local branches configured for 'git pull':
master rebases onto remote master
next rebases onto remote next
octopus merges with remote foo
and with remote bar
and with remote baz
and with remote frotz
Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---
builtin-remote.c | 190 ++++++++++++++++++++++++++++++++++++++++-------------
t/t5505-remote.sh | 31 +++++----
2 files changed, 162 insertions(+), 59 deletions(-)
diff --git a/builtin-remote.c b/builtin-remote.c
index a822bd5..852f779 100644
--- a/builtin-remote.c
+++ b/builtin-remote.c
@@ -149,6 +149,7 @@ static int add(int argc, const char **argv)
struct branch_info {
char *remote_name;
struct string_list merge;
+ int rebase;
};
static struct string_list branch_list;
@@ -165,10 +166,11 @@ static const char *abbrev_ref(const char *name, const char *prefix)
static int config_read_branches(const char *key, const char *value, void *cb)
{
if (!prefixcmp(key, "branch.")) {
+ const char *orig_key = key;
char *name;
struct string_list_item *item;
struct branch_info *info;
- enum { REMOTE, MERGE } type;
+ enum { REMOTE, MERGE, REBASE } type;
key += 7;
if (!postfixcmp(key, ".remote")) {
@@ -177,6 +179,9 @@ static int config_read_branches(const char *key, const char *value, void *cb)
} else if (!postfixcmp(key, ".merge")) {
name = xstrndup(key, strlen(key) - 6);
type = MERGE;
+ } else if (!postfixcmp(key, ".rebase")) {
+ name = xstrndup(key, strlen(key) - 7);
+ type = REBASE;
} else
return 0;
@@ -187,9 +192,9 @@ static int config_read_branches(const char *key, const char *value, void *cb)
info = item->util;
if (type == REMOTE) {
if (info->remote_name)
- warning("more than one branch.%s", key);
+ warning("more than one %s", orig_key);
info->remote_name = xstrdup(value);
- } else {
+ } else if (type == MERGE) {
char *space = strchr(value, ' ');
value = abbrev_branch(value);
while (space) {
@@ -200,7 +205,8 @@ static int config_read_branches(const char *key, const char *value, void *cb)
space = strchr(value, ' ');
}
string_list_append(xstrdup(value), &info->merge);
- }
+ } else
+ info->rebase = git_config_bool(orig_key, value);
}
return 0;
}
@@ -215,6 +221,7 @@ static void read_branches(void)
struct ref_states {
struct remote *remote;
struct string_list new, stale, tracked, heads;
+ int queried;
};
static int handle_one_branch(const char *refname,
@@ -637,20 +644,6 @@ static int rm(int argc, const char **argv)
return result;
}
-static void show_list(const char *title, struct string_list *list,
- const char *extra_arg)
-{
- int i;
-
- if (!list->nr)
- return;
-
- printf(title, list->nr > 1 ? "es" : "", extra_arg);
- printf("\n");
- for (i = 0; i < list->nr; i++)
- printf(" %s\n", list->items[i].string);
-}
-
static void free_remote_ref_states(struct ref_states *states)
{
string_list_clear(&states->new, 0);
@@ -694,6 +687,7 @@ static int get_remote_ref_states(const char *name,
states->remote->url[0] : NULL);
remote_refs = transport_get_remote_refs(transport);
transport_disconnect(transport);
+ states->queried = 1;
if (query & GET_REF_STATES)
get_ref_states(remote_refs, states);
if (query & GET_HEAD_NAMES)
@@ -702,6 +696,103 @@ static int get_remote_ref_states(const char *name,
for_each_ref(append_ref_to_tracked_list, states);
sort_string_list(&states->tracked);
}
+ return 0;
+}
+
+struct show_info {
+ struct string_list *list;
+ struct ref_states *states;
+ int width;
+ int any_rebase;
+};
+
+int add_remote_to_show_info(struct string_list_item *item, void *cb_data)
+{
+ struct show_info *info = cb_data;
+ int n = strlen(item->string);
+ if (n > info->width)
+ info->width = n;
+ string_list_insert(item->string, info->list);
+ return 0;
+}
+
+int show_remote_info_item(struct string_list_item *item, void *cb_data)
+{
+ struct show_info *info = cb_data;
+ struct ref_states *states = info->states;
+ const char *name = item->string;
+
+ if (states->queried) {
+ const char *fmt = "%s";
+ const char *arg = "";
+ if (string_list_has_string(&states->new, name)) {
+ fmt = " new (next fetch will store in remotes/%s)";
+ arg = states->remote->name;
+ } else if (string_list_has_string(&states->tracked, name))
+ arg = " tracked";
+ else if (string_list_has_string(&states->stale, name))
+ arg = " stale (use 'git remote prune' to remove)";
+ else
+ arg = " ???";
+ printf(" %-*s", info->width, name);
+ printf(fmt, arg);
+ printf("\n");
+ } else
+ printf(" %s\n", name);
+
+ return 0;
+}
+
+int add_local_to_show_info(struct string_list_item *branch_item, void *cb_data)
+{
+ struct show_info *show_info = cb_data;
+ struct ref_states *states = show_info->states;
+ struct branch_info *branch_info = branch_item->util;
+ struct string_list_item *item;
+ int n;
+
+ if (!branch_info->merge.nr || !branch_info->remote_name ||
+ strcmp(states->remote->name, branch_info->remote_name))
+ return 0;
+ if ((n = strlen(branch_item->string)) > show_info->width)
+ show_info->width = n;
+ if (branch_info->rebase)
+ show_info->any_rebase = 1;
+
+ item = string_list_insert(branch_item->string, show_info->list);
+ item->util = branch_info;
+
+ return 0;
+}
+
+int show_local_info_item(struct string_list_item *item, void *cb_data)
+{
+ struct show_info *show_info = cb_data;
+ struct branch_info *branch_info = item->util;
+ struct string_list *merge = &branch_info->merge;
+ const char *also;
+ int i;
+
+ if (branch_info->rebase && branch_info->merge.nr > 1) {
+ error("invalid branch.%s.merge; cannot rebase onto > 1 branch",
+ item->string);
+ return 0;
+ }
+
+ printf(" %-*s ", show_info->width, item->string);
+ if (branch_info->rebase) {
+ printf("rebases onto remote %s\n", merge->items[0].string);
+ return 0;
+ } else if (show_info->any_rebase) {
+ printf(" merges with remote %s\n", merge->items[0].string);
+ also = " and with remote";
+ } else {
+ printf("merges with remote %s\n", merge->items[0].string);
+ also = " and with remote";
+ }
+ for (i = 1; i < merge->nr; i++)
+ printf(" %-*s %s %s\n", show_info->width, "", also,
+ merge->items[i].string);
return 0;
}
@@ -715,6 +806,8 @@ static int show(int argc, const char **argv)
OPT_END()
};
struct ref_states states;
+ struct string_list info_list = { NULL, 0, 0, 0 };
+ struct show_info info;
argc = parse_options(argc, argv, options, builtin_remote_usage, 0);
@@ -725,6 +818,9 @@ static int show(int argc, const char **argv)
query_flag = (GET_REF_STATES | GET_HEAD_NAMES);
memset(&states, 0, sizeof(states));
+ memset(&info, 0, sizeof(info));
+ info.states = &states;
+ info.list = &info_list;
for (; argc; argc--, argv++) {
int i;
@@ -738,37 +834,37 @@ static int show(int argc, const char **argv)
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
- show_list(" HEAD branch%s:", &states.heads, "");
-
- for (i = 0; i < branch_list.nr; i++) {
- struct string_list_item *branch = branch_list.items + i;
- struct branch_info *info = branch->util;
- int j;
-
- if (!info->merge.nr || strcmp(*argv, info->remote_name))
- continue;
- printf(" Remote branch%s merged with 'git pull' "
- "while on branch %s\n ",
- info->merge.nr > 1 ? "es" : "",
- branch->string);
- for (j = 0; j < info->merge.nr; j++)
- printf(" %s", info->merge.items[j].string);
- printf("\n");
- }
-
- if (!no_query) {
- show_list(" New remote branch%s (next fetch "
- "will store in remotes/%s)",
- &states.new, states.remote->name);
- show_list(" Stale tracking branch%s (use 'git remote "
- "prune')", &states.stale, "");
+ 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);
}
- show_list(" Tracked remote branch%s", &states.tracked, "");
-
+ /* remote branch info */
+ info.width = 0;
+ for_each_string_list(add_remote_to_show_info, &states.new, &info);
+ for_each_string_list(add_remote_to_show_info, &states.tracked, &info);
+ for_each_string_list(add_remote_to_show_info, &states.stale, &info);
+ if (info.list->nr)
+ printf(" Remote branch%s:%s\n",
+ info.list->nr > 1 ? "es" : "",
+ no_query ? " (status not queried)" : "");
+ for_each_string_list(show_remote_info_item, info.list, &info);
+ string_list_clear(info.list, 0);
+
+ /* git pull info */
+ info.width = 0;
+ info.any_rebase = 0;
+ for_each_string_list(add_local_to_show_info, &branch_list, &info);
+ if (info.list->nr)
+ printf(" Local branch%s configured for 'git pull':\n",
+ info.list->nr > 1 ? "es" : "");
+ for_each_string_list(show_local_info_item, info.list, &info);
+ string_list_clear(info.list, 0);
+
+ /* git push info */
if (states.remote->push_refspec_nr) {
printf(" Local branch%s pushed with 'git push'\n",
states.remote->push_refspec_nr > 1 ?
diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh
index 56146eb..835adbd 100755
--- a/t/t5505-remote.sh
+++ b/t/t5505-remote.sh
@@ -28,7 +28,7 @@ tokens_match () {
}
check_remote_track () {
- actual=$(git remote show "$1" | sed -e '1,/Tracked/d') &&
+ actual=$(git remote show "$1" | sed -ne 's|^ \(.*\) tracked$|\1|p')
shift &&
tokens_match "$*" "$actual"
}
@@ -137,19 +137,21 @@ 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)
- master
- Tracked remote branches
- master
- side
+ Remote branches:
+ master new (next fetch will store in remotes/origin)
+ side tracked
+ Local branches configured for 'git pull':
+ foo rebases onto remote master
+ master merges with remote master
+ oct merges with remote topic-a
+ and with remote topic-b
+ and with remote topic-c
Local branches pushed with 'git push'
master:upstream
+refs/tags/lastbackup
* remote two
URL: ../two
- HEAD branches:
+ HEAD branch (remote HEAD is ambiguous, may be one of the following):
another
master
EOF
@@ -159,8 +161,12 @@ test_expect_success 'show' '
git config --add remote.origin.fetch \
refs/heads/master:refs/heads/upstream &&
git fetch &&
+ git branch --track oct origin/master &&
+ git branch --track foo origin/master &&
git branch -d -r origin/master &&
git config --add remote.two.url ../two &&
+ git config branch.foo.rebase true &&
+ git config branch.oct.merge "topic-a topic-b topic-c" &&
(cd ../one &&
echo 1 > file &&
test_tick &&
@@ -170,6 +176,7 @@ test_expect_success 'show' '
git config --add remote.origin.push \
+refs/tags/lastbackup &&
git remote show origin two > output &&
+ git branch -d foo oct &&
test_cmp expect output)
'
@@ -177,11 +184,11 @@ 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
+ Remote branches: (status not queried)
master
side
+ Local branch configured for 'git pull':
+ master merges with remote master
Local branches pushed with 'git push'
master:upstream
+refs/tags/lastbackup
--
1.6.2.rc1.291.g83eb
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH 18/23] builtin-remote: new show output style for push refspecs
[not found] <cover.1235467368.git.jaysoffian@gmail.com>
` (16 preceding siblings ...)
2009-02-24 9:51 ` [PATCH 17/23] builtin-remote: new show output style Jay Soffian
@ 2009-02-24 9:51 ` Jay Soffian
2009-02-24 9:51 ` [PATCH 19/23] test scripts: refactor start_httpd helper Jay Soffian
` (4 subsequent siblings)
22 siblings, 0 replies; 23+ messages in thread
From: Jay Soffian @ 2009-02-24 9:51 UTC (permalink / raw)
To: git; +Cc: Jay Soffian, Jeff King, Junio C Hamano
The existing output of "git remote show <remote>" with respect to push
ref specs is basically just to show the raw refspec. This patch teaches
the command to interpret the refspecs and show how each branch will be
pushed to the destination. The output gives the user an idea of what
"git push" should do if it is run w/o any arguments.
Example new output:
1a. Typical output with no push refspec (i.e. matching branches only)
$ git remote show origin
* remote origin
[...]
Local refs configured for 'git push':
master pushes to master (up to date)
next pushes to next (local out of date)
1b. Same as above, w/o querying the remote:
$ git remote show origin -n
* remote origin
[...]
Local ref configured for 'git push' (status not queried):
(matching) pushes to (matching)
2a. With a forcing refspec (+), and a new topic
(something like push = refs/heads/*:refs/heads/*):
$ git remote show origin
* remote origin
[...]
Local refs configured for 'git push':
master pushes to master (fast forwardable)
new-topic pushes to new-topic (create)
next pushes to next (local out of date)
pu forces to pu (up to date)
2b. Same as above, w/o querying the remote
$ git remote show origin -n
* remote origin
[...]
Local refs configured for 'git push' (status not queried):
master pushes to master
new-topic pushes to new-topic
next pushes to next
pu forces to pu
3. With a remote configured as a mirror:
* remote backup
[...]
Local refs will be mirrored by 'git push'
Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---
builtin-remote.c | 201 ++++++++++++++++++++++++++++++++++++++++++++++++----
t/t5505-remote.sh | 57 +++++++++------
2 files changed, 219 insertions(+), 39 deletions(-)
diff --git a/builtin-remote.c b/builtin-remote.c
index 852f779..80ab7af 100644
--- a/builtin-remote.c
+++ b/builtin-remote.c
@@ -21,6 +21,7 @@ static const char * const builtin_remote_usage[] = {
#define GET_REF_STATES (1<<0)
#define GET_HEAD_NAMES (1<<1)
+#define GET_PUSH_REF_STATES (1<<2)
static int verbose;
@@ -220,7 +221,7 @@ static void read_branches(void)
struct ref_states {
struct remote *remote;
- struct string_list new, stale, tracked, heads;
+ struct string_list new, stale, tracked, push, heads;
int queried;
};
@@ -275,6 +276,112 @@ static int get_ref_states(const struct ref *remote_refs, struct ref_states *stat
return 0;
}
+struct push_info {
+ char *dest;
+ int forced;
+ enum {
+ PUSH_STATUS_CREATE = 0,
+ PUSH_STATUS_DELETE,
+ PUSH_STATUS_UPTODATE,
+ PUSH_STATUS_FASTFORWARD,
+ PUSH_STATUS_OUTOFDATE,
+ PUSH_STATUS_NOTQUERIED,
+ } status;
+};
+
+static int get_push_ref_states(const struct ref *remote_refs,
+ struct ref_states *states)
+{
+ struct remote *remote = states->remote;
+ struct ref *ref, *local_refs, *push_map, **push_tail;
+ if (remote->mirror)
+ return 0;
+
+ local_refs = get_local_heads();
+ ref = push_map = copy_ref_list(remote_refs);
+ while (ref->next)
+ ref = ref->next;
+ push_tail = &ref->next;
+
+ match_refs(local_refs, push_map, &push_tail, remote->push_refspec_nr,
+ remote->push_refspec, MATCH_REFS_NONE);
+
+ states->push.strdup_strings = 1;
+ for (ref = push_map; ref; ref = ref->next) {
+ struct string_list_item *item;
+ struct push_info *info;
+
+ if (!ref->peer_ref)
+ continue;
+ hashcpy(ref->new_sha1, ref->peer_ref->new_sha1);
+
+ item = string_list_append(abbrev_branch(ref->peer_ref->name),
+ &states->push);
+ item->util = xcalloc(sizeof(struct push_info), 1);
+ info = item->util;
+ info->forced = ref->force;
+ info->dest = xstrdup(abbrev_branch(ref->name));
+
+ if (is_null_sha1(ref->new_sha1)) {
+ info->status = PUSH_STATUS_DELETE;
+ } else if (!hashcmp(ref->old_sha1, ref->new_sha1))
+ info->status = PUSH_STATUS_UPTODATE;
+ else if (is_null_sha1(ref->old_sha1))
+ info->status = PUSH_STATUS_CREATE;
+ else if (has_sha1_file(ref->old_sha1) &&
+ ref_newer(ref->new_sha1, ref->old_sha1))
+ info->status = PUSH_STATUS_FASTFORWARD;
+ else
+ info->status = PUSH_STATUS_OUTOFDATE;
+ // ref->peer_ref = NULL; /* local ref which is freed below */
+ }
+ free_refs(local_refs);
+ free_refs(push_map);
+ return 0;
+}
+
+static int get_push_ref_states_noquery(struct ref_states *states)
+{
+ int i;
+ struct remote *remote = states->remote;
+ struct string_list_item *item;
+ struct push_info *info;
+
+ if (remote->mirror)
+ return 0;
+
+ states->push.strdup_strings = 1;
+ if (!remote->push_refspec_nr) {
+ item = string_list_append("(matching)", &states->push);
+ info = item->util = xcalloc(sizeof(struct push_info), 1);
+ info->status = PUSH_STATUS_NOTQUERIED;
+ info->dest = xstrdup(item->string);
+ }
+ for (i = 0; i < remote->push_refspec_nr; i++) {
+ struct refspec *spec = remote->push + i;
+ char buf[PATH_MAX];
+ if (spec->matching)
+ item = string_list_append("(matching)", &states->push);
+ else if (spec->pattern) {
+ snprintf(buf, (sizeof(buf)), "%s*", spec->src);
+ item = string_list_append(buf, &states->push);
+ snprintf(buf, (sizeof(buf)), "%s*", spec->dst);
+ } else if (strlen(spec->src))
+ item = string_list_append(spec->src, &states->push);
+ else
+ item = string_list_append("(delete)", &states->push);
+
+ info = item->util = xcalloc(sizeof(struct push_info), 1);
+ info->forced = spec->force;
+ info->status = PUSH_STATUS_NOTQUERIED;
+ if (spec->pattern)
+ info->dest = xstrdup(buf);
+ else
+ info->dest = xstrdup(spec->dst ? spec->dst : item->string);
+ }
+ return 0;
+}
+
static int get_head_names(const struct ref *remote_refs,
const char *remote_name, struct ref_states *states)
{
@@ -644,12 +751,20 @@ static int rm(int argc, const char **argv)
return result;
}
+void clear_push_info(void *util, const char *string)
+{
+ struct push_info *info = util;
+ free(info->dest);
+ free(info);
+}
+
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);
+ string_list_clear_func(&states->push, clear_push_info);
}
static int append_ref_to_tracked_list(const char *refname,
@@ -692,9 +807,12 @@ static int get_remote_ref_states(const char *name,
get_ref_states(remote_refs, states);
if (query & GET_HEAD_NAMES)
get_head_names(remote_refs, name, states);
+ if (query & GET_PUSH_REF_STATES)
+ get_push_ref_states(remote_refs, states);
} else {
for_each_ref(append_ref_to_tracked_list, states);
sort_string_list(&states->tracked);
+ get_push_ref_states_noquery(states);
}
return 0;
}
@@ -702,7 +820,7 @@ static int get_remote_ref_states(const char *name,
struct show_info {
struct string_list *list;
struct ref_states *states;
- int width;
+ int width, width2;
int any_rebase;
};
@@ -797,6 +915,58 @@ int show_local_info_item(struct string_list_item *item, void *cb_data)
return 0;
}
+int add_push_to_show_info(struct string_list_item *push_item, void *cb_data)
+{
+ struct show_info *show_info = cb_data;
+ struct push_info *push_info = push_item->util;
+ struct string_list_item *item;
+ int n;
+ if ((n = strlen(push_item->string)) > show_info->width)
+ show_info->width = n;
+ if ((n = strlen(push_info->dest)) > show_info->width2)
+ show_info->width2 = n;
+ item = string_list_append(push_item->string, show_info->list);
+ item->util = push_item->util;
+ return 0;
+}
+
+int show_push_info_item(struct string_list_item *item, void *cb_data)
+{
+ struct show_info *show_info = cb_data;
+ struct push_info *push_info = item->util;
+ char *src = item->string, *status = NULL;
+
+ switch (push_info->status) {
+ case PUSH_STATUS_CREATE:
+ status = "create";
+ break;
+ case PUSH_STATUS_DELETE:
+ status = "delete";
+ src = "(none)";
+ break;
+ case PUSH_STATUS_UPTODATE:
+ status = "up to date";
+ break;
+ case PUSH_STATUS_FASTFORWARD:
+ status = "fast forwardable";
+ break;
+ case PUSH_STATUS_OUTOFDATE:
+ status = "local out of date";
+ break;
+ case PUSH_STATUS_NOTQUERIED:
+ break;
+ }
+ if (status)
+ printf(" %-*s %s to %-*s (%s)\n", show_info->width, src,
+ push_info->forced ? "forces" : "pushes",
+ show_info->width2, push_info->dest, status);
+ else
+ printf(" %-*s %s to %s\n", show_info->width, src,
+ push_info->forced ? "forces" : "pushes",
+ push_info->dest);
+ return 0;
+}
+
static int show(int argc, const char **argv)
{
int no_query = 0, result = 0, query_flag = 0;
@@ -815,7 +985,7 @@ static int show(int argc, const char **argv)
return show_all();
if (!no_query)
- query_flag = (GET_REF_STATES | GET_HEAD_NAMES);
+ query_flag = (GET_REF_STATES | GET_HEAD_NAMES | GET_PUSH_REF_STATES);
memset(&states, 0, sizeof(states));
memset(&info, 0, sizeof(info));
@@ -865,19 +1035,18 @@ static int show(int argc, const char **argv)
string_list_clear(info.list, 0);
/* git push info */
- if (states.remote->push_refspec_nr) {
- printf(" Local branch%s pushed with 'git push'\n",
- states.remote->push_refspec_nr > 1 ?
- "es" : "");
- for (i = 0; i < states.remote->push_refspec_nr; i++) {
- struct refspec *spec = states.remote->push + i;
- printf(" %s%s%s%s\n",
- spec->force ? "+" : "",
- abbrev_branch(spec->src),
- spec->dst ? ":" : "",
- spec->dst ? abbrev_branch(spec->dst) : "");
- }
- }
+ if (states.remote->mirror)
+ printf(" Local refs will be mirrored by 'git push'\n");
+
+ info.width = info.width2 = 0;
+ for_each_string_list(add_push_to_show_info, &states.push, &info);
+ sort_string_list(info.list);
+ if (info.list->nr)
+ printf(" Local ref%s configured for 'git push'%s:\n",
+ info.list->nr > 1 ? "s" : "",
+ no_query ? " (status not queried)" : "");
+ for_each_string_list(show_push_info_item, info.list, &info);
+ string_list_clear(info.list, 0);
free_remote_ref_states(&states);
}
diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh
index 835adbd..5ec668d 100755
--- a/t/t5505-remote.sh
+++ b/t/t5505-remote.sh
@@ -141,42 +141,51 @@ cat > test/expect << EOF
master new (next fetch will store in remotes/origin)
side tracked
Local branches configured for 'git pull':
- foo rebases onto remote master
- master merges with remote master
- oct merges with remote topic-a
- and with remote topic-b
- and with remote topic-c
- Local branches pushed with 'git push'
- master:upstream
- +refs/tags/lastbackup
+ ahead merges with remote master
+ master merges with remote master
+ octopus merges with remote topic-a
+ and with remote topic-b
+ and with remote topic-c
+ rebase rebases onto remote master
+ Local refs configured for 'git push':
+ master pushes to master (local out of date)
+ master pushes to upstream (create)
* remote two
URL: ../two
HEAD branch (remote HEAD is ambiguous, may be one of the following):
another
master
+ Local refs configured for 'git push':
+ ahead forces to master (fast forwardable)
+ master pushes to another (up to date)
EOF
test_expect_success 'show' '
(cd test &&
- git config --add remote.origin.fetch \
- refs/heads/master:refs/heads/upstream &&
+ git config --add remote.origin.fetch refs/heads/master:refs/heads/upstream &&
git fetch &&
- git branch --track oct origin/master &&
- git branch --track foo origin/master &&
+ git checkout -b ahead origin/master &&
+ echo 1 >> file &&
+ test_tick &&
+ git commit -m update file &&
+ git checkout master &&
+ git branch --track octopus origin/master &&
+ git branch --track rebase origin/master &&
git branch -d -r origin/master &&
git config --add remote.two.url ../two &&
- git config branch.foo.rebase true &&
- git config branch.oct.merge "topic-a topic-b topic-c" &&
+ git config branch.rebase.rebase true &&
+ git config branch.octopus.merge "topic-a topic-b topic-c" &&
(cd ../one &&
echo 1 > file &&
test_tick &&
git commit -m update file) &&
- git config remote.origin.push \
- refs/heads/master:refs/heads/upstream &&
- git config --add remote.origin.push \
- +refs/tags/lastbackup &&
+ git config --add remote.origin.push : &&
+ git config --add remote.origin.push refs/heads/master:refs/heads/upstream &&
+ git config --add remote.origin.push +refs/tags/lastbackup &&
+ git config --add remote.two.push +refs/heads/ahead:refs/heads/master &&
+ git config --add remote.two.push refs/heads/master:refs/heads/another &&
git remote show origin two > output &&
- git branch -d foo oct &&
+ git branch -d rebase octopus &&
test_cmp expect output)
'
@@ -187,11 +196,13 @@ cat > test/expect << EOF
Remote branches: (status not queried)
master
side
- Local branch configured for 'git pull':
+ Local branches configured for 'git pull':
+ ahead merges with remote master
master merges with remote master
- Local branches pushed with 'git push'
- master:upstream
- +refs/tags/lastbackup
+ Local refs configured for 'git push' (status not queried):
+ (matching) pushes to (matching)
+ refs/heads/master pushes to refs/heads/upstream
+ refs/tags/lastbackup forces to refs/tags/lastbackup
EOF
test_expect_success 'show -n' '
--
1.6.2.rc1.291.g83eb
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH 19/23] test scripts: refactor start_httpd helper
[not found] <cover.1235467368.git.jaysoffian@gmail.com>
` (17 preceding siblings ...)
2009-02-24 9:51 ` [PATCH 18/23] builtin-remote: new show output style for push refspecs Jay Soffian
@ 2009-02-24 9:51 ` Jay Soffian
2009-02-24 9:51 ` [PATCH 20/23] add basic http clone/fetch tests Jay Soffian
` (3 subsequent siblings)
22 siblings, 0 replies; 23+ messages in thread
From: Jay Soffian @ 2009-02-24 9:51 UTC (permalink / raw)
To: git; +Cc: Jay Soffian, Jeff King, Junio C Hamano
From: Jeff King <peff@peff.net>
There are some redirects and some error checking that need
to be done by the caller; let's move both into the
start_httpd function so that all callers don't have to
repeat them (there is only one caller now, but another will
follow in this series).
This doesn't violate any assumptions that aren't already
being made by lib-httpd, which is happy to say "skipping"
and call test_done for a number of other cases.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---
t/lib-httpd.sh | 9 +++++++--
t/t5540-http-push.sh | 8 +-------
2 files changed, 8 insertions(+), 9 deletions(-)
diff --git a/t/lib-httpd.sh b/t/lib-httpd.sh
index 3824020..88cfc51 100644
--- a/t/lib-httpd.sh
+++ b/t/lib-httpd.sh
@@ -82,13 +82,18 @@ prepare_httpd() {
}
start_httpd() {
- prepare_httpd
+ prepare_httpd >&3 2>&4
trap 'stop_httpd; die' EXIT
"$LIB_HTTPD_PATH" -d "$HTTPD_ROOT_PATH" \
-f "$TEST_PATH/apache.conf" $HTTPD_PARA \
- -c "Listen 127.0.0.1:$LIB_HTTPD_PORT" -k start
+ -c "Listen 127.0.0.1:$LIB_HTTPD_PORT" -k start \
+ >&3 2>&4
+ if ! test $? = 0; then
+ say "skipping test, web server setup failed"
+ test_done
+ fi
}
stop_httpd() {
diff --git a/t/t5540-http-push.sh b/t/t5540-http-push.sh
index 11b3432..57a4411 100755
--- a/t/t5540-http-push.sh
+++ b/t/t5540-http-push.sh
@@ -20,13 +20,7 @@ then
fi
. "$TEST_DIRECTORY"/lib-httpd.sh
-
-if ! start_httpd >&3 2>&4
-then
- say "skipping test, web server setup failed"
- test_done
- exit
-fi
+start_httpd
test_expect_success 'setup remote repository' '
cd "$ROOT_PATH" &&
--
1.6.2.rc1.291.g83eb
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH 20/23] add basic http clone/fetch tests
[not found] <cover.1235467368.git.jaysoffian@gmail.com>
` (18 preceding siblings ...)
2009-02-24 9:51 ` [PATCH 19/23] test scripts: refactor start_httpd helper Jay Soffian
@ 2009-02-24 9:51 ` Jay Soffian
2009-02-24 9:51 ` [PATCH 21/23] refactor find_refs_by_name to accept const list Jay Soffian
` (2 subsequent siblings)
22 siblings, 0 replies; 23+ messages in thread
From: Jay Soffian @ 2009-02-24 9:51 UTC (permalink / raw)
To: git; +Cc: Jay Soffian, Jeff King, Junio C Hamano
From: Jeff King <peff@peff.net>
This was mostly being tested implicitly by the "http push"
tests. But making a separate test script means that:
- we will run fetch tests even when http pushing support
is not built
- when there are failures on fetching, they are easier to
see and isolate, as they are not in the middle of push
tests
This script defaults to running the webserver on port 5550,
and puts the original t5540 on port 5540, so that the two
can be run simultaneously without conflict (but both still
respect an externally set LIB_HTTPD_PORT).
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---
Makefile | 1 +
t/t5540-http-push.sh | 1 +
t/t5550-http-fetch.sh | 46 ++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 48 insertions(+), 0 deletions(-)
create mode 100755 t/t5550-http-fetch.sh
diff --git a/Makefile b/Makefile
index b040a96..5e54c9c 100644
--- a/Makefile
+++ b/Makefile
@@ -1363,6 +1363,7 @@ GIT-CFLAGS: .FORCE-GIT-CFLAGS
GIT-BUILD-OPTIONS: .FORCE-GIT-BUILD-OPTIONS
@echo SHELL_PATH=\''$(subst ','\'',$(SHELL_PATH_SQ))'\' >$@
@echo TAR=\''$(subst ','\'',$(subst ','\'',$(TAR)))'\' >>$@
+ @echo NO_CURL=\''$(subst ','\'',$(subst ','\'',$(NO_CURL)))'\' >>$@
### Detect Tck/Tk interpreter path changes
ifndef NO_TCLTK
diff --git a/t/t5540-http-push.sh b/t/t5540-http-push.sh
index 57a4411..cefab45 100755
--- a/t/t5540-http-push.sh
+++ b/t/t5540-http-push.sh
@@ -11,6 +11,7 @@ This test runs various sanity checks on http-push.'
ROOT_PATH="$PWD"
LIB_HTTPD_DAV=t
+LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5540'}
if git http-push > /dev/null 2>&1 || [ $? -eq 128 ]
then
diff --git a/t/t5550-http-fetch.sh b/t/t5550-http-fetch.sh
new file mode 100755
index 0000000..b6e6ec9
--- /dev/null
+++ b/t/t5550-http-fetch.sh
@@ -0,0 +1,46 @@
+#!/bin/sh
+
+test_description='test fetching over http'
+. ./test-lib.sh
+
+if test -n "$NO_CURL"; then
+ say 'skipping test, git built without http support'
+ test_done
+fi
+
+. "$TEST_DIRECTORY"/lib-httpd.sh
+LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5550'}
+start_httpd
+
+test_expect_success 'setup repository' '
+ echo content >file &&
+ git add file &&
+ git commit -m one
+'
+
+test_expect_success 'create http-accessible bare repository' '
+ mkdir "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
+ (cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
+ git --bare init &&
+ echo "exec git update-server-info" >hooks/post-update &&
+ chmod +x hooks/post-update
+ ) &&
+ git remote add public "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
+ git push public master:master
+'
+
+test_expect_success 'clone http repository' '
+ git clone $HTTPD_URL/repo.git clone &&
+ test_cmp file clone/file
+'
+
+test_expect_success 'fetch changes via http' '
+ echo content >>file &&
+ git commit -a -m two &&
+ git push public
+ (cd clone && git pull) &&
+ test_cmp file clone/file
+'
+
+stop_httpd
+test_done
--
1.6.2.rc1.291.g83eb
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH 21/23] refactor find_refs_by_name to accept const list
[not found] <cover.1235467368.git.jaysoffian@gmail.com>
` (19 preceding siblings ...)
2009-02-24 9:51 ` [PATCH 20/23] add basic http clone/fetch tests Jay Soffian
@ 2009-02-24 9:51 ` Jay Soffian
2009-02-24 9:51 ` [PATCH 22/23] remote: refactor guess_remote_head Jay Soffian
2009-02-24 9:51 ` [PATCH 23/23] remote: use exact HEAD lookup if it is available Jay Soffian
22 siblings, 0 replies; 23+ messages in thread
From: Jay Soffian @ 2009-02-24 9:51 UTC (permalink / raw)
To: git; +Cc: Jay Soffian, Jeff King, Junio C Hamano
From: Jeff King <peff@peff.net>
Since it doesn't actually touch its argument, this makes
sense.
However, we still want to return a non-const version (which
requires a cast) so that this:
struct ref *a, *b;
a = find_ref_by_name(b);
works. Unfortunately, you can also silently strip the const
from a variable:
struct ref *a;
const struct ref *b;
a = find_ref_by_name(b);
This is a classic C const problem because there is no way to
say "return the type with the same constness that was passed
to us"; we provide the same semantics as standard library
functions like strchr.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---
cache.h | 2 +-
refs.c | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/cache.h b/cache.h
index 189151d..609380d 100644
--- a/cache.h
+++ b/cache.h
@@ -801,7 +801,7 @@ struct ref {
#define REF_HEADS (1u << 1)
#define REF_TAGS (1u << 2)
-extern struct ref *find_ref_by_name(struct ref *list, const char *name);
+extern struct ref *find_ref_by_name(const struct ref *list, const char *name);
#define CONNECT_VERBOSE (1u << 0)
extern struct child_process *git_connect(int fd[2], const char *url, const char *prog, int flags);
diff --git a/refs.c b/refs.c
index 6eb5f53..b2a37e1 100644
--- a/refs.c
+++ b/refs.c
@@ -1628,10 +1628,10 @@ int update_ref(const char *action, const char *refname,
return 0;
}
-struct ref *find_ref_by_name(struct ref *list, const char *name)
+struct ref *find_ref_by_name(const struct ref *list, const char *name)
{
for ( ; list; list = list->next)
if (!strcmp(list->name, name))
- return list;
+ return (struct ref *)list;
return NULL;
}
--
1.6.2.rc1.291.g83eb
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH 22/23] remote: refactor guess_remote_head
[not found] <cover.1235467368.git.jaysoffian@gmail.com>
` (20 preceding siblings ...)
2009-02-24 9:51 ` [PATCH 21/23] refactor find_refs_by_name to accept const list Jay Soffian
@ 2009-02-24 9:51 ` Jay Soffian
2009-02-24 9:51 ` [PATCH 23/23] remote: use exact HEAD lookup if it is available Jay Soffian
22 siblings, 0 replies; 23+ messages in thread
From: Jay Soffian @ 2009-02-24 9:51 UTC (permalink / raw)
To: git; +Cc: Jay Soffian, Jeff King, Junio C Hamano
From: Jeff King <peff@peff.net>
This function had a lot of complications which made it hard
to read and extend, and confusing to call (because of
optional unused parameters). This patch attempts to address
that:
- we used to manually search through the ref lists; this
should be a one-line call to find_ref_by_name
- guess_remote_head used to do two things: find the HEAD
ref, and then find a matching ref. And only one of the
two callers actually cared about returning the HEAD ref.
Since it's a one-liner, just have the caller do it
themselves (and remember it or not as they wish).
- there were two ways of getting results out of the
function (a return value, and an "all_matched" out
parameter), but no caller cared about both. One of them
returned a pointer into the passed-in ref list and one
of them returned a newly allocated list (with the
peer_ref fields stripped). Let's be simple and
consistent: the return value is always a ref copy with
a valid peer_ref. If "all" is requested, all candidates
are returned. Otherwise, the best candidate is returned.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---
builtin-clone.c | 5 +--
builtin-remote.c | 5 ++-
remote.c | 62 ++++++++++++++++++++++-------------------------------
remote.h | 17 ++++++--------
4 files changed, 38 insertions(+), 51 deletions(-)
diff --git a/builtin-clone.c b/builtin-clone.c
index d57818c..7130cab 100644
--- a/builtin-clone.c
+++ b/builtin-clone.c
@@ -508,9 +508,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
clear_extra_refs();
mapped_refs = write_remote_refs(refs, &refspec, reflog_msg.buf);
-
- head_points_at = guess_remote_head(refs, mapped_refs,
- &remote_head, NULL);
+ remote_head = find_ref_by_name(refs, "HEAD");
+ head_points_at = guess_remote_head(remote_head, mapped_refs, 0);
}
else {
warning("You appear to have cloned an empty repository.");
diff --git a/builtin-remote.c b/builtin-remote.c
index 80ab7af..d5a575f 100644
--- a/builtin-remote.c
+++ b/builtin-remote.c
@@ -385,7 +385,7 @@ static int get_push_ref_states_noquery(struct ref_states *states)
static int get_head_names(const struct ref *remote_refs,
const char *remote_name, struct ref_states *states)
{
- struct ref *ref, *matches = NULL;
+ struct ref *ref, *matches;
struct ref *fetch_map = NULL, **fetch_map_tail = &fetch_map;
struct refspec refspec;
@@ -394,7 +394,8 @@ static int get_head_names(const struct ref *remote_refs,
refspec.src = refspec.dst = "refs/heads/";
states->heads.strdup_strings = 1;
get_fetch_map(remote_refs, &refspec, &fetch_map_tail, 0);
- guess_remote_head(remote_refs, fetch_map, NULL, &matches);
+ 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);
diff --git a/remote.c b/remote.c
index f07ecf4..96d5c95 100644
--- a/remote.c
+++ b/remote.c
@@ -1431,53 +1431,43 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb)
return 1;
}
-const struct ref *guess_remote_head(const struct ref *refs,
- const struct ref *mapped_refs,
- const struct ref **remote_head_p,
- struct ref **all_matches_p)
+struct ref *copy_ref_with_peer(const struct ref *src)
{
- const struct ref *remote_head = NULL;
- const struct ref *remote_master = NULL;
- const struct ref *ret = NULL;
- const struct ref *r;
- struct ref **tail = all_matches_p;
-
- for (r = refs; r; r = r->next)
- if (!strcmp(r->name, "HEAD"))
- remote_head = r;
-
- if (!all_matches_p)
- for (r = mapped_refs; r; r = r->next)
- if (!strcmp(r->name, "refs/heads/master"))
- remote_master = r;
+ struct ref *dst = copy_ref(src);
+ dst->peer_ref = copy_ref(src->peer_ref);
+ return dst;
+}
- if (remote_head_p)
- *remote_head_p = remote_head;
+struct ref *guess_remote_head(const struct ref *head,
+ const struct ref *refs,
+ int all)
+{
+ const struct ref *r;
+ struct ref *list = NULL;
+ struct ref **tail = &list;
- /* If there's no HEAD value at all, never mind. */
- if (!remote_head)
+ if (!head)
return NULL;
/* If refs/heads/master could be right, it is. */
- if (remote_master && !hashcmp(remote_master->old_sha1,
- remote_head->old_sha1))
- return remote_master;
+ if (!all) {
+ const struct ref *m;
+ m = find_ref_by_name(refs, "refs/heads/master");
+ if (m && !hashcmp(m->old_sha1, head->old_sha1))
+ return copy_ref_with_peer(m);
+ }
/* Look for another ref that points there */
- for (r = mapped_refs; r; r = r->next)
- if (r != remote_head &&
- !hashcmp(r->old_sha1, remote_head->old_sha1)) {
- struct ref *cpy;
- if (!ret)
- ret = r;
- if (!all_matches_p)
+ for (r = refs; r; r = r->next) {
+ if (r != head && !hashcmp(r->old_sha1, head->old_sha1)) {
+ *tail = copy_ref_with_peer(r);
+ tail = &((*tail)->next);
+ if (!all)
break;
- *tail = cpy = copy_ref(r);
- cpy->peer_ref = NULL;
- tail = &cpy->next;
}
+ }
- return ret;
+ return list;
}
static int one_local_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
diff --git a/remote.h b/remote.h
index 1f78a0a..903712f 100644
--- a/remote.h
+++ b/remote.h
@@ -139,17 +139,14 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs);
int format_tracking_info(struct branch *branch, struct strbuf *sb);
/*
- * Look in refs for HEAD. Then look for a matching SHA1 in mapped_refs,
- * first checking if refs/heads/master matches. Return NULL if nothing matches
- * or if there is no HEAD in refs. remote_head_p is assigned HEAD if not NULL.
- * If all_matches_p is NULL, return after the first possible match. Otherwise
- * all_matches_p is set to a ref list of each branch head with the same SHA1 as
- * HEAD.
+ * Find refs from a list which are likely to be pointed to by the given HEAD
+ * ref. If 'all' is false, returns the most likely ref; otherwise, returns a
+ * list of all candidate refs. If no match is found (or 'head' is NULL),
+ * returns NULL. All returns are newly allocated and should be freed.
*/
-const struct ref *guess_remote_head(const struct ref *refs,
- const struct ref *mapped_refs,
- const struct ref **remote_head_p,
- struct ref **all_matches_p);
+struct ref *guess_remote_head(const struct ref *head,
+ const struct ref *refs,
+ int all);
struct ref *get_local_heads(void);
#endif
--
1.6.2.rc1.291.g83eb
^ permalink raw reply related [flat|nested] 23+ messages in thread* [PATCH 23/23] remote: use exact HEAD lookup if it is available
[not found] <cover.1235467368.git.jaysoffian@gmail.com>
` (21 preceding siblings ...)
2009-02-24 9:51 ` [PATCH 22/23] remote: refactor guess_remote_head Jay Soffian
@ 2009-02-24 9:51 ` Jay Soffian
22 siblings, 0 replies; 23+ messages in thread
From: Jay Soffian @ 2009-02-24 9:51 UTC (permalink / raw)
To: git; +Cc: Jay Soffian, Jeff King, Junio C Hamano
From: Jeff King <peff@peff.net>
Our usual method for determining the ref pointed to by HEAD
is to compare HEAD's sha1 to the sha1 of all refs, trying to
find a unique match.
However, some transports actually get to look at HEAD
directly; we should make use of that information when it is
available. Currently, only http remotes support this
feature.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---
remote.c | 10 ++++++++++
t/t5550-http-fetch.sh | 11 +++++++++++
2 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/remote.c b/remote.c
index 96d5c95..682af74 100644
--- a/remote.c
+++ b/remote.c
@@ -1449,6 +1449,16 @@ struct ref *guess_remote_head(const struct ref *head,
if (!head)
return NULL;
+ /*
+ * Some transports support directly peeking at
+ * where HEAD points; if that is the case, then
+ * we don't have to guess.
+ */
+ if (head->symref) {
+ r = find_ref_by_name(refs, head->symref);
+ return r ? copy_ref_with_peer(r) : NULL;
+ }
+
/* If refs/heads/master could be right, it is. */
if (!all) {
const struct ref *m;
diff --git a/t/t5550-http-fetch.sh b/t/t5550-http-fetch.sh
index b6e6ec9..05b1b62 100755
--- a/t/t5550-http-fetch.sh
+++ b/t/t5550-http-fetch.sh
@@ -42,5 +42,16 @@ test_expect_success 'fetch changes via http' '
test_cmp file clone/file
'
+test_expect_success 'http remote detects correct HEAD' '
+ git push public master:other &&
+ (cd clone &&
+ git remote set-head origin -d &&
+ git remote set-head origin -a &&
+ git symbolic-ref refs/remotes/origin/HEAD > output &&
+ echo refs/remotes/origin/master > expect &&
+ test_cmp expect output
+ )
+'
+
stop_httpd
test_done
--
1.6.2.rc1.291.g83eb
^ permalink raw reply related [flat|nested] 23+ messages in thread