Git development
 help / color / mirror / Atom feed
* [PATCH 0/8 v2] improve push's refspec handling
From: Steffen Prohaska @ 2007-10-27 16:49 UTC (permalink / raw)
  To: git

This patch series improves the refspec handling in push.

It is a replacement for the series in sp/push-refspec
(666df53d6868bf56ca6c9ed0a927d612c67fe68c).

The series addresses some issues that were recently discussed on the
mailing list.
- creating remote refs requires a more explicit command [1].
- the current branch can be pushed as "git push HEAD" [2].
- matching of refs use same rules as git rev-parse [3].
- annoying error messages when working with shared repos are supressed [4].

[1] http://marc.info/?l=git&m=119286893014690&w=2
[2] http://marc.info/?l=git&m=119089831513994&w=2
[3] http://marc.info/?l=git&m=119224567631084&w=2
[4] http://marc.info/?t=119305127000001&r=1&w=2


Note, existing setups may break. Therefore, we need to decide if this
series can be applied before git 1.6.

All tests pass.

    Steffen

 Documentation/git-http-push.txt |    6 ++
 Documentation/git-push.txt      |    8 ++-
 Documentation/git-send-pack.txt |   18 ++++-
 builtin-push.c                  |    6 ++-
 builtin-rev-parse.c             |   27 +++++---
 cache.h                         |    2 +
 http-push.c                     |    9 ++-
 remote.c                        |   41 ++++++++----
 remote.h                        |    2 +-
 send-pack.c                     |   70 ++++++++++++++++-----
 sha1_name.c                     |   52 +++++++++++++----
 t/t5516-fetch-push.sh           |  127 ++++++++++++++++++++++++++++++++++++++-
 transport.c                     |    8 ++-
 transport.h                     |    1 +
 14 files changed, 311 insertions(+), 66 deletions(-)

 [PATCH 1/8] push: change push to fail if short ref name does not exist
 [PATCH 2/8] push: teach push new flag --create
    these two should be kept together.

 [PATCH 3/8] add get_sha1_with_real_ref() returning full name of ref on demand

 [PATCH 4/8] rev-parse: teach "git rev-parse --symbolic" to print the full ref name
    This one is a bit off-topic and could be skipped.

 [PATCH 5/8] push, send-pack: support pushing HEAD to real ref name

 [PATCH 6/8] add ref_cmp_full_short() comparing full ref name with a short name
 [PATCH 7/8] push: use same rules as git-rev-parse to resolve refspecs

 [PATCH 8/8] push: teach push to be quiet if local ref is strict subset of remote ref

^ permalink raw reply

* [PATCH 5/8] push, send-pack: support pushing HEAD to real ref name
From: Steffen Prohaska @ 2007-10-27 16:50 UTC (permalink / raw)
  To: git; +Cc: Steffen Prohaska
In-Reply-To: <11935038083369-git-send-email-prohaska@zib.de>

This teaches "push <remote> HEAD" to resolve HEAD on the local
side to its real ref name, e.g. refs/heads/master, and then
use the real ref name on the remote side to search a matching
remote ref.

Signed-off-by: Steffen Prohaska <prohaska@zib.de>
---
 remote.c              |   13 ++++++++++---
 t/t5516-fetch-push.sh |   29 +++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+), 3 deletions(-)

diff --git a/remote.c b/remote.c
index 8908a19..1c96659 100644
--- a/remote.c
+++ b/remote.c
@@ -575,6 +575,8 @@ static struct ref *try_explicit_object_name(const char *name)
 	unsigned char sha1[20];
 	struct ref *ref;
 	int len;
+	char *real_name = 0;
+	const char *best_name;
 
 	if (!*name) {
 		ref = alloc_ref(20);
@@ -582,12 +584,17 @@ static struct ref *try_explicit_object_name(const char *name)
 		hashclr(ref->new_sha1);
 		return ref;
 	}
-	if (get_sha1(name, sha1))
+	if (get_sha1_with_real_ref(name, sha1, &real_name))
 		return NULL;
-	len = strlen(name) + 1;
+	best_name = real_name ? real_name : name;
+	len = strlen(best_name) + 1;
 	ref = alloc_ref(len);
-	memcpy(ref->name, name, len);
+	memcpy(ref->name, best_name, len);
 	hashcpy(ref->new_sha1, sha1);
+
+	if (real_name) {
+		free(real_name);
+	}
 	return ref;
 }
 
diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh
index 42ca0ff..0ff791a 100755
--- a/t/t5516-fetch-push.sh
+++ b/t/t5516-fetch-push.sh
@@ -282,6 +282,35 @@ test_expect_success 'push with colon-less refspec (4)' '
 
 '
 
+test_expect_success 'push with HEAD' '
+
+	mk_test heads/master &&
+	git push testrepo HEAD &&
+	check_push_result $the_commit heads/master
+
+'
+
+test_expect_success 'push with HEAD (--create)' '
+
+	mk_test &&
+	git push --create testrepo HEAD &&
+	check_push_result $the_commit heads/master
+
+'
+
+test_expect_success 'push with HEAD nonexisting at remote' '
+
+	mk_test heads/master &&
+	git checkout -b local master &&
+	if git push testrepo HEAD
+	then
+		echo "Oops, should have failed"
+		false
+	else
+		check_push_result $the_first_commit heads/master
+	fi
+'
+
 test_expect_success 'push with dry-run' '
 
 	mk_test heads/master &&
-- 
1.5.3.4.1261.g626eb

^ permalink raw reply related

* Remove reference to cogito from core-tutorial.txt?
From: Sergei Organov @ 2007-10-27 15:10 UTC (permalink / raw)
  To: git

Hello,

In Documentation/core-tutorial.txt at line 554 there is a note that
begins with

  "Most likely, you are not directly using the core git Plumbing
   commands, but using Porcelain like Cogito..."

As stated on <http://git.or.cz/index.html>, "Cogito was a popular
version control system on top of Git, aiming at seamless user interface
and ease of use. It provided much better user interface in the past days
of Git but by now it is mostly obsolete and currently unmaintained."

I think it's not a good idea to have this in the tutorial. Should this
entire note be removed, or rewritten using git porcelain commands? If
the former, I can make a patch, if the latter, I'm afraid I'm not yet
comfortable enough with git to do it right.

-- 
Sergei.

^ permalink raw reply

* [MinGW PATCH] Rework quote_arg()
From: Nguyễn Thái Ngọc Duy @ 2007-10-27 13:30 UTC (permalink / raw)
  To: git, Johannes Sixt

MS Windows command line is handled in a weird way. This patch addresses:
 - Quote empty arguments
 - Only escape backslashes and double quotation marks inside quoted arguments
 - Quote arguments if they have asterisk or question marks to prevent expansion

The last one is not documented in the link provided in the patch. I encountered
that behavior on cmd.exe, Windows XP. MSYS not tested.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 compat/mingw.c |   31 ++++++++++++++++++++++++++++---
 1 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/compat/mingw.c b/compat/mingw.c
index 22b5e10..90dc080 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -303,6 +303,7 @@ void openlog(const char *ident, int option, int facility)
 {
 }
 
+/* See http://msdn2.microsoft.com/en-us/library/17w5ykft(vs.71).aspx (Parsing C++ Command-Line Arguments */
 static const char *quote_arg(const char *arg)
 {
 	/* count chars to quote */
@@ -310,11 +311,23 @@ static const char *quote_arg(const char *arg)
 	int force_quotes = 0;
 	char *q, *d;
 	const char *p = arg;
+	if (!*p) force_quotes = 1;
 	while (*p) {
-		if (isspace(*p))
+		if (isspace(*p) || *p == '*' || *p == '?')
 			force_quotes = 1;
-		else if (*p == '"' || *p == '\\')
+		else if (*p == '"')
 			n++;
+		else if (*p == '\\') {
+			int count = 0;
+			while (*p == '\\') {
+				count++;
+				p++;
+				len++;
+			}
+			if (*p == '"')
+				n += count*2 + 1;
+			continue;
+		}
 		len++;
 		p++;
 	}
@@ -325,8 +338,20 @@ static const char *quote_arg(const char *arg)
 	d = q = xmalloc(len+n+3);
 	*d++ = '"';
 	while (*arg) {
-		if (*arg == '"' || *arg == '\\')
+		if (*arg == '"')
 			*d++ = '\\';
+		else if (*arg == '\\') {
+			int count = 0;
+			while (*arg == '\\') {
+				count++;
+				*d++ = *arg++;
+			}
+			if (*arg == '"') {
+				while (count-- > 0)
+					*d++ = '\\';
+				*d++ = '\\';
+			}
+		}
 		*d++ = *arg++;
 	}
 	*d++ = '"';
-- 
1.5.3.rc4.3.gab089

^ permalink raw reply related

* git-show-branch doesn't work as advertised?
From: Sergei Organov @ 2007-10-27 13:26 UTC (permalink / raw)
  To: git

Hello,

I'm rather new to git. I'm reading Documentation/core-tutorial.txt from
git repository cloned yesterday [no, it's not the first git manual I
read], and I'm stuck at the example beginning at line 938 of the
tutorial:

------------------------------------------------
$ git show-branch --topo-order master mybranch
* [master] Merge work in mybranch
 ! [mybranch] Some work.
--
-  [master] Merge work in mybranch
*+ [mybranch] Some work.
------------------------------------------------

The problem is that even though the output of git matches the above
output (after I've replayed all the commands to this point), both the
state of the repo and the text below the example in the tutorial suggest
that one commit is missing from the output. In particular, the tutorial
says: "Three commits are shown along with their log messages." and
later "'master~1' is the first parent of 'master' branch head.", while
there are only 2 commits shown and there is no 'master~1' in the output.

The behavior is the same with git version 1.5.2.2 and 1.5.3.4.

For reference, from gitk output, the history looks like this:

.  [master]
.  o Merge work in mybranch
.  |\[mybranch]
.  | o Some work
.  | |
.  o | Some fun
.   \|
.    o Commit message
.    |
.    o Initial commit

Why "[master~1] Some fun." is not shown by git-show-branch?

Another issue. After above confusion I turned to the manual page and
decided to try --independent option, expecting an output similar to the
above, but missing all the common commits. However, to my surprise I've
got just:

$ git show-branch --topo-order --independent master mybranch
715ec06a744a801237c7233f3fb87ad583653c3a

instead. Nowhere the manual page says that this particular option
changes the format of the output so dramatically. And back to the first
issue, there is still only 1 commit shown, while it seems there should
be 2 of them, one from master, and one from mybranch.

-- 
Sergei.

^ permalink raw reply

* Re: [PATCH] Add test case for running from a subdirectory with GIT_WORK_TREE
From: Johannes Schindelin @ 2007-10-27 13:27 UTC (permalink / raw)
  To: Nguyen Thai Ngoc Duy; +Cc: git
In-Reply-To: <fcaeb9bf0710270557n48a01ba2w3a89f65680b946d@mail.gmail.com>

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

Hi,

On Sat, 27 Oct 2007, Nguyen Thai Ngoc Duy wrote:

> On 10/27/07, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
> > Hi,
> >
> > On Sat, 27 Oct 2007, Nguyễn Thái Ngọc Duy wrote:
> >
> > > +mkdir -p work/sub/dir || exit 1
> > > +mv .git work
> > > +if test "$1" = --normal; then
> > > +     say "Normal case"
> > > +else
> > > +     say "Worktree case"
> > > +fi
> > > +test "$1" = --normal || mv work/.git repo.git || exit 1
> > > +
> > > +test "$1" = --normal || export GIT_DIR=$(pwd)/repo.git
> > > +export GIT_CONFIG="$(pwd)"/$GIT_DIR/config
> > > +test "$1" = --normal || export GIT_WORK_TREE=$(pwd)/work
> > > +
> > > +cd work/sub || exit 1
> >
> > Why don't you put this block into a test_expect_success?  And then just
> > make a
> >
> >         for mode in normal worktree
> >         do
> >
> >         ...
> >
> >         done
> >
> > Hmm?  I would like to see this test case in the official git.git.
> 
> Because after normal iteration, the test repository is no longer in
> clean state that the second iteration needs. Maybe I should just
> create another repo then set parameters properly in test_expect_*

Yes, you can do that:

	test_create_repo other-repo

Another option would be that you clean up at the end of the loop.

Ciao,
Dscho

^ permalink raw reply

* [MinGW PATCH] spawnvppe_pipe: Don't overwrite argv[0]
From: Nguyễn Thái Ngọc Duy @ 2007-10-27 13:26 UTC (permalink / raw)
  To: git, Johannes Sixt

Because caller expects it so

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 spawn-pipe.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/spawn-pipe.c b/spawn-pipe.c
index c8f0452..3df7e22 100644
--- a/spawn-pipe.c
+++ b/spawn-pipe.c
@@ -123,6 +123,7 @@ int spawnvppe_pipe(const char *cmd, const char **argv, const char **env,
 		  int pin[], int pout[])
 {
 	const char *cmd_basename = strrchr(cmd, '/');
+	const char *argv0 = argv[0];
 	pid_t pid;
 
 #ifdef __MINGW32__
@@ -214,6 +215,8 @@ int spawnvppe_pipe(const char *cmd, const char **argv, const char **env,
 	}
 #endif
 
+	argv[0] = argv0;
+
 	return pid;
 }
 
-- 
1.5.3.rc4.3.gab089

^ permalink raw reply related

* Re: Minor inconsistency: "git tag" requires space after -m.
From: Sergei Organov @ 2007-10-27 13:14 UTC (permalink / raw)
  To: git
In-Reply-To: <Pine.LNX.4.64.0710271347510.4362@racer.site>

Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> Hi,
>
> On Sat, 27 Oct 2007, Sergei Organov wrote:
>
>> It seems options parsing is somewhat broken in git-tag:
>> 
>> $ git tag -a -m"Annotated tag" annotated-tag
>> usage: git-tag [-n [<num>]] -l [<pattern>] | [-a | -s | -u <key-id>] [-f | -d | -v] [-m <msg> | -F <file>] <tagname> [<head>]
>> $ git tag -a -m "Annotated tag" annotated-tag
>> $ git --version
>> git version 1.5.3.4
>> 
>> This is inconsistent with, say, "git commit", that groks -m"Message"
>> (without space after -m) just fine.
>
> As it happens, we are in the middle of adding our own option parser which 
> probably solves the issue.  Can you please retest when we have that, and 
> use it in builtin-tag?

I'm 100% sure there will be no inconsistencies once you unify options
parsing among the tools, but I won't refrain from re-testing this
anyway.

-- 
Sergei.

^ permalink raw reply

* Re: Minor inconsistency: "git tag" requires space after -m.
From: Johannes Schindelin @ 2007-10-27 12:48 UTC (permalink / raw)
  To: Sergei Organov; +Cc: git
In-Reply-To: <ffv8ul$5a2$1@ger.gmane.org>

Hi,

On Sat, 27 Oct 2007, Sergei Organov wrote:

> It seems options parsing is somewhat broken in git-tag:
> 
> $ git tag -a -m"Annotated tag" annotated-tag
> usage: git-tag [-n [<num>]] -l [<pattern>] | [-a | -s | -u <key-id>] [-f | -d | -v] [-m <msg> | -F <file>] <tagname> [<head>]
> $ git tag -a -m "Annotated tag" annotated-tag
> $ git --version
> git version 1.5.3.4
> 
> This is inconsistent with, say, "git commit", that groks -m"Message"
> (without space after -m) just fine.

As it happens, we are in the middle of adding our own option parser which 
probably solves the issue.  Can you please retest when we have that, and 
use it in builtin-tag?

Thanks,
Dscho

^ permalink raw reply

* Re: [PATCH] Add test case for running from a subdirectory with GIT_WORK_TREE
From: Johannes Schindelin @ 2007-10-27 12:45 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy; +Cc: git
In-Reply-To: <20071027081954.GA23406@laptop>

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

Hi,

On Sat, 27 Oct 2007, Nguyễn Thái Ngọc Duy wrote:

> +mkdir -p work/sub/dir || exit 1
> +mv .git work
> +if test "$1" = --normal; then
> +	say "Normal case"
> +else
> +	say "Worktree case"
> +fi
> +test "$1" = --normal || mv work/.git repo.git || exit 1
> +
> +test "$1" = --normal || export GIT_DIR=$(pwd)/repo.git
> +export GIT_CONFIG="$(pwd)"/$GIT_DIR/config
> +test "$1" = --normal || export GIT_WORK_TREE=$(pwd)/work
> +
> +cd work/sub || exit 1

Why don't you put this block into a test_expect_success?  And then just 
make a

	for mode in normal worktree
	do

	...

	done

Hmm?  I would like to see this test case in the official git.git.

Ciao,
Dscho

^ permalink raw reply

* Re: [PATCH] Add NEED_WORK_TREE for more commands
From: Johannes Schindelin @ 2007-10-27 12:42 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy; +Cc: git
In-Reply-To: <20071027081910.GA23381@laptop>

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

Hi,

On Sat, 27 Oct 2007, Nguyễn Thái Ngọc Duy wrote:

> +		{ "annotate", cmd_annotate, RUN_SETUP | NEED_WORK_TREE },
> +		{ "blame", cmd_blame, RUN_SETUP | NEED_WORK_TREE },

Both can be sensibly run without a work tree: "git blame <commit> <file>"

> +		{ "format-patch", cmd_format_patch, RUN_SETUP | NEED_WORK_TREE },

This can be run without work tree in any case, methinks.  AFAICT 
format-patch only ever uses information from the object database.

> +		{ "ls-files", cmd_ls_files, RUN_SETUP | NEED_WORK_TREE },

That has already been commented on.

> +		{ "reset", cmd_reset, RUN_SETUP | NEED_WORK_TREE },

"git reset --soft HEAD <commit>" makes sense in a bare repository.

> +		{ "update-index", cmd_update_index, RUN_SETUP | NEED_WORK_TREE },

That has been coommented on, too.

I agree that there are modes for these commands (except format-patch), in 
which they want a work-tree, but they have other modes, too, so IMHO it 
should be solved a la 6d9ba67b(Commands requiring a work tree must not run 
in GIT_DIR).  You'll see that ls-files already has some special handling 
here, and this could be refactorised to requires_work_tree(), which should 
make the code much more elegant.

Ciao,
Dscho

^ permalink raw reply

* Re: merge vs rebase: Is visualization in gitk the only problem?
From: Johannes Schindelin @ 2007-10-27 12:33 UTC (permalink / raw)
  To: Steffen Prohaska; +Cc: David Symonds, Git Mailing List
In-Reply-To: <CEA39C15-F9AE-46F5-BBE9-3F7AB0711494@zib.de>

Hi,

On Sat, 27 Oct 2007, Steffen Prohaska wrote:

> Could we somehow send rerere information together with a patch? This 
> would give the upstream maintainer (and everyone else who wants to test 
> the patch) the help needed to do a merge.

IMHO this is not sensible to send over email.  But think I that something 
like this could be done for pullers: they fetch from somewhere, and then 
recreate the rerere information from the merge commits they just got (this 
would have to be a new option to git-rerere, methinks).

Ciao,
Dscho

^ permalink raw reply

* Minor inconsistency: "git tag" requires space after -m.
From: Sergei Organov @ 2007-10-27 11:55 UTC (permalink / raw)
  To: git

Hello,

It seems options parsing is somewhat broken in git-tag:

$ git tag -a -m"Annotated tag" annotated-tag
usage: git-tag [-n [<num>]] -l [<pattern>] | [-a | -s | -u <key-id>] [-f | -d | -v] [-m <msg> | -F <file>] <tagname> [<head>]
$ git tag -a -m "Annotated tag" annotated-tag
$ git --version
git version 1.5.3.4

This is inconsistent with, say, "git commit", that groks -m"Message"
(without space after -m) just fine.

-- 
Sergei.

^ permalink raw reply

* Re: [PATCH] Add NEED_WORK_TREE for more commands
From: Mike Hommey @ 2007-10-27 10:42 UTC (permalink / raw)
  To: Nguyen Thai Ngoc Duy; +Cc: git
In-Reply-To: <20071027101839.GA26043@laptop>

On Sat, Oct 27, 2007 at 05:18:39PM +0700, Nguyen Thai Ngoc Duy wrote:
> On Sat, Oct 27, 2007 at 11:08:22AM +0200, Mike Hommey wrote:
> > On Sat, Oct 27, 2007 at 03:19:10PM +0700, Nguy???n Th??i Ng???c Duy wrote:
> > > 
> > > Signed-off-by: Nguy???n Th??i Ng???c Duy <pclouds@gmail.com>
> > > ---
> > >  git.c |   12 ++++++------
> > >  1 files changed, 6 insertions(+), 6 deletions(-)
> > > 
> > > diff --git a/git.c b/git.c
> > > index 23a430c..9db40b3 100644
> > > --- a/git.c
> > > +++ b/git.c
> > > +		{ "ls-files", cmd_ls_files, RUN_SETUP | NEED_WORK_TREE },
> > > +		{ "update-index", cmd_update_index, RUN_SETUP | NEED_WORK_TREE },
> > 
> > At least these two work very fine without a working tree (and I *do*
> > need them to work without a working tree).
> 
> How can you do that while both need index and a working directory to
> operate?

For example, ls-files -c and update-index --remove don't need more than
the index, and you don't need a working tree to fiddle with the index
with these commands.

By the way, git-rm has a --cached option that allows it to only work on
the index, but it has a NEED_WORK_TREE which prevents its use without a
working tree in such a case (though I don't know if the implementation
itself relies on the working tree or not, but if it does, it shouldn't).
It's sad to have to do 
git-ls-files -c directory | xargs -d "\n" git-update-index --remove
instead of
git-rm -r --cached directory
when you want to remove a directory in a bare repository.

Mike

^ permalink raw reply

* Re: [PATCH] Add NEED_WORK_TREE for more commands
From: Nguyen Thai Ngoc Duy @ 2007-10-27 10:18 UTC (permalink / raw)
  To: Mike Hommey; +Cc: git
In-Reply-To: <20071027090822.GA6789@glandium.org>

On Sat, Oct 27, 2007 at 11:08:22AM +0200, Mike Hommey wrote:
> On Sat, Oct 27, 2007 at 03:19:10PM +0700, Nguy???n Th??i Ng???c Duy wrote:
> > 
> > Signed-off-by: Nguy???n Th??i Ng???c Duy <pclouds@gmail.com>
> > ---
> >  git.c |   12 ++++++------
> >  1 files changed, 6 insertions(+), 6 deletions(-)
> > 
> > diff --git a/git.c b/git.c
> > index 23a430c..9db40b3 100644
> > --- a/git.c
> > +++ b/git.c
> > +		{ "ls-files", cmd_ls_files, RUN_SETUP | NEED_WORK_TREE },
> > +		{ "update-index", cmd_update_index, RUN_SETUP | NEED_WORK_TREE },
> 
> At least these two work very fine without a working tree (and I *do*
> need them to work without a working tree).

How can you do that while both need index and a working directory to
operate?

> Mike

-- 
Duy

^ permalink raw reply

* Re: [POSSIBLE BUG] 'git log' option --no-color adds bogus empty line
From: Marco Costalba @ 2007-10-27 10:01 UTC (permalink / raw)
  To: Johannes Gilger; +Cc: Git Mailing List
In-Reply-To: <472306BA.5060409@hackvalue.de>

On 10/27/07, Johannes Gilger <heipei@hackvalue.de> wrote:
> Marco Costalba wrote:
> > Form git tree:
> >
> > $ git log -n 1 8d863c98b2f9b0d37 | wc
> >       7      28     246
> >
> > $ git log --no-color -n 1 8d863c98b2f9b0d37 | wc
> >       8      28     247
> >
> > $ git --version
> > git version 1.5.3.2.124.g648db
>
> Hi,
>
> using git version 1.5.3.4.383.gd90a7 i can't confirm this, the two
> outputs are of the same length here.
>

Yes. With the latest git everything works as expected.

Sorry fo rthe noise!

Marco

^ permalink raw reply

* Re: [POSSIBLE BUG] 'git log' option --no-color adds bogus empty line
From: Johannes Gilger @ 2007-10-27  9:36 UTC (permalink / raw)
  To: Marco Costalba, Git Mailing List
In-Reply-To: <e5bfff550710270210g6d363b40of597c3160124fb85@mail.gmail.com>

Marco Costalba wrote:
> Form git tree:
> 
> $ git log -n 1 8d863c98b2f9b0d37 | wc
>       7      28     246
> 
> $ git log --no-color -n 1 8d863c98b2f9b0d37 | wc
>       8      28     247
> 
> $ git --version
> git version 1.5.3.2.124.g648db

Hi,

using git version 1.5.3.4.383.gd90a7 i can't confirm this, the two
outputs are of the same length here.

Regards,
Johannes

-- 
Johannes Gilger <heipei@hackvalue.de>
http://hackvalue.de/heipei/
GPG-Key: 0x42F6DE81
GPG-Fingerprint: BB49 F967 775E BB52 3A81  882C 58EE B178 42F6 DE81

^ permalink raw reply

* [POSSIBLE BUG] 'git log' option --no-color adds bogus empty line
From: Marco Costalba @ 2007-10-27  9:10 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git list, Yaacov Akiba Slama

Form git tree:

$ git log -n 1 8d863c98b2f9b0d37 | wc
      7      28     246

$ git log --no-color -n 1 8d863c98b2f9b0d37 | wc
      8      28     247

$ git --version
git version 1.5.3.2.124.g648db

What's worst is that when using --log-size option, the size is always
the same (198 in this case) breaking qgit parsing when --no-color
option is used.

BTW --no-color option is needed to correctly handle repositories where
"diff.color = true" in the configuration as pointed out (and patched)
by Yaacov Akiba Slama.

Thanks
Marco

^ permalink raw reply

* Re: [PATCH] Add NEED_WORK_TREE for more commands
From: Mike Hommey @ 2007-10-27  9:08 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy; +Cc: git
In-Reply-To: <20071027081910.GA23381@laptop>

On Sat, Oct 27, 2007 at 03:19:10PM +0700, Nguyễn Thái Ngọc Duy wrote:
> 
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  git.c |   12 ++++++------
>  1 files changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/git.c b/git.c
> index 23a430c..9db40b3 100644
> --- a/git.c
> +++ b/git.c
> +		{ "ls-files", cmd_ls_files, RUN_SETUP | NEED_WORK_TREE },
> +		{ "update-index", cmd_update_index, RUN_SETUP | NEED_WORK_TREE },

At least these two work very fine without a working tree (and I *do*
need them to work without a working tree).

Mike

^ permalink raw reply

* Re: merge vs rebase: Is visualization in gitk the only problem?
From: Steffen Prohaska @ 2007-10-27  8:58 UTC (permalink / raw)
  To: David Symonds; +Cc: Git Mailing List
In-Reply-To: <ee77f5c20710270116g45a644bp2b6783310e16ff20@mail.gmail.com>


On Oct 27, 2007, at 10:16 AM, David Symonds wrote:

> On 10/27/07, Steffen Prohaska <prohaska@zib.de> wrote:
>>
>> Rebase has definitely benefits but not all of its details
>> are obvious at a first glance. Tell a newbie to read the
>> git rebase man page and explain what git reabase does and
>> you know what I mean. Rebase definitely can help to create a
>> cleaner history. But it rewrites history and therefore destroys
>> information, for example information about the original code
>> base a patch was developed against, or merge conflicts that
>> were resolved. You also need to decide when to use rebase and
>> when to use merge. So you need to make a choice.
>>
>> Why not always use git merge?
>
> I'd use git-rebase for when I'm sending stuff upstream that I don't
> want to force the maintainer to merge, because I can probably do it
> better and quicker by rebasing. Once that's done, the upstream
> maintainer can just do a git-am (or similar), and it'll apply neatly
> on top of the current head. In other words, git-rebase allows the
> "merge effort" to be shifted to the brancher and away from the
> mainline maintainer/developer.

That definitely makes sense.

But you may need to do more merging because you need to merge every
single commit. It may be easier to merge only the final state of
a topic branch.

Could we somehow send rerere information together with a
patch? This would give the upstream maintainer (and everyone
else who wants to test the patch) the help needed to do a merge.

	Steffen

^ permalink raw reply

* [PATCH 7/7] shell should call the new setup_path() to setup $PATH
From: Scott R Parish @ 2007-10-27  8:36 UTC (permalink / raw)
  To: git; +Cc: Scott R Parish
In-Reply-To: <1193474215-6728-6-git-send-email-srp@srparish.net>

Shell currently does its own manual thing for setting up the $PATH;
it can now call setup_path().

Signed-off-by: Scott R Parish <srp@srparish.net>
---
 shell.c |    8 +-------
 1 files changed, 1 insertions(+), 7 deletions(-)

diff --git a/shell.c b/shell.c
index cfe372b..9826109 100644
--- a/shell.c
+++ b/shell.c
@@ -24,17 +24,11 @@ static int do_cvs_cmd(const char *me, char *arg)
 	const char *cvsserver_argv[3] = {
 		"cvsserver", "server", NULL
 	};
-	const char *oldpath = getenv("PATH");
-	struct strbuf newpath = STRBUF_INIT;
 
 	if (!arg || strcmp(arg, "server"))
 		die("git-cvsserver only handles server: %s", arg);
 
-	strbuf_addstr(&newpath, git_exec_path());
-	strbuf_addch(&newpath, ':');
-	strbuf_addstr(&newpath, oldpath);
-
-	setenv("PATH", strbuf_detach(&newpath, NULL), 1);
+	setup_path(NULL);
 
 	return execv_git_cmd(cvsserver_argv);
 }
-- 
gitgui.0.8.4.11178.g9a1bf-dirty

^ permalink raw reply related

* [PATCH 2/7] remove unused/unneeded "pattern" argument of list_commands
From: Scott R Parish @ 2007-10-27  8:36 UTC (permalink / raw)
  To: git; +Cc: Scott R Parish
In-Reply-To: <1193474215-6728-1-git-send-email-srp@srparish.net>

list_commands() currently accepts and ignores a "pattern" argument,
and then hard codes a prefix as well as some magic numbers. This
hardcodes the prefix inside of the function and removes the magic
numbers.

Signed-off-by: Scott R Parish <srp@srparish.net>
---
 help.c |   14 ++++++++------
 1 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/help.c b/help.c
index d4b1818..b636774 100644
--- a/help.c
+++ b/help.c
@@ -93,10 +93,12 @@ static void pretty_print_string_list(struct cmdname **cmdname, int longest)
 	}
 }
 
-static void list_commands(const char *exec_path, const char *pattern)
+static void list_commands(const char *exec_path)
 {
 	unsigned int longest = 0;
 	char path[PATH_MAX];
+	const char *prefix = "git-";
+	int prefix_len = strlen(prefix);
 	int dirlen;
 	DIR *dir = opendir(exec_path);
 	struct dirent *de;
@@ -120,7 +122,7 @@ static void list_commands(const char *exec_path, const char *pattern)
 		struct stat st;
 		int entlen;
 
-		if (prefixcmp(de->d_name, "git-"))
+		if (prefixcmp(de->d_name, prefix))
 			continue;
 		strcpy(path+dirlen, de->d_name);
 		if (stat(path, &st) || /* stat, not lstat */
@@ -128,14 +130,14 @@ static void list_commands(const char *exec_path, const char *pattern)
 		    !(st.st_mode & S_IXUSR))
 			continue;
 
-		entlen = strlen(de->d_name);
+		entlen = strlen(de->d_name) - prefix_len;
 		if (has_extension(de->d_name, ".exe"))
 			entlen -= 4;
 
 		if (longest < entlen)
 			longest = entlen;
 
-		add_cmdname(de->d_name + 4, entlen-4);
+		add_cmdname(de->d_name + prefix_len, entlen);
 	}
 	closedir(dir);
 
@@ -143,7 +145,7 @@ static void list_commands(const char *exec_path, const char *pattern)
 	printf("----------------------------");
 	mput_char('-', strlen(exec_path));
 	putchar('\n');
-	pretty_print_string_list(cmdname, longest - 4);
+	pretty_print_string_list(cmdname, longest);
 	putchar('\n');
 }
 
@@ -210,7 +212,7 @@ int cmd_help(int argc, const char **argv, const char *prefix)
 	else if (!strcmp(help_cmd, "--all") || !strcmp(help_cmd, "-a")) {
 		printf("usage: %s\n\n", git_usage_string);
 		if(exec_path)
-			list_commands(exec_path, "git-*");
+			list_commands(exec_path);
 		exit(0);
 	}
 
-- 
gitgui.0.8.4.11178.g9a1bf-dirty

^ permalink raw reply related

* [PATCH 6/7] walk $PATH to generate list of commands for "help -a"
From: Scott R Parish @ 2007-10-27  8:36 UTC (permalink / raw)
  To: git; +Cc: Scott R Parish
In-Reply-To: <1193474215-6728-5-git-send-email-srp@srparish.net>

Git had previously been using the $PATH for scripts--a previous
patch moved exec'ed commands to also use the $PATH. For consistancy
"help -a" should also use the $PATH.

We walk all the paths in $PATH collecting the names of "git-*"
commands. To help distinguish between the main git commands
and commands picked up elsewhere (probably extensions) we
print them seperately. The main commands are the ones that
are found in the first directory in $PATH that contains the
"git" binary.

Signed-off-by: Scott R Parish <srp@srparish.net>
---
 help.c |  158 ++++++++++++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 125 insertions(+), 33 deletions(-)

diff --git a/help.c b/help.c
index ce3d795..ee4fce0 100644
--- a/help.c
+++ b/help.c
@@ -37,24 +37,29 @@ static inline void mput_char(char c, unsigned int num)
 		putchar(c);
 }
 
-static struct cmdname {
-	size_t len;
-	char name[1];
-} **cmdname;
-static int cmdname_alloc, cmdname_cnt;
-
-static void add_cmdname(const char *name, int len)
+static struct cmdnames {
+	int alloc;
+	int cnt;
+	char *dir;
+	struct cmdname {
+		size_t len;
+		char name[1];
+	} **names;
+} main_cmds, other_cmds;
+
+static void add_cmdname(struct cmdnames *cmds, const char *name, int len)
 {
 	struct cmdname *ent;
-	if (cmdname_alloc <= cmdname_cnt) {
-		cmdname_alloc = cmdname_alloc + 200;
-		cmdname = xrealloc(cmdname, cmdname_alloc * sizeof(*cmdname));
+	if (cmds->alloc <= cmds->cnt) {
+		cmds->alloc = cmds->alloc + 200;
+		cmds->names = xrealloc(cmds->names,
+				       cmds->alloc * sizeof(*cmds->names));
 	}
 	ent = xmalloc(sizeof(*ent) + len);
 	ent->len = len;
 	memcpy(ent->name, name, len);
 	ent->name[len] = 0;
-	cmdname[cmdname_cnt++] = ent;
+	cmds->names[cmds->cnt++] = ent;
 }
 
 static int cmdname_compare(const void *a_, const void *b_)
@@ -64,7 +69,42 @@ static int cmdname_compare(const void *a_, const void *b_)
 	return strcmp(a->name, b->name);
 }
 
-static void pretty_print_string_list(struct cmdname **cmdname, int longest)
+static void uniq(struct cmdnames *cmds)
+{
+	int i, j;
+
+	if (!cmds->cnt)
+		return;
+
+	for (i = j = 1; i < cmds->cnt; i++) {
+		if (strcmp(cmds->names[i]->name, cmds->names[i-1]->name)) {
+			cmds->names[j++] = cmds->names[i];
+		}
+	}
+
+	cmds->cnt = j;
+}
+
+static void subtract_cmds(struct cmdnames *a, struct cmdnames *b) {
+	int ai, aj, bi;
+
+	ai = aj = bi = 0;
+	while (ai < a->cnt && bi < b->cnt) {
+		if (0 > strcmp(a->names[ai]->name, b->names[bi]->name))
+			a->names[aj++] = a->names[ai++];
+		else if (0 > strcmp(a->names[ai]->name, b->names[bi]->name))
+			bi++;
+		else
+			ai++, bi++;
+	}
+
+	while (ai < a->cnt)
+		a->names[aj++] = a->names[ai++];
+
+	a->cnt = aj;
+}
+
+static void pretty_print_string_list(struct cmdnames *cmds, int longest)
 {
 	int cols = 1, rows;
 	int space = longest + 1; /* min 1 SP between words */
@@ -73,9 +113,7 @@ static void pretty_print_string_list(struct cmdname **cmdname, int longest)
 
 	if (space < max_cols)
 		cols = max_cols / space;
-	rows = (cmdname_cnt + cols - 1) / cols;
-
-	qsort(cmdname, cmdname_cnt, sizeof(*cmdname), cmdname_compare);
+	rows = (cmds->cnt + cols - 1) / cols;
 
 	for (i = 0; i < rows; i++) {
 		printf("  ");
@@ -83,31 +121,39 @@ static void pretty_print_string_list(struct cmdname **cmdname, int longest)
 		for (j = 0; j < cols; j++) {
 			int n = j * rows + i;
 			int size = space;
-			if (n >= cmdname_cnt)
+			if (n >= cmds->cnt)
 				break;
-			if (j == cols-1 || n + rows >= cmdname_cnt)
+			if (j == cols-1 || n + rows >= cmds->cnt)
 				size = 1;
-			printf("%-*s", size, cmdname[n]->name);
+			printf("%-*s", size, cmds->names[n]->name);
 		}
 		putchar('\n');
 	}
 }
 
-static void list_commands(const char *exec_path)
+static unsigned int list_commands_in_dir(const char *dir)
 {
 	unsigned int longest = 0;
 	const char *prefix = "git-";
 	int prefix_len = strlen(prefix);
-	DIR *dir = opendir(exec_path);
+	DIR *dirp = opendir(dir);
+	struct cmdnames *cmds;
 	struct dirent *de;
+	struct stat st;
 
-	if (!dir || chdir(exec_path)) {
-		fprintf(stderr, "git: '%s': %s\n", exec_path, strerror(errno));
-		exit(1);
+	if (!dirp || chdir(dir))
+		return 0;
+
+	if (!main_cmds.cnt &&
+	    !stat("git", &st) &&
+	    S_ISREG(st.st_mode) && (st.st_mode & S_IXUSR)) {
+		cmds = &main_cmds;
+		cmds->dir = xstrdup(dir);
 	}
+	else
+		cmds = &other_cmds;
 
-	while ((de = readdir(dir)) != NULL) {
-		struct stat st;
+	while ((de = readdir(dirp)) != NULL) {
 		int entlen;
 
 		if (prefixcmp(de->d_name, prefix))
@@ -122,18 +168,66 @@ static void list_commands(const char *exec_path)
 		if (has_extension(de->d_name, ".exe"))
 			entlen -= 4;
 
+		if (has_extension(de->d_name, ".perl") ||
+		    has_extension(de->d_name, ".sh"))
+			continue;
+
 		if (longest < entlen)
 			longest = entlen;
 
-		add_cmdname(de->d_name + prefix_len, entlen);
+		add_cmdname(cmds, de->d_name + prefix_len, entlen);
+	}
+	closedir(dirp);
+
+	return longest;
+}
+
+static void list_commands()
+{
+	unsigned int longest = 0;
+	unsigned int len;
+	const char *env_path = getenv("PATH");
+	char *paths, *path, *colon;
+
+	if (!env_path) {
+		fprintf(stderr, "PATH not set\n");
+		exit(1);
 	}
-	closedir(dir);
 
-	printf("git commands available in '%s'\n", exec_path);
+	path = paths = xstrdup(env_path);
+	while ((char *)1 != path) {
+		if ((colon = strchr(path, ':')))
+			*colon = 0;
+
+		len = list_commands_in_dir(path);
+		longest = MAX(longest, len);
+
+		path = colon + 1;
+	}
+	free(paths);
+
+	qsort(main_cmds.names, main_cmds.cnt,
+	      sizeof(*main_cmds.names), cmdname_compare);
+	uniq(&main_cmds);
+
+	qsort(other_cmds.names, other_cmds.cnt,
+	      sizeof(*other_cmds.names), cmdname_compare);
+	uniq(&other_cmds);
+	subtract_cmds(&other_cmds, &main_cmds);
+
+	printf("available git commands in '%s'\n", main_cmds.dir);
 	printf("----------------------------");
-	mput_char('-', strlen(exec_path));
+	mput_char('-', strlen(main_cmds.dir));
+	putchar('\n');
+	pretty_print_string_list(&main_cmds, longest);
 	putchar('\n');
-	pretty_print_string_list(cmdname, longest);
+
+	if (!other_cmds.cnt)
+		return;
+
+	printf("git commands available from elsewhere on your $PATH\n");
+	printf("---------------------------------------------------\n");
+	pretty_print_string_list(&other_cmds, longest);
 	putchar('\n');
 }
 
@@ -189,7 +283,6 @@ int cmd_version(int argc, const char **argv, const char *prefix)
 int cmd_help(int argc, const char **argv, const char *prefix)
 {
 	const char *help_cmd = argc > 1 ? argv[1] : NULL;
-	const char *exec_path = git_exec_path();
 
 	if (!help_cmd) {
 		printf("usage: %s\n\n", git_usage_string);
@@ -199,8 +292,7 @@ int cmd_help(int argc, const char **argv, const char *prefix)
 
 	else if (!strcmp(help_cmd, "--all") || !strcmp(help_cmd, "-a")) {
 		printf("usage: %s\n\n", git_usage_string);
-		if(exec_path)
-			list_commands(exec_path);
+		list_commands();
 		exit(0);
 	}
 
-- 
gitgui.0.8.4.11178.g9a1bf-dirty

^ permalink raw reply related

* [PATCH 5/7] use only the $PATH for exec'ing git commands
From: Scott R Parish @ 2007-10-27  8:36 UTC (permalink / raw)
  To: git; +Cc: Scott R Parish
In-Reply-To: <1193474215-6728-4-git-send-email-srp@srparish.net>

We need to correctly set up $PATH for non-c based git commands.
Since we already do this, we can just use that $PATH and execvp,
instead of looping over the paths with execve.

This patch adds a setup_path() function to exec_cmd.c, which sets
the $PATH order correctly for our search order. execv_git_cmd() is
stripped down to setting up argv and calling execvp(). git.c's
main() only only needs to call setup_path().

Signed-off-by: Scott R Parish <srp@srparish.net>
---
 exec_cmd.c |  121 ++++++++++++++++++++++++++----------------------------------
 exec_cmd.h |    1 +
 git.c      |   43 +++------------------
 3 files changed, 60 insertions(+), 105 deletions(-)

diff --git a/exec_cmd.c b/exec_cmd.c
index 8b681d0..c228dbf 100644
--- a/exec_cmd.c
+++ b/exec_cmd.c
@@ -29,85 +29,68 @@ const char *git_exec_path(void)
 	return builtin_exec_path;
 }
 
+static void add_path(struct strbuf *out, const char *path)
+{
+	if (path && strlen(path)) {
+		if (is_absolute_path(path))
+			strbuf_addstr(out, path);
+		else
+			strbuf_addstr(out, make_absolute_path(path));
+
+		strbuf_addch(out, ':');
+	}
+}
+
+void setup_path(const char *cmd_path)
+{
+	const char *old_path = getenv("PATH");
+	struct strbuf new_path;
+
+	strbuf_init(&new_path, 0);
+
+	add_path(&new_path, argv_exec_path);
+	add_path(&new_path, getenv(EXEC_PATH_ENVIRONMENT));
+	add_path(&new_path, builtin_exec_path);
+	add_path(&new_path, cmd_path);
+
+	if (old_path)
+		strbuf_addstr(&new_path, old_path);
+	else
+		strbuf_addstr(&new_path, "/usr/local/bin:/usr/bin:/bin");
+
+	setenv("PATH", new_path.buf, 1);
+
+	strbuf_release(&new_path);
+}
 
 int execv_git_cmd(const char **argv)
 {
-	char git_command[PATH_MAX + 1];
-	int i;
-	const char *paths[] = { argv_exec_path,
-				getenv(EXEC_PATH_ENVIRONMENT),
-				builtin_exec_path };
-
-	for (i = 0; i < ARRAY_SIZE(paths); ++i) {
-		size_t len;
-		int rc;
-		const char *exec_dir = paths[i];
-		const char *tmp;
-
-		if (!exec_dir || !*exec_dir) continue;
-
-		if (*exec_dir != '/') {
-			if (!getcwd(git_command, sizeof(git_command))) {
-				fprintf(stderr, "git: cannot determine "
-					"current directory: %s\n",
-					strerror(errno));
-				break;
-			}
-			len = strlen(git_command);
-
-			/* Trivial cleanup */
-			while (!prefixcmp(exec_dir, "./")) {
-				exec_dir += 2;
-				while (*exec_dir == '/')
-					exec_dir++;
-			}
-
-			rc = snprintf(git_command + len,
-				      sizeof(git_command) - len, "/%s",
-				      exec_dir);
-			if (rc < 0 || rc >= sizeof(git_command) - len) {
-				fprintf(stderr, "git: command name given "
-					"is too long.\n");
-				break;
-			}
-		} else {
-			if (strlen(exec_dir) + 1 > sizeof(git_command)) {
-				fprintf(stderr, "git: command name given "
-					"is too long.\n");
-				break;
-			}
-			strcpy(git_command, exec_dir);
-		}
-
-		len = strlen(git_command);
-		rc = snprintf(git_command + len, sizeof(git_command) - len,
-			      "/git-%s", argv[0]);
-		if (rc < 0 || rc >= sizeof(git_command) - len) {
-			fprintf(stderr,
-				"git: command name given is too long.\n");
-			break;
-		}
+	struct strbuf cmd;
+	const char *tmp;
 
-		/* argv[0] must be the git command, but the argv array
-		 * belongs to the caller, and my be reused in
-		 * subsequent loop iterations. Save argv[0] and
-		 * restore it on error.
-		 */
+	strbuf_init(&cmd, 0);
+	strbuf_addf(&cmd, "git-%s", argv[0]);
 
-		tmp = argv[0];
-		argv[0] = git_command;
+	/* argv[0] must be the git command, but the argv array
+	 * belongs to the caller, and my be reused in
+	 * subsequent loop iterations. Save argv[0] and
+	 * restore it on error.
+	 */
+	tmp = argv[0];
+	argv[0] = cmd.buf;
 
-		trace_argv_printf(argv, -1, "trace: exec:");
+	trace_argv_printf(argv, -1, "trace: exec:");
 
-		/* execve() can only ever return if it fails */
-		execve(git_command, (char **)argv, environ);
+	/* execvp() can only ever return if it fails */
+	execvp(cmd.buf, (char **)argv);
 
-		trace_printf("trace: exec failed: %s\n", strerror(errno));
+	trace_printf("trace: exec failed: %s\n", strerror(errno));
 
-		argv[0] = tmp;
-	}
-	return -1;
+	argv[0] = tmp;
 
+	strbuf_release(&cmd);
+
+	return -1;
 }
 
 
diff --git a/exec_cmd.h b/exec_cmd.h
index da99287..a892355 100644
--- a/exec_cmd.h
+++ b/exec_cmd.h
@@ -3,6 +3,7 @@
 
 extern void git_set_argv_exec_path(const char *exec_path);
 extern const char* git_exec_path(void);
+extern void setup_path(const char *);
 extern int execv_git_cmd(const char **argv); /* NULL terminated */
 extern int execl_git_cmd(const char *cmd, ...);
 
diff --git a/git.c b/git.c
index c7cabf5..4e10581 100644
--- a/git.c
+++ b/git.c
@@ -6,28 +6,6 @@
 const char git_usage_string[] =
 	"git [--version] [--exec-path[=GIT_EXEC_PATH]] [-p|--paginate|--no-pager] [--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE] [--help] COMMAND [ARGS]";
 
-static void prepend_to_path(const char *dir, int len)
-{
-	const char *old_path = getenv("PATH");
-	char *path;
-	int path_len = len;
-
-	if (!old_path)
-		old_path = "/usr/local/bin:/usr/bin:/bin";
-
-	path_len = len + strlen(old_path) + 1;
-
-	path = xmalloc(path_len + 1);
-
-	memcpy(path, dir, len);
-	path[len] = ':';
-	memcpy(path + len + 1, old_path, path_len - len);
-
-	setenv("PATH", path, 1);
-
-	free(path);
-}
-
 static int handle_options(const char*** argv, int* argc, int* envchanged)
 {
 	int handled = 0;
@@ -408,7 +386,7 @@ int main(int argc, const char **argv)
 {
 	const char *cmd = argv[0] ? argv[0] : "git-help";
 	char *slash = strrchr(cmd, '/');
-	const char *exec_path = NULL;
+	const char *cmd_path = NULL;
 	int done_alias = 0;
 
 	/*
@@ -418,10 +396,7 @@ int main(int argc, const char **argv)
 	 */
 	if (slash) {
 		*slash++ = 0;
-		if (*cmd == '/')
-			exec_path = cmd;
-		else
-			exec_path = xstrdup(make_absolute_path(cmd));
+		cmd_path = cmd;
 		cmd = slash;
 	}
 
@@ -458,16 +433,12 @@ int main(int argc, const char **argv)
 	cmd = argv[0];
 
 	/*
-	 * We execute external git command via execv_git_cmd(),
-	 * which looks at "--exec-path" option, GIT_EXEC_PATH
-	 * environment, and $(gitexecdir) in Makefile while built,
-	 * in this order.  For scripted commands, we prepend
-	 * the value of the exec_path variable to the PATH.
+	 * We use PATH to find git commands, but we prepend some higher
+	 * precidence paths: the "--exec-path" option, the GIT_EXEC_PATH
+	 * environment, and the $(gitexecdir) from the Makefile at build
+	 * time.
 	 */
-	if (exec_path)
-		prepend_to_path(exec_path, strlen(exec_path));
-	exec_path = git_exec_path();
-	prepend_to_path(exec_path, strlen(exec_path));
+	setup_path(cmd_path);
 
 	while (1) {
 		/* See if it's an internal command */
-- 
gitgui.0.8.4.11178.g9a1bf-dirty

^ permalink raw reply related

* [PATCH 3/7] "current_exec_path" is a misleading name, use "argv_exec_path"
From: Scott R Parish @ 2007-10-27  8:36 UTC (permalink / raw)
  To: git; +Cc: Scott R Parish
In-Reply-To: <1193474215-6728-2-git-send-email-srp@srparish.net>

Signed-off-by: Scott R Parish <srp@srparish.net>
---
 exec_cmd.c |   12 ++++++------
 exec_cmd.h |    2 +-
 git.c      |    2 +-
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/exec_cmd.c b/exec_cmd.c
index 9b74ed2..8b681d0 100644
--- a/exec_cmd.c
+++ b/exec_cmd.c
@@ -5,11 +5,11 @@
 
 extern char **environ;
 static const char *builtin_exec_path = GIT_EXEC_PATH;
-static const char *current_exec_path;
+static const char *argv_exec_path = 0;
 
-void git_set_exec_path(const char *exec_path)
+void git_set_argv_exec_path(const char *exec_path)
 {
-	current_exec_path = exec_path;
+	argv_exec_path = exec_path;
 }
 
 
@@ -18,8 +18,8 @@ const char *git_exec_path(void)
 {
 	const char *env;
 
-	if (current_exec_path)
-		return current_exec_path;
+	if (argv_exec_path)
+		return argv_exec_path;
 
 	env = getenv(EXEC_PATH_ENVIRONMENT);
 	if (env && *env) {
@@ -34,7 +34,7 @@ int execv_git_cmd(const char **argv)
 {
 	char git_command[PATH_MAX + 1];
 	int i;
-	const char *paths[] = { current_exec_path,
+	const char *paths[] = { argv_exec_path,
 				getenv(EXEC_PATH_ENVIRONMENT),
 				builtin_exec_path };
 
diff --git a/exec_cmd.h b/exec_cmd.h
index 849a839..da99287 100644
--- a/exec_cmd.h
+++ b/exec_cmd.h
@@ -1,7 +1,7 @@
 #ifndef GIT_EXEC_CMD_H
 #define GIT_EXEC_CMD_H
 
-extern void git_set_exec_path(const char *exec_path);
+extern void git_set_argv_exec_path(const char *exec_path);
 extern const char* git_exec_path(void);
 extern int execv_git_cmd(const char **argv); /* NULL terminated */
 extern int execl_git_cmd(const char *cmd, ...);
diff --git a/git.c b/git.c
index efed91c..c7cabf5 100644
--- a/git.c
+++ b/git.c
@@ -51,7 +51,7 @@ static int handle_options(const char*** argv, int* argc, int* envchanged)
 		if (!prefixcmp(cmd, "--exec-path")) {
 			cmd += 11;
 			if (*cmd == '=')
-				git_set_exec_path(cmd + 1);
+				git_set_argv_exec_path(cmd + 1);
 			else {
 				puts(git_exec_path());
 				exit(0);
-- 
gitgui.0.8.4.11178.g9a1bf-dirty

^ permalink raw reply related


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox