summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 803527f)
raw | patch | inline | side by side (parent: 803527f)
author | Paolo Bonzini <bonzini@gnu.org> | |
Thu, 15 Mar 2007 08:23:20 +0000 (09:23 +0100) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Fri, 16 Mar 2007 09:10:12 +0000 (02:10 -0700) |
This patch adds support for a dummy remote '.' to avoid having
to declare a fake remote like
[remote "local"]
url = .
fetch = refs/heads/*:refs/heads/*
Such a builtin remote simplifies the operation of "git-fetch",
which will populate FETCH_HEAD but will not pretend that two
repositories are in use, will not create a thin pack, and will
not perform any useless remapping of names. The speed
improvement is around 20%, and it should improve more if
"git-fetch" is converted to a builtin.
To this end, git-parse-remote is grown with a new kind of
remote, 'builtin'. In git-fetch.sh, we treat the builtin remote
specially in that it needs no pack/store operations. In fact,
doing git-fetch on a builtin remote will simply populate
FETCH_HEAD appropriately.
The patch also improves of the --track/--no-track support,
extending it so that branch.<name>.remote items referring '.'
can be created. Finally, it fixes a typo in git-checkout.sh.
Signed-off-by: Paolo Bonzini <bonzini@gnu.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
to declare a fake remote like
[remote "local"]
url = .
fetch = refs/heads/*:refs/heads/*
Such a builtin remote simplifies the operation of "git-fetch",
which will populate FETCH_HEAD but will not pretend that two
repositories are in use, will not create a thin pack, and will
not perform any useless remapping of names. The speed
improvement is around 20%, and it should improve more if
"git-fetch" is converted to a builtin.
To this end, git-parse-remote is grown with a new kind of
remote, 'builtin'. In git-fetch.sh, we treat the builtin remote
specially in that it needs no pack/store operations. In fact,
doing git-fetch on a builtin remote will simply populate
FETCH_HEAD appropriately.
The patch also improves of the --track/--no-track support,
extending it so that branch.<name>.remote items referring '.'
can be created. Finally, it fixes a typo in git-checkout.sh.
Signed-off-by: Paolo Bonzini <bonzini@gnu.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
index aaae9ac3052b5a4de6ec53817e79797626f7da31..953acaee4c9b692802a4e98861dac8ceec315d54 100644 (file)
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
`git fetch`) to lookup the default branch for merging. Without
this option, `git pull` defaults to merge the first refspec fetched.
Specify multiple values to get an octopus merge.
+ If you wish to setup `git pull` so that it merges into <name> from
+ another branch in the local repository, you can point
+ branch.<name>.merge to the desired branch, and use the special setting
+ `.` (a period) for branch.<name>.remote.
color.branch::
A boolean to enable/disable color in the output of
diff --git a/builtin-branch.c b/builtin-branch.c
index 42b1ff129e7d5bbea47a4d1af955395014f200f9..a4494ee337d70a400664e529e84f90d475a03b92 100644 (file)
--- a/builtin-branch.c
+++ b/builtin-branch.c
return 0;
}
-static void set_branch_defaults(const char *name, const char *real_ref)
+static void set_branch_merge(const char *name, const char *config_remote,
+ const char *config_repo)
{
char key[1024];
+ if (sizeof(key) <=
+ snprintf(key, sizeof(key), "branch.%s.remote", name))
+ die("what a long branch name you have!");
+ git_config_set(key, config_remote);
+
+ /*
+ * We do not have to check if we have enough space for
+ * the 'merge' key, since it's shorter than the
+ * previous 'remote' key, which we already checked.
+ */
+ snprintf(key, sizeof(key), "branch.%s.merge", name);
+ git_config_set(key, config_repo);
+}
+
+static void set_branch_defaults(const char *name, const char *real_ref)
+{
const char *slash = strrchr(real_ref, '/');
if (!slash)
start_len = strlen(real_ref);
base_len = slash - real_ref;
git_config(get_remote_config);
+ if (!config_repo && !config_remote &&
+ !prefixcmp(real_ref, "refs/heads/")) {
+ set_branch_merge(name, ".", real_ref);
+ printf("Branch %s set up to track local branch %s.\n",
+ name, real_ref);
+ }
if (config_repo && config_remote) {
- if (sizeof(key) <=
- snprintf(key, sizeof(key), "branch.%s.remote", name))
- die("what a long branch name you have!");
- git_config_set(key, config_remote);
-
- /*
- * We do not have to check if we have enough space for
- * the 'merge' key, since it's shorter than the
- * previous 'remote' key, which we already checked.
- */
- snprintf(key, sizeof(key), "branch.%s.merge", name);
- git_config_set(key, config_repo);
-
+ set_branch_merge(name, config_remote, config_repo);
printf("Branch %s set up to track remote branch %s.\n",
name, real_ref);
}
diff --git a/git-checkout.sh b/git-checkout.sh
index fcadf200ee990f195ce3f5c72306cbf0206277cd..39ffa8b8a3322b623a6d4938d566453fe206ca69 100755 (executable)
--- a/git-checkout.sh
+++ b/git-checkout.sh
esac
done
-case "$new_branch,$track" in
+case "$newbranch,$track" in
,--*)
die "git checkout: --track and --no-track require -b"
esac
diff --git a/git-fetch.sh b/git-fetch.sh
index 9d45dd266a8110a2d39fe29ffeb84aacb6053623..e21804284398016a789b415dec9332700d33f8e6 100755 (executable)
--- a/git-fetch.sh
+++ b/git-fetch.sh
fi
fi
-fetch_native () {
+fetch_all_at_once () {
eval=$(echo "$1" | git-fetch--tool parse-reflist "-")
eval "$eval"
( : subshell because we muck with IFS
IFS=" $LF"
(
- if test -f "$remote" ; then
+ if test "$remote" = . ; then
+ git-show-ref $rref || echo failed "$remote"
+ elif test -f "$remote" ; then
test -n "$shallow_depth" &&
die "shallow clone with bundle is not supported"
git-bundle unbundle "$remote" $rref ||
}
-fetch_dumb () {
+fetch_per_ref () {
reflist="$1"
refs=
rref=
fetch_main () {
case "$remote" in
http://* | https://* | ftp://* | rsync://* )
- fetch_dumb "$@"
+ fetch_per_ref "$@"
;;
*)
- fetch_native "$@"
+ fetch_all_at_once "$@"
;;
esac
}
diff --git a/git-parse-remote.sh b/git-parse-remote.sh
index c46131f6d6619aa07ddb72265583b1de0832ff3e..437b0c3b1bc522c4b5a4a3a656b97cb2009c43a0 100755 (executable)
--- a/git-parse-remote.sh
+++ b/git-parse-remote.sh
*/*)
echo ''
;;
+ .)
+ echo self
+ ;;
*)
if test "$(git-config --get "remote.$1.url")"
then
'')
echo "$1"
;;
+ self)
+ echo "$1"
+ ;;
config)
git-config --get "remote.$1.url"
;;
get_remote_default_refs_for_push () {
data_source=$(get_data_source "$1")
case "$data_source" in
- '' | branches)
+ '' | branches | self)
;; # no default push mapping, just send matching refs.
config)
git-config --get-all "remote.$1.push" ;;
case "$data_source" in
'')
echo "HEAD:" ;;
+ self)
+ canon_refs_list_for_fetch -d "$1" \
+ $(git-for-each-ref --format='%(refname):')
+ ;;
config)
canon_refs_list_for_fetch -d "$1" \
$(git-config --get-all "remote.$1.fetch") ;;
}' "$GIT_DIR/remotes/$1")
;;
*)
- die "internal error: get-remote-default-ref-for-push $1" ;;
+ die "internal error: get-remote-default-ref-for-fetch $1" ;;
esac
}
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index 75c000a968c4b3a371393062e14801aa90ee53f1..9558bdb6318cc2956c43153084e1f1cc8386973f 100755 (executable)
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
git-config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
(git-show-ref -q refs/remotes/local/master || git-fetch local) &&
git-branch --no-track my2 local/master &&
+ git-config branch.autosetupmerge false &&
! test $(git-config branch.my2.remote) = local &&
! test $(git-config branch.my2.merge) = refs/heads/master'
+test_expect_success 'test local tracking setup' \
+ 'git branch --track my6 s &&
+ test $(git-config branch.my6.remote) = . &&
+ test $(git-config branch.my6.merge) = refs/heads/s'
+
# Keep this test last, as it changes the current branch
cat >expect <<EOF
0000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 7eb37838bb788dfb68361bca95860fd532276deb..243212d3dac03c19db18e9c8fcfc3b9049137cdd 100755 (executable)
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
diff file cloned/file
'
+test_expect_success 'test . as a remote' '
+
+ git branch copy master &&
+ git config branch.copy.remote . &&
+ git config branch.copy.merge refs/heads/master &&
+ echo updated >file &&
+ git commit -a -m updated &&
+ git checkout copy &&
+ test `cat file` = file &&
+ git pull &&
+ test `cat file` = updated
+'
+
+test_expect_success 'the default remote . should not break explicit pull' '
+ git checkout -b second master^ &&
+ echo modified >file &&
+ git commit -a -m modified &&
+ git checkout copy &&
+ git reset --hard HEAD^ &&
+ test `cat file` = file &&
+ git pull . second &&
+ test `cat file` = modified
+'
+
test_done