* [RFC/PATCH] git-fetch: Use already fetched branch with the --local flag.
@ 2006-10-16 13:40 Santi Béjar
2006-10-17 7:14 ` Junio C Hamano
2006-10-17 14:03 ` Santi Béjar
0 siblings, 2 replies; 4+ messages in thread
From: Santi Béjar @ 2006-10-16 13:40 UTC (permalink / raw)
To: Git Mailing List
It allows to separate when you fetch from when you merge. So, a "git pull"
can be:
$ git fetch
$ git pull --local
and the pull call can be made later. This is usefull when you have multiple
branches and you want to merge the same "upstream" branch, or when you are
offline but you have already fetched the remote branch.
Note that this is different from:
$ git fetch
$ git pull . origin
(1) you do not have to tell explicitly the branch to merge
(2) the commit message is exactly as with "git pull"
Signed-off-by: Santi Béjar <sbejar@gmail.com>
---
Documentation/fetch-options.txt | 3 +++
git-fetch.sh | 25 +++++++++++++++++++------
git-parse-remote.sh | 22 ++++++++++++++++++++++
3 files changed, 44 insertions(+), 6 deletions(-)
diff --git a/Documentation/fetch-options.txt b/Documentation/fetch-options.txt
index 13f34d3..3a6cb3d 100644
--- a/Documentation/fetch-options.txt
+++ b/Documentation/fetch-options.txt
@@ -39,3 +39,6 @@
check. Note that fetching into the current branch will not
update the index and working directory, so use it with care.
+\--local::
+ Do not fetch from the remote repository. Use the already fetched
+ branches to program the merge for `git-pull`.
diff --git a/git-fetch.sh b/git-fetch.sh
index 79222fb..5ff800a 100755
--- a/git-fetch.sh
+++ b/git-fetch.sh
@@ -21,6 +21,7 @@ update_head_ok=
exec=
upload_pack=
keep=--thin
+local_fetch=
while case "$#" in 0) break ;; esac
do
case "$1" in
@@ -56,6 +57,9 @@ do
--reflog-action=*)
rloga=`expr "z$1" : 'z-[^=]*=\(.*\)'`
;;
+ --local)
+ local_fetch=t
+ ;;
-*)
usage
;;
@@ -80,6 +84,10 @@ refs=
rref=
rsync_slurped_objects=
+[ "$local_fetch" = t ] && [ "$remote_nick" = "$remote" ] && \
+ [ "$remote" != "." ] && \
+ die "Flag --local only compatible with remote shorthands"
+
rloga="$rloga $remote_nick"
test "$remote_nick" = "$remote" || rloga="$rloga $remote"
@@ -285,8 +293,8 @@ fetch_main () {
rref="$rref$LF$remote_name"
# There are transports that can fetch only one head at a time...
- case "$remote" in
- http://* | https://* | ftp://*)
+ case "$local_fetch,$remote" in
+ ,http://* | ,https://* | ,ftp://*)
if [ -n "$GIT_SSL_NO_VERIFY" ]; then
curl_extra_args="-k"
fi
@@ -313,7 +321,7 @@ fetch_main () {
echo >&2 Fetching "$remote_name from $remote" using http
git-http-fetch -v -a "$head" "$remote/" || exit
;;
- rsync://*)
+ ,rsync://*)
TMP_HEAD="$GIT_DIR/TMP_HEAD"
rsync -L -q "$remote/$remote_name" "$TMP_HEAD" || exit 1
head=$(git-rev-parse --verify TMP_HEAD)
@@ -343,6 +351,11 @@ fetch_main () {
rsync_slurped_objects=t
}
;;
+ t,*)
+ [ -z "$local_name" ] &&\
+ local_name=$(get_ref_for_remote_branch "$remote_nick" "$remote_name")
+ head=$(git-rev-parse --verify $local_name^0) || exit
+ ;;
*)
# We will do git native transport with just one call later.
continue ;;
@@ -353,8 +366,8 @@ fetch_main () {
done
- case "$remote" in
- http://* | https://* | ftp://* | rsync://* )
+ case "$local_fetch,$remote" in
+ ,http://* | ,https://* | ,ftp://* | ,rsync://* | t,*)
;; # we are already done.
*)
( : subshell because we muck with IFS
@@ -406,7 +419,7 @@ fetch_main () {
fetch_main "$reflist"
# automated tag following
-case "$no_tags$tags" in
+case "$no_tags$tags$local_fetch" in
'')
case "$reflist" in
*:refs/*)
diff --git a/git-parse-remote.sh b/git-parse-remote.sh
index c325ef7..679f73c 100755
--- a/git-parse-remote.sh
+++ b/git-parse-remote.sh
@@ -236,3 +236,25 @@ resolve_alternates () {
esac
done
}
+
+get_ref_for_remote_branch (){
+ data_source=$(get_data_source "$1")
+ case "$data_source" in
+ '' | config-partial | branches | branches-partial)
+ test "$1" = . && echo $2
+ ;;
+ config)
+ ref=$(git-repo-config --get-all "remote.$1.fetch" |\
+ grep "^$2:")
+ expr "z$ref" : 'z[^:]*:\(.*\)'
+ ;;
+ remotes)
+ ref=$(sed -ne '/^Pull: */{
+ s///p
+ }' "$GIT_DIR/remotes/$1" | grep "$2:")
+ expr "z$ref" : 'z[^:]*:\(.*\)'
+ ;;
+ *)
+ die "internal error: get-ref-for-remote-branch $1 $2" ;;
+ esac
+}
--
1.4.3.rc2.ga442
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [RFC/PATCH] git-fetch: Use already fetched branch with the --local flag.
2006-10-16 13:40 [RFC/PATCH] git-fetch: Use already fetched branch with the --local flag Santi Béjar
@ 2006-10-17 7:14 ` Junio C Hamano
2006-10-17 8:36 ` Santi Béjar
2006-10-17 14:03 ` Santi Béjar
1 sibling, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2006-10-17 7:14 UTC (permalink / raw)
To: Santi Béjar; +Cc: git
Santi Béjar <sbejar@gmail.com> writes:
> It allows to separate when you fetch from when you merge. So, a "git pull"
> can be:
>
> $ git fetch
> $ git pull --local
There was something that has been disturbing me in your patches
(this one, and the previous "remote=." one) and I could not tell
what it was. I think I know what it is now.
Let me outline my understanding of the workflow these two
changes would help.
You have an upstream repository that has more than one branches
you are interested in, say "master" and "next". And you work on
top of both of them, so you have two branches of your own that
correspond to them.
So you organize your remote section perhaps like this:
[remote."origin"]
url = git://git.k.o/.../git.git/
fetch = refs/heads/master:refs/remotes/origin/master
fetch = refs/heads/next:refs/remotes/origin/next
fetch = +refs/heads/pu:refs/remotes/origin/pu
[branch."master"]
remote = origin
merge = refs/heads/master
[branch."next"]
remote = origin
merge = refs/heads/next
That is, your refs/heads/master corresponds to upstream's master
branch and your next corresponds to upstream's next branch.
When you are on your "master" you would merge changes made to
upstream's master into it with "git pull".
By the way, could you add descriptions on remote.* to
Documentation/config.txt?
After doing a "git pull" while on your "master" and finishing
working on your "master", you might switch to your "next". At
that point, if you want to merge upstream changes without
re-fetching, you can do either of the following:
git pull . remotes/origin/next
git pull --local
(the former can be "git pull" if "branch.next.remote=.").
I think this is the point of your two patches, and in that
sense, the --local one makes "branch.remote=." patch
unnecessary.
While these save typing on "git pull", two things bother me.
* the tool is not helping you decide if you can get away
without re-fetching. you need to remember that (1) you
fetched from the upstream to update "master" recently _and_
(2) because of your [remote."origin"] configuration your
remotes/origin/next was updated while you pulled into your
"master".
* while the workflow assumes that one local branch is tied
closely to one remote branch (in this example, tracked under
remotes/origin), the rest of the tools do not take advantage
of that assumption to help you decide what to do next.
For example, if each of your local branch is tied closely to one
remote branch, you should be able to "git fetch" to update the
tracking branches and then ask:
- what changes are in remote that I haven't merged?
- what happens when I pull --local right now?
- what changes if any are in mine alone missing from remote?
- can I push to remote right now (i.e. would it fast-forward)?
- how fresh is the tracking branch that corresponds to my
current branch?
Right now, these require you to spell out the name of the
tracking branch. Assuming you are on your "next" branch:
git log ..remotes/origin/next
git log remotes/origin/next..
git log remotes/origin/next...next [*1*]
git show-branch remotes/origin/next next
tail -n 1 .git/logs/remotes/origin/next
would be the ways to ask the above questions (and the last one
is unreadable unless you can do strptime in your head).
Maybe we can introduce a new extended SHA-1 notation to mean
"the tracking branch this branch usually merges from". Then we
can say:
git log ..^
git log ^..
git log ^...
git show-branch ^ next
I am not sure '^' is syntactically viable, but hopefully you get
the idea.
[*1*] While three-dots symmetric difference is a nice addition
made recently, I often find it irritating that the output does
not tell which branch each of the commit is reachable from, and
end up running show-branch, which does. Would anybody have a
clever idea to fix this cleanly?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFC/PATCH] git-fetch: Use already fetched branch with the --local flag.
2006-10-17 7:14 ` Junio C Hamano
@ 2006-10-17 8:36 ` Santi Béjar
0 siblings, 0 replies; 4+ messages in thread
From: Santi Béjar @ 2006-10-17 8:36 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
2006/10/17, Junio C Hamano <junkio@cox.net>:
[...]
>
> You have an upstream repository that has more than one branches
> you are interested in, say "master" and "next". And you work on
> top of both of them, so you have two branches of your own that
> correspond to them.
>
> So you organize your remote section perhaps like this:
>
> [remote."origin"]
> url = git://git.k.o/.../git.git/
> fetch = refs/heads/master:refs/remotes/origin/master
> fetch = refs/heads/next:refs/remotes/origin/next
> fetch = +refs/heads/pu:refs/remotes/origin/pu
>
> [branch."master"]
> remote = origin
> merge = refs/heads/master
>
> [branch."next"]
> remote = origin
> merge = refs/heads/next
>
> That is, your refs/heads/master corresponds to upstream's master
> branch and your next corresponds to upstream's next branch.
> When you are on your "master" you would merge changes made to
> upstream's master into it with "git pull".
Yes, that is.
>
> By the way, could you add descriptions on remote.* to
> Documentation/config.txt?
>
I'll try. Off-topic: Do you want also docs for the ^@ notation and an
implementation in git-rev-parse?
> After doing a "git pull" while on your "master" and finishing
> working on your "master", you might switch to your "next". At
> that point, if you want to merge upstream changes without
> re-fetching, you can do either of the following:
>
> git pull . remotes/origin/next
> git pull --local
>
> (the former can be "git pull" if "branch.next.remote=.").
>
> I think this is the point of your two patches, and in that
> sense, the --local one makes "branch.remote=." patch
> unnecessary.
I see them differently. "branch.remote=." is when there is no upstream
(e.g., for your next and master branches in git.git).
>
> While these save typing on "git pull", two things bother me.
>
> * the tool is not helping you decide if you can get away
> without re-fetching. you need to remember that (1) you
> fetched from the upstream to update "master" recently _and_
> (2) because of your [remote."origin"] configuration your
> remotes/origin/next was updated while you pulled into your
> "master".
You never know if you can get away without re-fetching (or I don't
parse this sentence :). The way I see it, you always us "git pull"
except when you want to merge the exactly the already fetch branch
because (1) you want to merge the same upstream as with other branch
(2) you don't have access to the remote repository (3)...
>
> * while the workflow assumes that one local branch is tied
> closely to one remote branch (in this example, tracked under
> remotes/origin), the rest of the tools do not take advantage
> of that assumption to help you decide what to do next.
This is the next item in my TODO :)
Next with a program similar to "svn info" showing misc info about a branch.
>
> For example, if each of your local branch is tied closely to one
> remote branch, you should be able to "git fetch" to update the
> tracking branches and then ask:
>
> - what changes are in remote that I haven't merged?
>
> - what happens when I pull --local right now?
>
> - what changes if any are in mine alone missing from remote?
>
> - can I push to remote right now (i.e. would it fast-forward)?
>
> - how fresh is the tracking branch that corresponds to my
> current branch?
>
> Right now, these require you to spell out the name of the
> tracking branch. Assuming you are on your "next" branch:
>
> git log ..remotes/origin/next
> git log remotes/origin/next..
> git log remotes/origin/next...next [*1*]
> git show-branch remotes/origin/next next
> tail -n 1 .git/logs/remotes/origin/next
>
> would be the ways to ask the above questions (and the last one
> is unreadable unless you can do strptime in your head).
>
> Maybe we can introduce a new extended SHA-1 notation to mean
> "the tracking branch this branch usually merges from". Then we
> can say:
>
> git log ..^
> git log ^..
> git log ^...
> git show-branch ^ next
>
> I am not sure '^' is syntactically viable, but hopefully you get
> the idea.
I get it. Another idea is to have a .git/ORIGIN that points to the
tracking branch so you could say:
git log ..ORIGIN
git log ORIGIN..
git log ORIGIN...
git show-branch ORIGIN next
One advantage is that it only needs changes to "git checkout" (and
possibly others but not to plumbing ones).
Another is that the ^ notation forces the low level tools to follow
configs in [branch."..."] and [remote."..."].
>
>
> [*1*] While three-dots symmetric difference is a nice addition
> made recently, I often find it irritating that the output does
> not tell which branch each of the commit is reachable from, and
> end up running show-branch, which does. Would anybody have a
> clever idea to fix this cleanly?
I don't know if it is a clever idea but...
We could use the git-name-rev method:
$git log a...b
commit sha1 (a)
....
commit sha1 (a^)
....
commit sha1 (b^)
....
commit sha1 (b)
....
and without this when on both branches.
Santi
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFC/PATCH] git-fetch: Use already fetched branch with the --local flag.
2006-10-16 13:40 [RFC/PATCH] git-fetch: Use already fetched branch with the --local flag Santi Béjar
2006-10-17 7:14 ` Junio C Hamano
@ 2006-10-17 14:03 ` Santi Béjar
1 sibling, 0 replies; 4+ messages in thread
From: Santi Béjar @ 2006-10-17 14:03 UTC (permalink / raw)
To: Git Mailing List
Please, add this:
diff --git a/git-parse-remote.sh b/git-parse-remote.sh
index 617d022..a792323 100755
--- a/git-parse-remote.sh
+++ b/git-parse-remote.sh
@@ -260,7 +260,7 @@ get_ref_for_remote_branch (){
remotes)
ref=$(sed -ne '/^Pull: */{
s///p
- }' "$GIT_DIR/remotes/$1" | grep "$2:")
+ }' "$GIT_DIR/remotes/$1" | grep "^$2:")
expr "z$ref" : 'z[^:]*:\(.*\)'
;;
*)
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2006-10-17 14:03 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-10-16 13:40 [RFC/PATCH] git-fetch: Use already fetched branch with the --local flag Santi Béjar
2006-10-17 7:14 ` Junio C Hamano
2006-10-17 8:36 ` Santi Béjar
2006-10-17 14:03 ` Santi Béjar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).