All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] git-clone: Add option --branch to override initial branch
@ 2009-03-02 22:11 Tor Arne Vestbø
  2009-03-02 23:48 ` Johannes Schindelin
  0 siblings, 1 reply; 19+ messages in thread
From: Tor Arne Vestbø @ 2009-03-02 22:11 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

The options --branch and -b allow the user to override the initial
branch created and checked out by git-clone. Normally this is the
active branch of the remote repository, which is also the fallback
if the selected branch is not found.

Signed-off-by: Tor Arne Vestbø <torarnv@gmail.com>
---
 Documentation/git-clone.txt |    5 +++++
 builtin-clone.c             |   33 +++++++++++++++++++++++++++++----
 2 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/Documentation/git-clone.txt b/Documentation/git-clone.txt
index 95f08b9..e7feb4d 100644
--- a/Documentation/git-clone.txt
+++ b/Documentation/git-clone.txt
@@ -119,6 +119,11 @@ then the cloned repository will become corrupt.
 	Instead of using the remote name 'origin' to keep track
 	of the upstream repository, use <name> instead.
 
+--branch <name>::
+-b <name>::
+	Instead of using the remote repository's active branch as the
+	initial branch, use <name> instead.
+
 --upload-pack <upload-pack>::
 -u <upload-pack>::
 	When given, and the repository to clone from is accessed
diff --git a/builtin-clone.c b/builtin-clone.c
index c338910..601c2c2 100644
--- a/builtin-clone.c
+++ b/builtin-clone.c
@@ -38,6 +38,7 @@ static int option_quiet, option_no_checkout, option_bare, option_mirror;
 static int option_local, option_no_hardlinks, option_shared;
 static char *option_template, *option_reference, *option_depth;
 static char *option_origin = NULL;
+static char *option_branch = NULL;
 static char *option_upload_pack = "git-upload-pack";
 static int option_verbose;
 
@@ -66,6 +67,8 @@ static struct option builtin_clone_options[] = {
 		   "path to git-upload-pack on the remote"),
 	OPT_STRING(0, "depth", &option_depth, "depth",
 		    "create a shallow clone of that depth"),
+	OPT_STRING('b', "branch", &option_branch, "branch",
+		    "initial remote branch to check out"),
 
 	OPT_END()
 };
@@ -372,7 +375,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 	const char *repo_name, *repo, *work_tree, *git_dir;
 	char *path, *dir;
 	int dest_exists;
-	const struct ref *refs, *head_points_at, *remote_head, *mapped_refs;
+	const struct ref *refs, *mapped_refs;
+	const struct ref *remote_head = NULL;
+	const struct ref *head_points_at = NULL;
 	struct strbuf key = STRBUF_INIT, value = STRBUF_INIT;
 	struct strbuf branch_top = STRBUF_INIT, reflog_msg = STRBUF_INIT;
 	struct transport *transport = NULL;
@@ -545,12 +550,32 @@ 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);
+		if (option_branch) {
+		    const int offset = 11;
+		    const char *branch = option_branch;
+		    if (!prefixcmp(branch, "refs/heads/"))
+			branch += offset;
+
+		    const struct ref *r;
+		    for (r = mapped_refs; r; r = r->next) {
+			if (!strcmp(r->name + offset, branch)) {
+			    /* Override initial branch */
+			    head_points_at = r;
+			    remote_head = r;
+			    break;
+			}
+		    }
+
+		    if (!head_points_at)
+			warning("remote has no branch named '%s', "
+				"falling back to default.", option_branch);
+		}
+
+		if (!head_points_at)
+		    head_points_at = locate_head(refs, mapped_refs, &remote_head);
 	}
 	else {
 		warning("You appear to have cloned an empty repository.");
-		head_points_at = NULL;
-		remote_head = NULL;
 		option_no_checkout = 1;
 		if (!option_bare)
 			install_branch_config("master", option_origin,
-- 
1.6.2.rc2.16.gf474c.dirty

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [PATCH] git-clone: Add option --branch to override initial branch
  2009-03-02 22:11 [PATCH] git-clone: Add option --branch to override initial branch Tor Arne Vestbø
@ 2009-03-02 23:48 ` Johannes Schindelin
  2009-03-03  0:09   ` Junio C Hamano
                     ` (2 more replies)
  0 siblings, 3 replies; 19+ messages in thread
From: Johannes Schindelin @ 2009-03-02 23:48 UTC (permalink / raw)
  To: Tor Arne Vestbø; +Cc: Junio C Hamano, git

[-- Attachment #1: Type: TEXT/PLAIN, Size: 628 bytes --]

Hi,

On Mon, 2 Mar 2009, Tor Arne Vestbø wrote:

> The options --branch and -b allow the user to override the initial 
> branch created and checked out by git-clone. Normally this is the active 
> branch of the remote repository, which is also the fallback if the 
> selected branch is not found.

I do not think that falling back if the selected branch is not found is a 
wise choice.

Besides, the common way to check out something different than the remote's 
HEAD is like this:

	$ git clone -n $URL
	$ cd $DIR
	$ git checkout -t origin/$BRANCH

I am undecided if that is good enough, or your patch is needed.

Ciao,
Dscho

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] git-clone: Add option --branch to override initial branch
  2009-03-02 23:48 ` Johannes Schindelin
@ 2009-03-03  0:09   ` Junio C Hamano
  2009-03-03  0:11   ` Tor Arne Vestbø
  2009-03-03  0:33   ` [PATCH v2] " Tor Arne Vestbø
  2 siblings, 0 replies; 19+ messages in thread
From: Junio C Hamano @ 2009-03-03  0:09 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: Tor Arne Vestbø, git

Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:

> Hi,
>
> On Mon, 2 Mar 2009, Tor Arne Vestbø wrote:
>
>> The options --branch and -b allow the user to override the initial 
>> branch created and checked out by git-clone. Normally this is the active 
>> branch of the remote repository, which is also the fallback if the 
>> selected branch is not found.
>
> I do not think that falling back if the selected branch is not found is a 
> wise choice.
>
> Besides, the common way to check out something different than the remote's 
> HEAD is like this:
>
> 	$ git clone -n $URL
> 	$ cd $DIR
> 	$ git checkout -t origin/$BRANCH
>
> I am undecided if that is good enough, or your patch is needed.

I am fairly negative on this one, if it matters.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] git-clone: Add option --branch to override initial branch
  2009-03-02 23:48 ` Johannes Schindelin
  2009-03-03  0:09   ` Junio C Hamano
@ 2009-03-03  0:11   ` Tor Arne Vestbø
  2009-03-03  0:33   ` [PATCH v2] " Tor Arne Vestbø
  2 siblings, 0 replies; 19+ messages in thread
From: Tor Arne Vestbø @ 2009-03-03  0:11 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: Junio C Hamano, git

Johannes Schindelin wrote:
> On Mon, 2 Mar 2009, Tor Arne Vestbø wrote:
>> The options --branch and -b allow the user to override the initial 
>> branch created and checked out by git-clone. Normally this is the active 
>> branch of the remote repository, which is also the fallback if the 
>> selected branch is not found.
> 
> I do not think that falling back if the selected branch is not found is a 
> wise choice.

Ah, was not sure what the proper response would be. I'll resubmit with a
die() instead.

> Besides, the common way to check out something different than the remote's 
> HEAD is like this:
> 
> 	$ git clone -n $URL
> 	$ cd $DIR
> 	$ git checkout -t origin/$BRANCH

Yepp, plus removing the original branch:

 $ git branch -D $ORIGINAL_ACTIVE_BRANCH # typically master

> I am undecided if that is good enough, or your patch is needed.

The idea was to be able to tell someone "hey, if you want to hack on
some feature for next, do the following:"

 $ git clone git://git.kernel.org/pub/scm/git/git.git -b next

Maybe next is not such a good example, since it does not diverge that
much from master and pu, but imagine a repository with a master, plus
other branches that over time diverge from master (where you would
typically use git-new-workdir to have them in a separate working tree).

In that situation it would be nice to be able to tell someone, hey, if
you want to work on this odd branch which is not master, just do -b.

Tor Arne

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH v2] git-clone: Add option --branch to override initial branch
  2009-03-02 23:48 ` Johannes Schindelin
  2009-03-03  0:09   ` Junio C Hamano
  2009-03-03  0:11   ` Tor Arne Vestbø
@ 2009-03-03  0:33   ` Tor Arne Vestbø
  2009-03-03  9:07     ` Johannes Schindelin
  2009-03-04  6:55     ` Junio C Hamano
  2 siblings, 2 replies; 19+ messages in thread
From: Tor Arne Vestbø @ 2009-03-03  0:33 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Johannes.Schindelin

The options --branch and -b allow the user to override the initial
branch created and checked out by git-clone (normally this is the
active branch of the remote repository).

If the selected branch is not found the operation aborts.

Signed-off-by: Tor Arne Vestbø <torarnv@gmail.com>
---

Something like this?

Documentation/git-clone.txt |    5 +++++
 builtin-clone.c             |   32 ++++++++++++++++++++++++++++----
 2 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/Documentation/git-clone.txt b/Documentation/git-clone.txt
index 95f08b9..e7feb4d 100644
--- a/Documentation/git-clone.txt
+++ b/Documentation/git-clone.txt
@@ -119,6 +119,11 @@ then the cloned repository will become corrupt.
 	Instead of using the remote name 'origin' to keep track
 	of the upstream repository, use <name> instead.
 
+--branch <name>::
+-b <name>::
+	Instead of using the remote repository's active branch as the
+	initial branch, use <name> instead.
+
 --upload-pack <upload-pack>::
 -u <upload-pack>::
 	When given, and the repository to clone from is accessed
diff --git a/builtin-clone.c b/builtin-clone.c
index c338910..5fc01ce 100644
--- a/builtin-clone.c
+++ b/builtin-clone.c
@@ -38,6 +38,7 @@ static int option_quiet, option_no_checkout, option_bare, option_mirror;
 static int option_local, option_no_hardlinks, option_shared;
 static char *option_template, *option_reference, *option_depth;
 static char *option_origin = NULL;
+static char *option_branch = NULL;
 static char *option_upload_pack = "git-upload-pack";
 static int option_verbose;
 
@@ -66,6 +67,8 @@ static struct option builtin_clone_options[] = {
 		   "path to git-upload-pack on the remote"),
 	OPT_STRING(0, "depth", &option_depth, "depth",
 		    "create a shallow clone of that depth"),
+	OPT_STRING('b', "branch", &option_branch, "branch",
+		    "initial remote branch to check out"),
 
 	OPT_END()
 };
@@ -372,7 +375,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 	const char *repo_name, *repo, *work_tree, *git_dir;
 	char *path, *dir;
 	int dest_exists;
-	const struct ref *refs, *head_points_at, *remote_head, *mapped_refs;
+	const struct ref *refs, *mapped_refs;
+	const struct ref *remote_head = NULL;
+	const struct ref *head_points_at = NULL;
 	struct strbuf key = STRBUF_INIT, value = STRBUF_INIT;
 	struct strbuf branch_top = STRBUF_INIT, reflog_msg = STRBUF_INIT;
 	struct transport *transport = NULL;
@@ -545,12 +550,31 @@ 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);
+		if (option_branch) {
+		    const int offset = 11;
+		    const char *branch = option_branch;
+		    if (!prefixcmp(branch, "refs/heads/"))
+			branch += offset;
+
+		    const struct ref *r;
+		    for (r = mapped_refs; r; r = r->next) {
+			if (!strcmp(r->name + offset, branch)) {
+			    /* Override initial branch */
+			    head_points_at = r;
+			    remote_head = r;
+			    break;
+			}
+		    }
+
+		    if (!head_points_at)
+			die("remote has no branch named '%s'.", option_branch);
+
+		} else {
+		    head_points_at = locate_head(refs, mapped_refs, &remote_head);
+		}
 	}
 	else {
 		warning("You appear to have cloned an empty repository.");
-		head_points_at = NULL;
-		remote_head = NULL;
 		option_no_checkout = 1;
 		if (!option_bare)
 			install_branch_config("master", option_origin,
-- 
1.6.2.rc2.17.g2aa38

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [PATCH v2] git-clone: Add option --branch to override initial branch
  2009-03-03  0:33   ` [PATCH v2] " Tor Arne Vestbø
@ 2009-03-03  9:07     ` Johannes Schindelin
  2009-03-03 16:47       ` Tor Arne Vestbø
  2009-03-04  6:55     ` Junio C Hamano
  1 sibling, 1 reply; 19+ messages in thread
From: Johannes Schindelin @ 2009-03-03  9:07 UTC (permalink / raw)
  To: Tor Arne Vestbø; +Cc: Junio C Hamano, git

[-- Attachment #1: Type: TEXT/PLAIN, Size: 499 bytes --]

Hi,

On Tue, 3 Mar 2009, Tor Arne Vestbø wrote:

> Something like this?

Leaving unnecessary initialization and funny indentation aside for a 
moment, what about the objection that it might not be necessary?

Keep in mind: your change (as every change) bears the potential to 
introduce bugs and to complicate the user interface.  The change must be 
worth those risks.

So could you make a case (if you resubmit a patch, in the commit message, 
please) why your change is desirable?

Thanks,
Dscho

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2] git-clone: Add option --branch to override initial branch
  2009-03-03  9:07     ` Johannes Schindelin
@ 2009-03-03 16:47       ` Tor Arne Vestbø
  2009-03-03 16:51         ` Junio C Hamano
  0 siblings, 1 reply; 19+ messages in thread
From: Tor Arne Vestbø @ 2009-03-03 16:47 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: Junio C Hamano, git

Johannes Schindelin wrote:
> Leaving unnecessary initialization and funny indentation aside for a 
> moment,

I do appreciate the feedback though. C is not my primary language, and
I'm happy to learn from my mistakes :-)

> Keep in mind: your change (as every change) bears the potential to 
> introduce bugs and to complicate the user interface.  The change must be 
> worth those risks.

I fully understand. Here is my rationale for why it's worth the risk:

Imagine you have a project called Foo, which has active development on 
the 'master' branch, and not quite so active development on the more 
stable version branch '1.6' (which v1.6.0 and v1.6.1 was tagged from).

Now, you want to put up info on the project web page / wiki on how to 
contribute to project Foo. This information is for new contributors -- 
who may be unfamiliar with git and it's inner workings. You write:

"To get started contributing to project Foo, please clone using:

   $ git clone git://git.foo.com/project.git

"

This looks nice and inviting.

You also want to provide instructions for those who would like to 
contribute to the more stable branch of project Foo, 1.6:

"If you would like to contribute to the stable 1.6 branch, do:

   $ git clone -n git://git.foo.com/project.git
   $ cd project
   $ git checkout -t origin/1.6
   $ git branch -D master

"

Which is not so nice and inviting. At least not compared to:

"If you would like to contribute to the stable 1.6 branch, do:

   $ git clone git://git.foo.com/project.git --branch 1.6

"

Remember these are new contributors, unfamiliar with git. Presenting 
them with a list of four commands that have to be run to get started 
(commands which incidentally also are the first-ones new users mix up), 
is not ideal. "What does -n do?", "What does -t do?", "What's a tracking
branch?", "Origin? What's that?", "What does -D do?", "Delete?! Will I 
delete the main development line!?", etc.. :)

Also, remember that these commands are not something that can be 
scripted or put into an alias, because these users have not cloned 
anything yet.

I know Subversions is perhaps not the best ideal, but to contrast:

   $ svn import http://svn.foo.bar/project/trunk
   $ svn import http://svn.foo.bar/project/branches/1.6

Easy to get to a different branch without having to dive into the full 
feature set of the SCM.

So, to conclude, I see this as a usability-feature of git-clone, which 
outweighs the possible risk of introducing new bugs. It's not a feature 
I will personally use that often, but it's one that I think new users 
will appreciate.


Tor Arne

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2] git-clone: Add option --branch to override initial branch
  2009-03-03 16:47       ` Tor Arne Vestbø
@ 2009-03-03 16:51         ` Junio C Hamano
  2009-03-03 17:04           ` Tor Arne Vestbø
  0 siblings, 1 reply; 19+ messages in thread
From: Junio C Hamano @ 2009-03-03 16:51 UTC (permalink / raw)
  To: Tor Arne Vestbø; +Cc: Johannes Schindelin, git

Tor Arne Vestbø <torarnv@gmail.com> writes:

> If you would like to contribute to the stable 1.6 branch, do:
>   $ git clone -n git://git.foo.com/project.git
>   $ cd project
>   $ git checkout -t origin/1.6
>   $ git branch -D master
> Which is not so nice and inviting.

If you are working on 1.6 maintenance track, why discard 'master'?  If the
upstream project calls it 1.6, you can call your fork 1.6 and keep that
checked out.

IOW, _you_ are make it not nice.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2] git-clone: Add option --branch to override initial branch
  2009-03-03 16:51         ` Junio C Hamano
@ 2009-03-03 17:04           ` Tor Arne Vestbø
  2009-03-03 17:07             ` Junio C Hamano
  0 siblings, 1 reply; 19+ messages in thread
From: Tor Arne Vestbø @ 2009-03-03 17:04 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Johannes Schindelin, git

Junio C Hamano wrote:
> Tor Arne Vestbø <torarnv@gmail.com> writes:
> 
>> If you would like to contribute to the stable 1.6 branch, do:
>>   $ git clone -n git://git.foo.com/project.git
>>   $ cd project
>>   $ git checkout -t origin/1.6
>>   $ git branch -D master
>> Which is not so nice and inviting.
> 
> If you are working on 1.6 maintenance track, why discard 'master'?

One example I can think of is if master is moving a lot faster than the 
maintenance track, and you are not interested in master.

[box:/tmp/downstream] $ git branch
* 1.6
   master

[box:/tmp/downstream] $ git pull --rebase
Current branch 1.6 is up to date.

[box:/tmp/downstream] $ git push
To file:///tmp/upstream
  ! [rejected]        master -> master (non-fast forward)
error: failed to push some refs to 'file:///tmp/upstream'

In that case you would either have to ff master all the time (requiring 
a checkout or rebase magic), or do an explicit "git push origin 1.6".

Neither good options when you are trying to teach people that git push 
is the way you submit changes.

Tor Arne

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2] git-clone: Add option --branch to override initial branch
  2009-03-03 17:04           ` Tor Arne Vestbø
@ 2009-03-03 17:07             ` Junio C Hamano
  0 siblings, 0 replies; 19+ messages in thread
From: Junio C Hamano @ 2009-03-03 17:07 UTC (permalink / raw)
  To: Tor Arne Vestbø; +Cc: Johannes Schindelin, git

Tor Arne Vestbø <torarnv@gmail.com> writes:

> In that case you would either have to ff master all the time
> (requiring a checkout or rebase magic), or do an explicit "git push
> origin 1.6".

or do something like:

$ cat >>.git/config <<\EOF
[remote "there"]
    push = HEAD
EOF

just once.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2] git-clone: Add option --branch to override initial branch
  2009-03-03  0:33   ` [PATCH v2] " Tor Arne Vestbø
  2009-03-03  9:07     ` Johannes Schindelin
@ 2009-03-04  6:55     ` Junio C Hamano
  2009-03-04  8:56       ` Johannes Schindelin
                         ` (2 more replies)
  1 sibling, 3 replies; 19+ messages in thread
From: Junio C Hamano @ 2009-03-04  6:55 UTC (permalink / raw)
  To: Tor Arne Vestbø; +Cc: git, Johannes.Schindelin

Tor Arne Vestbø <torarnv@gmail.com> writes:

> The options --branch and -b allow the user to override the initial
> branch created and checked out by git-clone (normally this is the
> active branch of the remote repository).
>
> If the selected branch is not found the operation aborts.
>
> Signed-off-by: Tor Arne Vestbø <torarnv@gmail.com>

The semantics and desirability of the new feature have been already
discussed, and I am not convinced that it is necessary, in the sense that
I do not think I likely ever use this myself, but I am just one of git
users so that is not a strong basis for rejection.

I'll let others discuss more about the design issues, and will only talk
about code in this message.

> diff --git a/builtin-clone.c b/builtin-clone.c
> index c338910..5fc01ce 100644
> --- a/builtin-clone.c
> +++ b/builtin-clone.c
> @@ -38,6 +38,7 @@ static int option_quiet, option_no_checkout, option_bare, option_mirror;
>  static int option_local, option_no_hardlinks, option_shared;
>  static char *option_template, *option_reference, *option_depth;
>  static char *option_origin = NULL;
> +static char *option_branch = NULL;

I see this was copied from the line immediately above, but please do not
initialize static variables to 0 or NULL.  BSS will take care of it.

> @@ -372,7 +375,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
>  	const char *repo_name, *repo, *work_tree, *git_dir;
>  	char *path, *dir;
>  	int dest_exists;
> -	const struct ref *refs, *head_points_at, *remote_head, *mapped_refs;
> +	const struct ref *refs, *mapped_refs;
> +	const struct ref *remote_head = NULL;
> +	const struct ref *head_points_at = NULL;
>  	struct strbuf key = STRBUF_INIT, value = STRBUF_INIT;
>  	struct strbuf branch_top = STRBUF_INIT, reflog_msg = STRBUF_INIT;
>  	struct transport *transport = NULL;
> @@ -545,12 +550,31 @@ 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);
> +		if (option_branch) {
> +		    const int offset = 11;
> +		    const char *branch = option_branch;

One indent level in git code equals a HT, i.e. 8 places.

> +		    if (!prefixcmp(branch, "refs/heads/"))
> +			branch += offset;

I suspect that you are trying to protect your code against somebody
miscounting the length of "refs/heads/" (perhaps when updating this
codepath in git version 47 that keeps local branches somewhere else, such
as "refs/local-heads/"), but this "const int offset" does not buy you
anything.  He will likely to leave "offset" to 11 just the same.

It is a different story if it were done like this:

		static const char heads_prefix[] = "refs/heads/";
                if (!prefixcmp(branch, heads_prefix))
                	branch += strlen(heads_prefix);

to let the compiler notice heads_prefix is a constant and optimize the
strlen() out, but I personally think it is overkill.

> +		    const struct ref *r;

We do not tolerate decl-after-statement.

> +		    for (r = mapped_refs; r; r = r->next) {
> +			if (!strcmp(r->name + offset, branch)) {
> +			    /* Override initial branch */
> +			    head_points_at = r;
> +			    remote_head = r;
> +			    break;
> +			}
> +		    }

This duplicates major part of what locate_head() does but with a different
target other than "master", doesn't it?

You would want to refactor this, but I think 'next/pu' already has some
refactoring of the locate_head() logic, so you may want to look at it and
either build your changes on top of it, or wait until that other topic to
stabilize.

> +		    if (!head_points_at)
> +			die("remote has no branch named '%s'.", option_branch);
> +
> +		} else {
> +		    head_points_at = locate_head(refs, mapped_refs, &remote_head);
> +		}

This falls into more personal taste than coding guideline, but it often is
easier to read to arrange your code:

	if (... condition ...) {
        	shorter codepath
	} else {
        	much
                longer
                code
                path
	}

For one thing, it is much easier to miss a short "else" clause hanging at
the end of loooong "if" part.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2] git-clone: Add option --branch to override initial branch
  2009-03-04  6:55     ` Junio C Hamano
@ 2009-03-04  8:56       ` Johannes Schindelin
  2009-03-04 10:23       ` Tor Arne Vestbø
  2009-03-09 14:39       ` Paolo Ciarrocchi
  2 siblings, 0 replies; 19+ messages in thread
From: Johannes Schindelin @ 2009-03-04  8:56 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Tor Arne Vestbø, git

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1036 bytes --]

Hi,

On Tue, 3 Mar 2009, Junio C Hamano wrote:

> Tor Arne Vestbø <torarnv@gmail.com> writes:
> 
> > +		    if (!prefixcmp(branch, "refs/heads/"))
> > +			branch += offset;
> 
> I suspect that you are trying to protect your code against somebody
> miscounting the length of "refs/heads/" (perhaps when updating this
> codepath in git version 47 that keeps local branches somewhere else, such
> as "refs/local-heads/"), but this "const int offset" does not buy you
> anything.  He will likely to leave "offset" to 11 just the same.
> 
> It is a different story if it were done like this:
> 
> 		static const char heads_prefix[] = "refs/heads/";
>                 if (!prefixcmp(branch, heads_prefix))
>                 	branch += strlen(heads_prefix);
> 
> to let the compiler notice heads_prefix is a constant and optimize the
> strlen() out, but I personally think it is overkill.

Of course you could also do this instead (which I personally think would 
not be overkill):

		branch = skip_prefix(branch, "refs/heads/");

Ciao,
Dscho

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2] git-clone: Add option --branch to override initial branch
  2009-03-04  6:55     ` Junio C Hamano
  2009-03-04  8:56       ` Johannes Schindelin
@ 2009-03-04 10:23       ` Tor Arne Vestbø
  2009-03-09 14:39       ` Paolo Ciarrocchi
  2 siblings, 0 replies; 19+ messages in thread
From: Tor Arne Vestbø @ 2009-03-04 10:23 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Johannes.Schindelin

Junio C Hamano wrote:
> I'll let others discuss more about the design issues, and will only talk
> about code in this message.

[...snip...]

Great feedback, much appreciated! :) I'll work up a new patch as soon as 
I have some free cycles. Thanks!

Tor Arne

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2] git-clone: Add option --branch to override initial branch
  2009-03-04  6:55     ` Junio C Hamano
  2009-03-04  8:56       ` Johannes Schindelin
  2009-03-04 10:23       ` Tor Arne Vestbø
@ 2009-03-09 14:39       ` Paolo Ciarrocchi
  2009-03-09 16:01         ` Felipe Contreras
  2 siblings, 1 reply; 19+ messages in thread
From: Paolo Ciarrocchi @ 2009-03-09 14:39 UTC (permalink / raw)
  To: git

Junio C Hamano <gitster <at> pobox.com> writes:

> 
> Tor Arne Vestbø <torarnv <at> gmail.com> writes:
> 
> > The options --branch and -b allow the user to override the initial
> > branch created and checked out by git-clone (normally this is the
> > active branch of the remote repository).
> >
> > If the selected branch is not found the operation aborts.
> >
> > Signed-off-by: Tor Arne Vestbø <torarnv <at> gmail.com>
> 
> The semantics and desirability of the new feature have been already
> discussed, and I am not convinced that it is necessary, in the sense that
> I do not think I likely ever use this myself, but I am just one of git
> users so that is not a strong basis for rejection.

I wrote a comment about the --branch approach a couple of days ago, dunno why
but this thread never reached my inbox (replying via gmame web interface).

http://thread.gmane.org/gmane.comp.version-control.git/112527

As I wrote in my post a friend of mine, new to git, was looking for the
possibility of cloning a repo and automatically checkout a specific branch.

Regards,
           Paolo

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2] git-clone: Add option --branch to override initial  branch
  2009-03-09 14:39       ` Paolo Ciarrocchi
@ 2009-03-09 16:01         ` Felipe Contreras
  2009-03-11  8:52           ` Paolo Ciarrocchi
  0 siblings, 1 reply; 19+ messages in thread
From: Felipe Contreras @ 2009-03-09 16:01 UTC (permalink / raw)
  To: Paolo Ciarrocchi; +Cc: git

On Mon, Mar 9, 2009 at 4:39 PM, Paolo Ciarrocchi
<paolo.ciarrocchi@gmail.com> wrote:
> Junio C Hamano <gitster <at> pobox.com> writes:
>
>>
>> Tor Arne Vestbø <torarnv <at> gmail.com> writes:
>>
>> > The options --branch and -b allow the user to override the initial
>> > branch created and checked out by git-clone (normally this is the
>> > active branch of the remote repository).
>> >
>> > If the selected branch is not found the operation aborts.
>> >
>> > Signed-off-by: Tor Arne Vestbø <torarnv <at> gmail.com>
>>
>> The semantics and desirability of the new feature have been already
>> discussed, and I am not convinced that it is necessary, in the sense that
>> I do not think I likely ever use this myself, but I am just one of git
>> users so that is not a strong basis for rejection.
>
> I wrote a comment about the --branch approach a couple of days ago, dunno why
> but this thread never reached my inbox (replying via gmame web interface).
>
> http://thread.gmane.org/gmane.comp.version-control.git/112527
>
> As I wrote in my post a friend of mine, new to git, was looking for the
> possibility of cloning a repo and automatically checkout a specific branch.

Yeah, I also would like this option... one-liner for people that don't
know git at all.

me: you want my code? just run this command.

-- 
Felipe Contreras

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2] git-clone: Add option --branch to override initial  branch
  2009-03-09 16:01         ` Felipe Contreras
@ 2009-03-11  8:52           ` Paolo Ciarrocchi
  2009-03-12  4:18             ` Miles Bader
  0 siblings, 1 reply; 19+ messages in thread
From: Paolo Ciarrocchi @ 2009-03-11  8:52 UTC (permalink / raw)
  To: Felipe Contreras; +Cc: git, torarnv, Junio C Hamano, Johannes Schindelin

[restored the CC list]

On Mon, Mar 9, 2009 at 5:01 PM, Felipe Contreras
<felipe.contreras@gmail.com> wrote:
> On Mon, Mar 9, 2009 at 4:39 PM, Paolo Ciarrocchi
> <paolo.ciarrocchi@gmail.com> wrote:
[...]
>> I wrote a comment about the --branch approach a couple of days ago, dunno why
>> but this thread never reached my inbox (replying via gmame web interface).
>>
>> http://thread.gmane.org/gmane.comp.version-control.git/112527
>>
>> As I wrote in my post a friend of mine, new to git, was looking for the
>> possibility of cloning a repo and automatically checkout a specific branch.
>
> Yeah, I also would like this option... one-liner for people that don't
> know git at all.
>
> me: you want my code? just run this command.

Yes, that is what my friend was lookin for.

I told him to use the following procedure:
$ git clone -n URL
$ git checkout -b foo origin/bar

He is now an almost happy git user :-).

That being said, I see the following command as an improvement over
the actual GIT UI:

 $ git clone git://URI -b bar


Ciao,
-- 
Paolo
http://paolo.ciarrocchi.googlepages.com/
http://mypage.vodafone.it/

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2] git-clone: Add option --branch to override initial  branch
  2009-03-11  8:52           ` Paolo Ciarrocchi
@ 2009-03-12  4:18             ` Miles Bader
  2009-03-12  8:48               ` Paolo Ciarrocchi
  0 siblings, 1 reply; 19+ messages in thread
From: Miles Bader @ 2009-03-12  4:18 UTC (permalink / raw)
  To: Paolo Ciarrocchi
  Cc: Felipe Contreras, git, torarnv, Junio C Hamano, Johannes Schindelin

Paolo Ciarrocchi <paolo.ciarrocchi@gmail.com> writes:
> $ git clone -n URL
> $ git checkout -b foo origin/bar
>
> That being said, I see the following command as an improvement over
> the actual GIT UI:
>
>  $ git clone git://URI -b bar

Note that in your original advice, foo and bar can be different, and
it's not clear to me what "-b bar" should do...

Personally I frequently use foo == bar (no local master branch), but I
think another common pattern is foo != bar, but foo or bar == "master".

Maybe a syntax similar to push, like "-b LOCAL_BR:REMOTE_BR",
with "-b BR" being shorthand for "-b BR:BR"?

-Miles

-- 
Happiness, n. An agreeable sensation arising from contemplating the misery of
another.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2] git-clone: Add option --branch to override initial  branch
  2009-03-12  4:18             ` Miles Bader
@ 2009-03-12  8:48               ` Paolo Ciarrocchi
  2009-03-12  9:12                 ` Felipe Contreras
  0 siblings, 1 reply; 19+ messages in thread
From: Paolo Ciarrocchi @ 2009-03-12  8:48 UTC (permalink / raw)
  To: Miles Bader
  Cc: Felipe Contreras, git, torarnv, Junio C Hamano, Johannes Schindelin

On Thu, Mar 12, 2009 at 5:18 AM, Miles Bader <miles@gnu.org> wrote:
> Paolo Ciarrocchi <paolo.ciarrocchi@gmail.com> writes:
>> $ git clone -n URL
>> $ git checkout -b foo origin/bar
>>
>> That being said, I see the following command as an improvement over
>> the actual GIT UI:
>>
>>  $ git clone git://URI -b bar
>
> Note that in your original advice, foo and bar can be different, and
> it's not clear to me what "-b bar" should do...
>
> Personally I frequently use foo == bar (no local master branch), but I
> think another common pattern is foo != bar, but foo or bar == "master".
>
> Maybe a syntax similar to push, like "-b LOCAL_BR:REMOTE_BR",
> with "-b BR" being shorthand for "-b BR:BR"?

Yes, makes sense.

Ciao,
-- 
Paolo
http://paolo.ciarrocchi.googlepages.com/
http://mypage.vodafone.it/

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2] git-clone: Add option --branch to override initial  branch
  2009-03-12  8:48               ` Paolo Ciarrocchi
@ 2009-03-12  9:12                 ` Felipe Contreras
  0 siblings, 0 replies; 19+ messages in thread
From: Felipe Contreras @ 2009-03-12  9:12 UTC (permalink / raw)
  To: Paolo Ciarrocchi
  Cc: Miles Bader, git, torarnv, Junio C Hamano, Johannes Schindelin

On Thu, Mar 12, 2009 at 10:48 AM, Paolo Ciarrocchi
<paolo.ciarrocchi@gmail.com> wrote:
> On Thu, Mar 12, 2009 at 5:18 AM, Miles Bader <miles@gnu.org> wrote:
>> Paolo Ciarrocchi <paolo.ciarrocchi@gmail.com> writes:
>>> $ git clone -n URL
>>> $ git checkout -b foo origin/bar
>>>
>>> That being said, I see the following command as an improvement over
>>> the actual GIT UI:
>>>
>>>  $ git clone git://URI -b bar
>>
>> Note that in your original advice, foo and bar can be different, and
>> it's not clear to me what "-b bar" should do...
>>
>> Personally I frequently use foo == bar (no local master branch), but I
>> think another common pattern is foo != bar, but foo or bar == "master".
>>
>> Maybe a syntax similar to push, like "-b LOCAL_BR:REMOTE_BR",
>> with "-b BR" being shorthand for "-b BR:BR"?
>
> Yes, makes sense.

+1

-- 
Felipe Contreras

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2009-03-12  9:13 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-02 22:11 [PATCH] git-clone: Add option --branch to override initial branch Tor Arne Vestbø
2009-03-02 23:48 ` Johannes Schindelin
2009-03-03  0:09   ` Junio C Hamano
2009-03-03  0:11   ` Tor Arne Vestbø
2009-03-03  0:33   ` [PATCH v2] " Tor Arne Vestbø
2009-03-03  9:07     ` Johannes Schindelin
2009-03-03 16:47       ` Tor Arne Vestbø
2009-03-03 16:51         ` Junio C Hamano
2009-03-03 17:04           ` Tor Arne Vestbø
2009-03-03 17:07             ` Junio C Hamano
2009-03-04  6:55     ` Junio C Hamano
2009-03-04  8:56       ` Johannes Schindelin
2009-03-04 10:23       ` Tor Arne Vestbø
2009-03-09 14:39       ` Paolo Ciarrocchi
2009-03-09 16:01         ` Felipe Contreras
2009-03-11  8:52           ` Paolo Ciarrocchi
2009-03-12  4:18             ` Miles Bader
2009-03-12  8:48               ` Paolo Ciarrocchi
2009-03-12  9:12                 ` Felipe Contreras

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.