Skip to contentSkip to conversation

Get rid of .git/branches/ and .git/remotes/?

PATCH In review Johannes Schindelin 9 participants 62 messages Jun 15, 2016 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi,

I just had a crazy idea. Since we have a framework in place to read/write .git/config, I thought that maybe it would be a nice thing to move the information which is in .git/branches or .git/remotes into the config.

Advantages:

- it would be easy to copy your private configuration by copying just one file,

- it would be easy to add a switch to git-fetch/git-pull to actually store/update the URL and head mapping under a certain nick,

- we could get rid of some parsing code, and

- it would arguably be more consistent.

Disadvantage:

- I know, I know, yet another change to the location of this information...

- (very lame) you could not find out which nicks you have stored with "ls"

Comments?

Ciao,
Dscho

P.S.: I did not yet say anything about .git/info/, did I?

#1 lore raw
Quoted 4 lines · Johannes Schindelin

I just had a crazy idea. Since we have a framework in place to read/write .git/config, I thought that maybe it would be a nice thing to move the information which is in .git/branches or .git/remotes into the config.

I considered it, but thee thing is, it really wants "nested names", ie having multi-level base-names for the variables. At the same time, I absolutely _abhor_ horrible crap like XML, which make nesting a fundamental part of their structure.

XML may be "logical", but it has absolutely zero to do with being human-readable and clean. In short, XML is total and absolute CRAP (in fact, the "X" in "XML" stands for "Crap", but the XML designers were also incredibly bad spellers).

So while the basic notion of the git ini file does support nesting (we could just make variable names be "base.level1.final" or any number of levels deep), I don't know what a sane format would be. I have one suggestion that in my opinion "fits" the .ini file syntax (see below), but people may well hate it.

Basically I've considered saying that one or more '.' characters at the start of a section name would mean "re-use the previous one", so we could have (this is a really bad example, just to show the implications):

[core]
[.values]
fixed = true
nested = fine
[..example]
test = Hell yes
[.other]
example = strange
[.]
name = hi

[section]
example = yet another

and that would result in a parse of

core.values.fixed = true
core.values.nested = fine
core.values.example.test = Hell yes
core.other.example = strange
core.name = hi
secontion.example = yet another

and that seems reasonably clean. I'd also allow explicit multi-level section names:

[core.values]
fixed = true

so you could always write the above config file in an alternate format:

[core.values] fixed = true
[core.values] nested = fine
[core.values.example] test = Hell yes
[core.other] example = strange
[core] name = hi
[section] example = yet another

instead, using no implicit nesting at all (or, indeed, even re-using sections like "core.values").

That would allow things like

[branches]
[.origin]
url = master.kernel.org:/pub/scm/git/git.git pull = master:origin
[.mine]
url = my.domain.com:/other/repo pull = master:mine

(which could also be written as

[branches.origin]
url = master.kernel.org:/pub/scm/git/git.git pull = master:origin

[branches.mine]
url = my.domain.com:/other/repo
pull = master:mine

and the following mixed-indentation usage would be technically correct, but perhaps crazy:

[branches.origin]
url = master.kernel.org:/pub/scm/git/git.git pull = master:origin

[.mine]
url = my.domain.com:/other/repo
pull = master:mine

Basically, right now we only allow alphanumeric characters in the base name, and a new section name completely clears the old one. The above would be a very simple extension of that: we would allow '.' in addition to alphanumerics, and any initial '.' characters would _keep_ that many levels of the old name.

I dunno. That seems a nice extension, and it would make these things very unambiguous. But how do other .ini-file-like things do this?

And I'm not 100% convinced that putting these branches in the config file has any real advantages over keeping them as separate files. Having everything in one place is nice, of course, and being able to copy just one file around might be convenient, but it _does_ make the config file more complicated.

Anyway, if you want to play with this, here's a trivial patch that may or may not work.

Linus

----

config.c +13 -0
index 915bb97..3b9f300 100644
@@ -136,6 +136,19 @@ static int get_base_var(char *name)
 			return -1;
 		if (c == ']')
 			return baselen;
+		if (c == '.') {
+			if (!baselen || name[baselen-1] == '.') {
+				for (;;) {
+					if (!name[baselen])
+						return -1;
+					if (name[baselen++] == '.')
+						break;
+				}
+				continue;
+			}
+			name[baselen++] = c;
+			continue;
+		}
 		if (!isalnum(c))
 			return -1;
 		if (baselen > MAXNAME / 2)
#2 lore raw
Quoted 9 lines · Linus Torvalds

and that would result in a parse of

core.values.fixed = true
core.values.nested = fine
core.values.example.test = Hell yes
core.other.example = strange
core.name = hi
secontion.example = yet another

[..]

Quoted 2 lines

I dunno. That seems a nice extension, and it would make these things very unambiguous. But how do other .ini-file-like things do this?

Not sure if this falls in the ".ini-file-like" category, but YAML (www.yaml.org) does nesting based on indentation. Your example would look like

core:
values:
fixed: true
nested: fine
example:
test: Hell yes
other:
example: strange
name: hi
secontion:
example: yet another

or

core:
values: { fixed: true, nested: fine, example: { test: Hell yes } }
other: { example: strange }
name: hi
secontion: { example: 'yet another' }

skimo

#3 lore raw
Quoted 3 lines · Sven Verdoolaege

Not sure if this falls in the ".ini-file-like" category, but YAML (www.yaml.org) does nesting based on indentation.

The main reason I don't like indentation is that it tends to have strange rules for "tab". Some people (incorrectly, of course) think that tabs are not at fixed 8-byte things, so deciding the indentation of a tab often ends up either disallowing tabs altogether (bad) or having other strange rules (disallowing spaces).

So I'm not religiously opposed to it, but I find it to be less than optimal.

I'd rather have just _pure_ braces, but while that is natural to programmers, it's not very natural to most users, I think.

Linus

#4 lore raw
Quoted 3 lines · Linus Torvalds

I'd rather have just _pure_ braces, but while that is natural to programmers, it's not very natural to most users, I think.

Sysadmins should be used to braces too (xinetd, dhcpd, named...).

How many office clerks do you expect to use git?

Signature · 3 lines
Andreas Ericsson                   [email protected]
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231
#5 lore raw
In reply to Linus Torvalds

Hi,

Quoted 7 lines · Linus Torvalds

[branches.origin]
url = master.kernel.org:/pub/scm/git/git.git pull = master:origin

[branches.mine]
url = my.domain.com:/other/repo
pull = master:mine

I like this approach best. In fact, that was my idea on how to go about implementing that feature.

However,

Quoted 7 lines

[branches.origin]
url = master.kernel.org:/pub/scm/git/git.git pull = master:origin

[.mine]
url = my.domain.com:/other/repo
pull = master:mine

I don't like this. Usually, data in ini files is not dependent on its position in the file, with the notable exception of section names. I never ran across nested sections (probably for all the reasons XML is unreadable). And the sections should be exchangable, just for clarities sake.

Quoted 5 lines

And I'm not 100% convinced that putting these branches in the config file has any real advantages over keeping them as separate files. Having everything in one place is nice, of course, and being able to copy just one file around might be convenient, but it _does_ make the config file more complicated.

And it _does_ make finding the information for less savvy git users more easy.

I'm not 100% convinced, either, but it could be a better concept than different files in different places and different formats basically doing the same.

But my thinking went like this: if Pasky and Junio can not agree on one location and format, and therefore none of the two is deprecated, how about giving them a way out they both might be able to agree to?

Ciao,
Dscho

P.S.: Anybody noticed that I did not use 0xb4 in five days?

#6 lore raw

Dear diary, on Sun, Nov 20, 2005 at 08:50:41PM CET, I got a letter where Johannes Schindelin <[email protected]> said that...

Quoted 8 lines
Quoted 5 lines

And I'm not 100% convinced that putting these branches in the config file has any real advantages over keeping them as separate files. Having everything in one place is nice, of course, and being able to copy just one file around might be convenient, but it _does_ make the config file more complicated.

And it _does_ make finding the information for less savvy git users more easy.

Is that so?

I'm not 50% convinced, but if people are excited about it, I can live with it; in that case I would like appropriately powerful git-repo-config, though - so that I can say "list me all branch.* section names". Surely I could play some ugly grep games, but ideally, I would like to avoid peeking into the .git/config file directly altogether in Cogito - call that proper layering. ;-)

Quoted 7 lines

I'm not 100% convinced, either, but it could be a better concept than different files in different places and different formats basically doing the same.

But my thinking went like this: if Pasky and Junio can not agree on one location and format, and therefore none of the two is deprecated, how about giving them a way out they both might be able to agree to?

Now, those are just different concepts. Cogito's "branch" concept maps single local head to a single remote head, 1:1. GIT's "remote" concept maps (possibly not well-defined) bunch of local heads to a remote repository (where they have same or different name) or a piece of it; to accomplish this, it introduces a whole new rather complicated concept, which nevertheless in part shares the namespace with heads (branches).

Surely, remotes are more flexible, but from the end-user perspective they really act just as kind of "macros" compared to branches, except that it's faster when you fetch multiple branches at once than when you do it in sequence. I might add support for multibranch fetches to Cogito, and I still intend to implement "readonly" remotes support for the sake of compatibility with GIT, but I plan to stick to branches otherwise. It's confusing enough to have remote and local heads, and actually remotes make it even more confusing since you direct your "direct touch" with the remote heads, now covered in some more abstract entity.

Signature · 4 lines
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
VI has two modes: the one in which it beeps and the one in which
it doesn't.
#7 lore raw
Quoted 8 lines · Petr Baudis
Quoted 3 lines

But my thinking went like this: if Pasky and Junio can not agree on one location and format, and therefore none of the two is deprecated, how about giving them a way out they both might be able to agree to?

Now, those are just different concepts. Cogito's "branch" concept maps single local head to a single remote head, 1:1. GIT's "remote" concept maps (possibly not well-defined) bunch of local heads to a remote repository (where they have same or different name) or a piece of it...

I agree. They are simply different things and serve different audiences.

When you are asked to pull from somebody else (and when you are playing an integrator role, not an individual developer role, you will be asked to pull from different people) you may not want to immediately pull into your master branch. I usually either do "git checkout -b throwaway master" and pull into it, or run "git fetch remote master:throwaway" followed by "git diff master throwaway" to see what I'll be getting. When you set up one "remotes" file is when you realize that you are pulling this way from the same place number of times, to reduce future typing. So as Pasky says, it is exactly "macro" and not "per branch configuration". It is just "per remote shorthand".

Cogito "branch" matches very naturally to what an individual developer might want to do. You have one branch that you use to do your work tracking one upstream. You can of course have more than one upstream and branch, but the most typical usage would be traditional CVS style setup to get updates from the central location (described in branches/* file), fetch and merge from there and push your changes back. It is very well designed to support this pattern of usage.

It may not make much sense for an integrator-role person to have branches/master file to configure his "master" branch that points at the URL of only one of his subsystem maintainers. An integrator-role person does not need "per branch" configuration in that sense. On the other hand "remotes" may help if the integrator-role person regularly pulls from the same set of subsystem maintainers.

Of course, an individual developer can set up a single remotes file that describes the single upstream, fetching "master:origin" and merging into his "master"; what "remotes" file used that way does not give us, unlike "branch" of Cogito, is that it does not say on which local branch that fetching and merging happens.

#8 lore raw
In reply to Linus Torvalds
Quoted 3 lines · Linus Torvalds

[branches.origin]
url = master.kernel.org:/pub/scm/git/git.git pull = master:origin

Two things:
* base names are case insensitive. Repository shortcuts are case sensitive (and head names, too)
* to get rid of .git/branches/XXX, XXX has to be allowed as base name. But XXX can contain anything a head name can (including ".").

Not really a problem. Use the ' for ' syntax:

[remotes]
url = master.kernel.org:/pub/scm/git/git.git for origin pull = master:origin for origin

Not really nice. We can not have "for" as head name.

Josef

#9 lore raw
Quoted 11 lines · Josef Weidendorfer
Quoted 3 lines · Linus Torvalds

[branches.origin]
url = master.kernel.org:/pub/scm/git/git.git pull = master:origin

Two things:
* base names are case insensitive. Repository shortcuts are case sensitive (and head names, too)
* to get rid of .git/branches/XXX, XXX has to be allowed as base name. But XXX can contain anything a head name can (including ".").

Quoted 7 lines

Not really a problem. Use the ' for ' syntax:

[remotes]
url = master.kernel.org:/pub/scm/git/git.git for origin pull = master:origin for origin

Not really nice. We can not have "for" as head name.

What about another syntax for multivalue vars?
Proposed syntax:

[remote:origin]
url = master.kernel.org:/pub/scm/git/git.git
pull = master:origin

For this, the parser could return
remote.url = master.kernel.org:/pub/scm/git/git.git for origin remote.pull = master:origin for origin

By introducing such a scheme, multi-value vars would fit perfectly for use for .git/remotes or .git/branches.

Josef

#10 lore raw

Hi,

Quoted 10 lines · Josef Weidendorfer

[remote:origin]
url = master.kernel.org:/pub/scm/git/git.git
pull = master:origin

For this, the parser could return
remote.url = master.kernel.org:/pub/scm/git/git.git for origin remote.pull = master:origin for origin

By introducing such a scheme, multi-value vars would fit perfectly for use for .git/remotes or .git/branches.

I don't know if you missed it, but hierarchical config keys were introduced by b17e659dd4007cb1d3eb5ac32b524c0c5ab59601:

[remote.origin]
url = master.kernel.org:/pub/scm/git/git.git pull = master:origin

is parsable by

	git-config-set --get remote.origin.url

now.

Hth,
Dscho

#11 lore raw
Quoted 11 lines · Johannes Schindelin
Quoted 3 lines · Josef Weidendorfer

[remote:origin]
url = master.kernel.org:/pub/scm/git/git.git
pull = master:origin

I don't know if you missed it, but hierarchical config keys were introduced by b17e659dd4007cb1d3eb5ac32b524c0c5ab59601:

[remote.origin]
url = master.kernel.org:/pub/scm/git/git.git pull = master:origin

I know. My suggestion complements hierarchical keys:

[myporcelain.headproperties: my/head.name]
merge.candidates = my/other.head
merge.default = your/master

would be the same as

[myporcelain.headproperties]
merge.candidates = my/other.head for my/head.name merge.default = your/master for my/head.name

It is about specifying the same " for "-part for multiple keys. The idea is to use everything after a ":\s*" in a section name to use as prefix for any " for "-part of keys values given in this section.

Josef

#12 lore raw

Hi,

Quoted 11 lines · Josef Weidendorfer

My suggestion complements hierarchical keys:

[myporcelain.headproperties: my/head.name]
merge.candidates = my/other.head
merge.default = your/master

would be the same as

[myporcelain.headproperties]
merge.candidates = my/other.head for my/head.name merge.default = your/master for my/head.name

Okay. What about this config file?

-- snip --
[myporcelain.headproperties: my/head.name]
merge.candidates = my/other.head
[myporcelain.headproperties]
merge.candidates = blabla for my/head.name
-- snap --

I am not totally opposed to what you are trying, but I think it contradicts the KISS principle. (Note: the restriction that key names must not start with a digit is also a contradiction to that.)

Ciao,
Dscho

#13 lore raw
Quoted 8 lines · Johannes Schindelin

Okay. What about this config file?

-- snip --
[myporcelain.headproperties: my/head.name]
merge.candidates = my/other.head
[myporcelain.headproperties]
merge.candidates = blabla for my/head.name
-- snap --

I am not sure you want to show here. Your example gives

myporcelain.headproperties.merge.candidates = my/other.head for my/head.name myporcelain.headproperties.merge.candidates = blabla for my/head.name

I.e. 2 values for the same variable with the same "for" specification. This is perfectly valid.

Are you talking about the multiple representations for the same thing? Then hierarchical config keys already introduce this:

[myporcelain]
headproperties.merge.candidates = blabla

is the same as

[myprocelain.headproperties.merge]
candidates = blabla

Quoted 2 lines

I am not totally opposed to what you are trying, but I think it contradicts the KISS principle.

This suggestion is about easier reading of config files; IMHO far easier with some use cases; but yes, it is arguable if it's worth an added complexity of config.c/config-set.c.

And of course this is no issue if config files are only to be written by git-config-set. But I do not think this was the goal of the config format.

Josef

Quoted 12 lines

(Note: the restriction that key names must
not start with a digit is also a contradiction to that.)

Ciao,
Dscho

-
To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#14 lore raw

Hi,

Quoted 2 lines · Josef Weidendorfer

[myporcelain]
headproperties.merge.candidates = blabla

With such a config file, git complains loudly. Key names are only allowed to be alphanumerical, and the first letter cannot even be a digit. No dots.

Quoted 3 lines

This suggestion is about easier reading of config files; IMHO far easier with some use cases; but yes, it is arguable if it's worth an added complexity of config.c/config-set.c.

Well, I'll be glad to help the implementation of whatever we agree on.

Ciao,
Dscho

#15 lore raw
In reply to Johannes Schindelin
Quoted 3 lines · Johannes Schindelin
	git-config-set --get remote.origin.url

So... "git-config-set" is used for both getting and setting? Why not just "git-config --set" and "git-config --get" to make things a bit less confusing?

Signature · 3 lines
Andreas Ericsson                   [email protected]
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231
#16 lore raw

Hi,

Quoted 7 lines · Andreas Ericsson
Quoted 3 lines · Johannes Schindelin
	git-config-set --get remote.origin.url

So... "git-config-set" is used for both getting and setting? Why not just "git-config --set" and "git-config --get" to make things a bit less confusing?

I tried to do this more like a proof of a concept (Yeah, famous last words...) and tried to be not so intrusive. There is already a config.c, and to keep with the naming, this would have to move to config-lib.c to make space for config.c which really is the source for git-config$(X).

Should we rename config.c to config-lib.c, and config-set.c to config.c? Personally, I think it too intrusive, but what the heck.

Ciao,
Dscho

#17 lore raw
Quoted 10 lines · Johannes Schindelin
Quoted 2 lines

So... "git-config-set" is used for both getting and setting? Why not just "git-config --set" and "git-config --get" to make things a bit less confusing?

I tried to do this more like a proof of a concept (Yeah, famous last words...) and tried to be not so intrusive. There is already a config.c, and to keep with the naming, this would have to move to config-lib.c to make space for config.c which really is the source for git-config$(X).

Should we rename config.c to config-lib.c, and config-set.c to config.c? Personally, I think it too intrusive, but what the heck.

I do not think that change is intrusive. We've renamed source files number of times ;-).

I somehow get a very funny feeling to see "git-XXXX --get" command that reports different things in different repositories (for obvious reasons) called git-config, and not git-repository-config. But it probably is just me.

Anyway, the whole "remote specification in config file" is not a very high priority for me right now.

#18 lore raw
Quoted 6 lines · Junio C Hamano

I somehow get a very funny feeling to see "git-XXXX --get" command that reports different things in different repositories (for obvious reasons) called git-config, and not git-repository-config. But it probably is just me.

git-repo-config is way friendlier for us poor lazy folks. That last 'y' in "repository" really breaks the flow.

Signature · 3 lines
Andreas Ericsson                   [email protected]
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231
#19 lore raw

Hi,

Quoted 2 lines · Andreas Ericsson

git-repo-config is way friendlier for us poor lazy folks. That last 'y' in "repository" really breaks the flow.

How about "git-local-config"?

Ciao,
Dscho

#20 lore raw
Quoted 11 lines · Johannes Schindelin

Hi,

Quoted 2 lines · Andreas Ericsson

git-repo-config is way friendlier for us poor lazy folks. That last 'y' in "repository" really breaks the flow.

How about "git-local-config"?

Nah. It would really mess things up if there's ever such a thing as a real local config (ie, ~/.gitrc).

git-config-set handles configuration for a particular repo, so git-repo-config is better, IMO.

Signature · 3 lines
Andreas Ericsson                   [email protected]
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231
#21 lore raw
Quoted 2 lines · Andreas Ericsson

git-config-set handles configuration for a particular repo, so git-repo-config is better, IMO.

Ok, so git-repo-config that is. Johannes?

#22 lore raw

PATCH 1/1 Rename git-config-set to git-repo-config

... and adjust all references.

---

On Thu, 24 Nov 2005, Junio C Hamano wrote:

> Andreas Ericsson <[email protected]> writes:
>
> > git-config-set handles configuration for a particular repo, so > > git-repo-config is better, IMO.
>
> Ok, so git-repo-config that is. Johannes?

Sorry, git-mv did not work on my system. I can now confirm that there is *at least* one perl 5.6 version out there which does not like lists in open statements at all. Grmpf.

Further grpmf: Is it intended behaviour that git-diff *detects* renames, while git-format-patch *doesn't*?

 .gitignore                        |    2 +
 Documentation/git-repo-config.txt |   36 +++++++++++++-------------
 Documentation/git.txt             |    6 ++--
 Makefile                          |    2 +
 repo-config.c                     |    2 +
 t/t1300-repo-config.sh            |   52 +++++++++++++++++++------------------
 6 files changed, 50 insertions(+), 50 deletions(-)
.gitignore +1 -1
index 074ebe9..0876525 100644
@@ -17,7 +17,6 @@ git-clone
 git-clone-pack
 git-commit
 git-commit-tree
-git-config-set
 git-convert-objects
 git-count-objects
 git-cvsexportcommit
@@ -77,6 +76,7 @@ git-receive-pack
 git-relink
 git-rename
 git-repack
+git-repo-config
 git-request-pull
 git-reset
 git-resolve
Documentation/git-repo-config.txt renamed from Documentation/git-config-set.txt +18 -18
similarity index 82%
rename from Documentation/git-config-set.txt
rename to Documentation/git-repo-config.txt
index bfbd421..92b9156 100644
@@ -1,19 +1,19 @@
-git-config-set(1)
+git-repo-config(1)
 ===============
 
 NAME
 ----
-git-config-set - Set options in .git/config.
+git-repo-config - Get and set options in .git/config.
 
 
 SYNOPSIS
 --------
-'git-config-set' name [value [value_regex]]
-'git-config-set' --replace-all name [value [value_regex]]
-'git-config-set' --get name [value_regex]
-'git-config-set' --get-all name [value_regex]
-'git-config-set' --unset name [value_regex]
-'git-config-set' --unset-all name [value_regex]
+'git-repo-config' name [value [value_regex]]
+'git-repo-config' --replace-all name [value [value_regex]]
+'git-repo-config' --get name [value_regex]
+'git-repo-config' --get-all name [value_regex]
+'git-repo-config' --unset name [value_regex]
+'git-repo-config' --unset-all name [value_regex]
 
 DESCRIPTION
 -----------
@@ -89,7 +89,7 @@ Given a .git/config like this:
 you can set the filemode to true with
 
 ------------
-% git config-set core.filemode true
+% git repo-config core.filemode true
 ------------
 
 The hypothetic proxy command entries actually have a postfix to discern
@@ -97,7 +97,7 @@ to what URL they apply. Here is how to c
 to "ssh".
 
 ------------
-% git config-set proxy.command '"ssh" for kernel.org' 'for kernel.org$'
+% git repo-config proxy.command '"ssh" for kernel.org' 'for kernel.org$'
 ------------
 
 This makes sure that only the key/value pair for kernel.org is replaced.
@@ -105,7 +105,7 @@ This makes sure that only the key/value 
 To delete the entry for renames, do
 
 ------------
-% git config-set --unset diff.renames
+% git repo-config --unset diff.renames
 ------------
 
 If you want to delete an entry for a multivar (like proxy.command above),
@@ -114,45 +114,45 @@ you have to provide a regex matching the
 To query the value for a given key, do
 
 ------------
-% git config-set --get core.filemode
+% git repo-config --get core.filemode
 ------------
 
 or
 
 ------------
-% git config-set core.filemode
+% git repo-config core.filemode
 ------------
 
 or, to query a multivar:
 
 ------------
-% git config-set --get proxy.command "for kernel.org$"
+% git repo-config --get proxy.command "for kernel.org$"
 ------------
 
 If you want to know all the values for a multivar, do:
 
 ------------
-% git config-set --get-all proxy.command
+% git repo-config --get-all proxy.command
 ------------
 
 If you like to live dangerous, you can replace *all* proxy.commands by a
 new one with
 
 ------------
-% git config-set --replace-all proxy.command ssh
+% git repo-config --replace-all proxy.command ssh
 ------------
 
 However, if you really only want to replace the line for the default proxy,
 i.e. the one without a "for ..." postfix, do something like this:
 
 ------------
-% git config-set proxy.command ssh '! for '
+% git repo-config proxy.command ssh '! for '
 ------------
 
 To actually match only values with an exclamation mark, you have to
 
 ------------
-% git config-set section.key value '[!]'
+% git repo-config section.key value '[!]'
 ------------
 
 
Documentation/git.txt +3 -3
index 694fee8..a518249 100644
@@ -84,9 +84,6 @@ gitlink:git-checkout-index[1]::
 gitlink:git-commit-tree[1]::
 	Creates a new commit object
 
-gitlink:git-config-set[1]::
-	Set options in .git/config.
-
 gitlink:git-hash-object[1]::
 	Computes the object ID from a file.
 
@@ -111,6 +108,9 @@ gitlink:git-prune-packed[1]::
 gitlink:git-read-tree[1]::
 	Reads tree information into the directory index
 
+gitlink:git-repo-config[1]::
+	Get and set options in .git/config.
+
 gitlink:git-unpack-objects[1]::
 	Unpacks objects out of a packed archive.
 
Makefile +1 -1
index 53bba2f..c47eeec 100644
@@ -134,7 +134,7 @@ PROGRAMS = \
 	git-unpack-objects$X git-update-index$X git-update-server-info$X \
 	git-upload-pack$X git-verify-pack$X git-write-tree$X \
 	git-update-ref$X git-symbolic-ref$X git-check-ref-format$X \
-	git-name-rev$X git-pack-redundant$X git-config-set$X git-var$X
+	git-name-rev$X git-pack-redundant$X git-repo-config$X git-var$X
 
 # what 'all' will build and 'install' will install.
 ALL_PROGRAMS = $(PROGRAMS) $(SIMPLE_PROGRAMS) $(SCRIPTS) git$X
repo-config.c renamed from config-set.c +1 -1
similarity index 98%
rename from config-set.c
rename to repo-config.c
index d938f96..b2569b7 100644
@@ -2,7 +2,7 @@
 #include <regex.h>
 
 static const char git_config_set_usage[] =
-"git-config-set [--get | --get-all | --replace-all | --unset | --unset-all] name [value [value_regex]]";
+"git-repo-config [--get | --get-all | --replace-all | --unset | --unset-all] name [value [value_regex]]";
 
 static char* key = NULL;
 static char* value = NULL;
t/t1300-repo-config.sh renamed from t/t1300-config-set.sh +26 -26

158 lines not on this page · raw message

#23 lore raw

Re: [PATCH] Rename git-config-set to git-repo-config

Thanks for the patch. I unfortunately was doing the same, because I wanted to get the repo-format-validation stuff into a presentable shape, and I thought this would interfere with it and wanted to do it first (fortunately it didn't). They are both in the proposed updates branch. At a quick glance, I think your patch is identical to what I did (there aren't that many different ways to rename a command after all).

Quoted 3 lines

Sorry, git-mv did not work on my system. I can now confirm that there is *at least* one perl 5.6 version out there which does not like lists in open statements at all. Grmpf.

Yeah, perl5.8delta says that is 5.8 feature. As discussed on the list with Merlyn, we have a fair amount of backporting, I suspect. At least we should work on 5.6, if not 5.5.

I do not use git-mv myself. It does not work in subdirectories, and typing Documentation/ twice to move just one file is a chore, so I tend to just 'R' (rename) the file, move to the renamed file, and '!' (run shell command on the specified path) with 'git-add', all within a single Emacs dired buffer.

Quoted 2 lines

Further grpmf: Is it intended behaviour that git-diff *detects* renames, while git-format-patch *doesn't*?

I do not want to force all the kernel subsystem maintainers to use git (namely, git-apply) to process e-mails, so format-patch should not default to git specific renaming patches.

An option to git-format-patch _might_ make sense someday. Maybe after the world domination ;-).

Oh, wait. It already can produce renaming patches, just does not do it by default.

Junio "again I forgot what I implemented before; sheesh I even used it myself to feed some patches to Linus" Hamano

#24 lore raw

Re: [PATCH] Rename git-config-set to git-repo-config

Hi,

Quoted 7 lines · Junio C Hamano

Thanks for the patch. I unfortunately was doing the same, because I wanted to get the repo-format-validation stuff into a presentable shape, and I thought this would interfere with it and wanted to do it first (fortunately it didn't). They are both in the proposed updates branch. At a quick glance, I think your patch is identical to what I did (there aren't that many different ways to rename a command after all).

Well, there are differences:

- I did not adjust the length of the "=====" line in the dox,

- I adjusted the punch line to "Get and set options in .git/config." (both in git-repo-config and git, but you have it in git, exchanged...), and

- I did not rename the usage string in repo-config.c.

Quoted 1 line

At least we should work on 5.6, if not 5.5.

Agree. I don't find too many bad things about

	open F, 'git-ls-files -z |' or die 'blabla';
Quoted 5 lines

I do not use git-mv myself. It does not work in subdirectories, and typing Documentation/ twice to move just one file is a chore, so I tend to just 'R' (rename) the file, move to the renamed file, and '!' (run shell command on the specified path) with 'git-add', all within a single Emacs dired buffer.

Well, I don't use Emacs any longer, since it was such a hassle to install it on every machine. I still like it, though.

As for git-mv: looks like we need a "git-perl-setup.perl", right?

Quoted 9 lines

An option to git-format-patch _might_ make sense someday. Maybe after the world domination ;-).

Oh, wait. It already can produce renaming patches, just does not do it by default.

Junio "again I forgot what I implemented before; sheesh I even used it myself to feed some patches to Linus" Hamano

*grin* Thanks for pointing that out, Oh Merciful Maintainer (OMM)!

Ciao,
Dscho "trying to find a place to put his flagellations which is hard in the absence of a last name in his typical signature"

#25 lore raw

Re: [PATCH] Rename git-config-set to git-repo-config

Quoted 1 line · Johannes Schindelin

Well, there are differences:

Thanks; I took yours (big thanks to Tony for teaching us how great topic branches are -- I can just blow my "hold/repoconfig" branch which had only one patch away, apply yours to "master" and merge with other topics), with one minor adjustment.

Quoted 1 line

- I did not adjust the length of the "=====" line in the dox,

In "make doc", asciidoc barfs if they do not match, so I adjusted this.

Quoted 2 lines

Well, I don't use Emacs any longer, since it was such a hassle to install it on every machine. I still like it, though.

I do not encourge use of Emacs to others; I was using it as an excuse for not debugging nor testing it personally myself ;-).

Quoted 1 line

As for git-mv: looks like we need a "git-perl-setup.perl", right?

Depends on what that git-$lang-setup.$lang does, but I am not quite sure. Currently, using git-sh-setup implies you run only from toplevel, with fairly convoluted logic.

I was looking at git-sh-setup does for the last couple of days; and it is really hard to decide what the best approach is to make various pieces subdirectory safe.

Currently git C-level tools works like this:

- Natively, they work only from the project toplevel. Period.

- GIT_DIR defaults to ".git". GIT_OBJECT_DIRECTORY defaults to "$GIT_DIR/objects".

- If GIT_DIR environment variable does not exist, tools that use setup_git_directory() try to find a directory that has a subdirectory that looks like a valid GIT_DIR, and chdir() to that directory. They remember the relative path from the new cwd() to the original. If you started from a subdirectory, they work at the toplevel, but know where it came from e.g. "Documentation/howto/".

The users of setup_git_directory() are responsible for prepending that relative path to user supplied repository relative pathnames. Two functions, prefix_path() and get_pathspec(), are supplied to help this process.

If GIT_DIR environment variable exists, setup_git_directory() does not do any ".git/" discovery (there is no point doing so because the user told us where it is). HOWEVER, as a side effect of having GIT_DIR, they cannot know where their current directory is relative to the project toplevel. IOW, they require to be started at the project toplevel if GIT_DIR environment variable exists, and I think this behaviour is the only one that makes sense [*1*].

- The ones that use enter_repo() takes user supplied path, chdir() to it and sets GIT_DIR=. environment. They work in naked repository without associated working tree so this is a sane behaviour.

- The ones that use neither assume that they are at the project toplevel if they need to access working tree.

Among the scripts, the ones that do _not_ use git-sh-setup but can work in subdirectories work this way:

- Do not do project toplevel discovery, do not do chdir.

- Use only tools that use setup_git_directory().

- If an access to ".git" is needed, find out where it is by running "git-rev-parse --git-dir", but _do_ _not_ export it as GIT_DIR; otherwise the tools that use setup_git_directory() would not work as expected.

- They do _not_ work from subdirectory if the user has GIT_DIR environment set [*2*].

The ones that do use git-sh-setup can use GIT_DIR shell variable given by git-sh-setup, but git-sh-setup does _not_ export it (very important). If GIT_DIR environment was given by the user, the commands would not work from subdirectory because many C-level tools they use have setup_git_directory() internally as mentioned before. Otherwise, GIT_DIR is set to .git by this script, which means these commands can run from the toplevel only.

[Footnote]

*1* This is because GIT_DIR can point at totally out-of-tree. Your working tree can live in tmpfs filesystem and GIT_DIR on safer location. You may lose uncommitted changes in exchange for etter filesystem performance this way.

We _could_ special case when GIT_DIR is set to "/some/path/.git" and "/some/path/" is (grand)*parent directory of the current directory (e.g. /some/path/Documentation/howto), and do the usual chdir() + prefix, but I suspect this leads to more confusion not less. The rules when things work and do not in subdirectories become too complex.

*2* This cannot be helped; see *1* above.

#26 lore raw

PATCH 1/8 git-apply: work from subdirectory.

This adds three things:

- prefix_filename() is like prefix_path() but can be used to name any file on the filesystem, not the files that might go into the index file.

- git-apply uses setup_git_directory() to find out the GIT_DIR and reads configuration file. Later this would allow us to affect the behaviour of the command from the configuration.

- When git-apply is run from a subdirectory, it applies the given patch only to the files under the current directory and below.

---

 apply.c |   15 +++++++++++++++
 cache.h |    1 +
 setup.c |   15 +++++++++++++++
 3 files changed, 31 insertions(+), 0 deletions(-)

applies-to: 9ccf8849fa9b522a344645c2f28f12ab036e30d5 c20b8d006edfa964b3df5e4c5cc28cb93edcb240

apply.c +15 -0
index 50be8f3..ae06d41 100644
@@ -16,6 +16,9 @@
 //  --numstat does numeric diffstat, and doesn't actually apply
 //  --index-info shows the old and new index info for paths if available.
 //
+static const char *prefix;
+static int prefix_length;
+
 static int allow_binary_replacement = 0;
 static int check_index = 0;
 static int write_index = 0;
@@ -1706,6 +1709,12 @@ static int use_patch(struct patch *p)
 			return 0;
 		x = x->next;
 	}
+	if (prefix && *prefix) {
+		int pathlen = strlen(pathname);
+		if (pathlen <= prefix_length ||
+		    memcmp(prefix, pathname, prefix_length))
+			return 0;
+	}
 	return 1;
 }
 
@@ -1784,6 +1793,10 @@ int main(int argc, char **argv)
 	int i;
 	int read_stdin = 1;
 
+	prefix = setup_git_directory();
+	prefix_length = prefix ? strlen(prefix) : 0;
+	git_config(git_default_config);
+
 	for (i = 1; i < argc; i++) {
 		const char *arg = argv[i];
 		int fd;
@@ -1845,6 +1858,8 @@ int main(int argc, char **argv)
 			line_termination = 0;
 			continue;
 		}
+		arg = prefix_filename(prefix, prefix_length, arg);
+
 		fd = open(arg, O_RDONLY);
 		if (fd < 0)
 			usage(apply_usage);
cache.h +1 -0
index 6ac94c5..62920ce 100644
@@ -149,6 +149,7 @@ extern char *get_graft_file(void);
 extern const char **get_pathspec(const char *prefix, const char **pathspec);
 extern const char *setup_git_directory(void);
 extern const char *prefix_path(const char *prefix, int len, const char *path);
+extern const char *prefix_filename(const char *prefix, int len, const char *path);
 
 #define alloc_nr(x) (((x)+16)*3/2)
 
setup.c +15 -0
index ab3c778..54f6a34 100644
@@ -47,6 +47,21 @@ const char *prefix_path(const char *pref
 	return path;
 }
 
+/* 
+ * Unlike prefix_path, this should be used if the named file does
+ * not have to interact with index entry; i.e. name of a random file
+ * on the filesystem.
+ */
+const char *prefix_filename(const char *pfx, int pfx_len, const char *arg)
+{
+	static char path[PATH_MAX];
+	if (!pfx || !*pfx || arg[0] == '/')
+		return arg;
+	memcpy(path, pfx, pfx_len);
+	strcpy(path + pfx_len, arg);
+	return path;
+}
+
 const char **get_pathspec(const char *prefix, const char **pathspec)
 {
 	const char *entry = *pathspec;

---
0.99.9.GIT

#27 lore raw

Re: [PATCH 1/8] git-apply: work from subdirectory.

Quoted 11 lines · Junio C Hamano

This adds three things:

- prefix_filename() is like prefix_path() but can be used to name any file on the filesystem, not the files that might go into the index file.

- git-apply uses setup_git_directory() to find out the GIT_DIR and reads configuration file. Later this would allow us to affect the behaviour of the command from the configuration.

Quoted 5 lines

- When git-apply is run from a subdirectory, it applies the given patch only to the files under the current directory and below.

This breaks git-apply when used to just do a "diffstat", or when used on a non-git repository.

For "git-apply --stat", we definitely don't want to force it inside a git directory. In fact, even _trying_ to find a git directory would be wrong.

The only case where we care about a git directory is the "--index" case. In all other cases we should happily apply it (or stat it).

Linus

#28 lore raw

Re: [PATCH 1/8] git-apply: work from subdirectory.

Quoted 2 lines · Linus Torvalds

This breaks git-apply when used to just do a "diffstat", or when used on a non-git repository.

You are right. Something like this?

An off-topic note (that's why this message is CC'd to larsi). People may notice messages in this thread have accumulated a modest number of References: entries. I read git list via new.gmane.org NNTP server (running fetchnews locally to slurp from there) and noticed droppage on my end --- whose cause turns out to be that gmane NNTP server chops References: entries in the middle and fetchnews rejects such messages, and I am sure I am _not_ going to see this message on my local machine. Has anybody else noticed this problem?

-- >8 --
[PATCH] apply: only do GIT_DIR discovery when running with --index.

It does not have to be run in git repository unless we are applying or checking the patch to the index file.

---

apply.c +10 -7
index ae06d41..1742ab2 100644
@@ -17,7 +17,7 @@
 //  --index-info shows the old and new index info for paths if available.
 //
 static const char *prefix;
-static int prefix_length;
+static int prefix_length = -1;
 
 static int allow_binary_replacement = 0;
 static int check_index = 0;
@@ -1709,7 +1709,7 @@ static int use_patch(struct patch *p)
 			return 0;
 		x = x->next;
 	}
-	if (prefix && *prefix) {
+	if (0 < prefix_length) {
 		int pathlen = strlen(pathname);
 		if (pathlen <= prefix_length ||
 		    memcmp(prefix, pathname, prefix_length))
@@ -1793,10 +1793,6 @@ int main(int argc, char **argv)
 	int i;
 	int read_stdin = 1;
 
-	prefix = setup_git_directory();
-	prefix_length = prefix ? strlen(prefix) : 0;
-	git_config(git_default_config);
-
 	for (i = 1; i < argc; i++) {
 		const char *arg = argv[i];
 		int fd;
@@ -1858,7 +1854,14 @@ int main(int argc, char **argv)
 			line_termination = 0;
 			continue;
 		}
-		arg = prefix_filename(prefix, prefix_length, arg);
+
+		if (check_index && prefix_length < 0) {
+			prefix = setup_git_directory();
+			prefix_length = prefix ? strlen(prefix) : 0;
+			git_config(git_default_config);
+		}
+		if (0 < prefix_length)
+			arg = prefix_filename(prefix, prefix_length, arg);
 
 		fd = open(arg, O_RDONLY);
 		if (fd < 0)
#29 lore raw

Re: [PATCH 1/8] git-apply: work from subdirectory.

Quoted 5 lines · Junio C Hamano

I read git list via new.gmane.org NNTP server (running fetchnews locally to slurp from there) and noticed droppage on my end --- whose cause turns out to be that gmane NNTP server chops References:
entries in the middle and fetchnews rejects such messages, and I am sure I am _not_ going to see this message on my local machine.

No, news.gmane.org doesn't chop any references. But if you happen to use a news reader that takes rfc1036bis and rfc2822 seriously (like, ahem, Gnus), it'll chop the References header to get the size under 1024 octets.

If this gives fetchnews problems, then, er, fetchnews has problems. Serious problems.

Signature · 2 lines
(domestic pets only, the antidote for overdose, milk.)
  [email protected] * Lars Magne Ingebrigtsen

A message that is not in the archive (sent off-list or not yet received): [email protected]

#31 lore raw

Re: [PATCH 1/8] git-apply: work from subdirectory.

Quoted 3 lines · Junio C Hamano

It may be that news.gmane.org doesn't chop, but somebody between vger.kernel.org mailing list manager and what comes out of the newsserver does.

Egads! It's all my fault -- there's some code in the mail-to-news script that's truncating long header lines, and nobody's noticed up 'till now. I've now twiddled it slightly; it should stop mangling References headers now...

Signature · 2 lines
(domestic pets only, the antidote for overdose, milk.)
  [email protected] * Lars Magne Ingebrigtsen
#32 lore raw

Re: [PATCH 1/8] git-apply: work from subdirectory.

Quoted 4 lines · Lars Magne Ingebrigtsen

Egads! It's all my fault -- there's some code in the mail-to-news script that's truncating long header lines, and nobody's noticed up 'till now. I've now twiddled it slightly; it should stop mangling References headers now...

Thanks, it looks good now --- checked with your message I am responding to ;-).

#33 lore raw

Re: [PATCH 1/8] git-apply: work from subdirectory.

In reply to Linus Torvalds
Quoted 2 lines · Linus Torvalds

The only case where we care about a git directory is the "--index" case. In all other cases we should happily apply it (or stat it).

True. We should do the same as peek-remote.

#34 lore raw

Re: [PATCH] Rename git-config-set to git-repo-config

In reply to Junio C Hamano
Quoted 3 lines · Linus Torvalds

Please don't.

We should just make the scripts do it automatically instead.

Don't worry, we are in agreement about that goal.

Quoted 7 lines

"git-rev-parse" already has support for all of this, and you can do

	GIT_DIR=$(git-rev-parse --git-dir)
	GIT_PREFIX=$(git-rev-parse --show-prefix)

where the first one shows the GIT_DIR, and the second one shows where in a git directory we are (empty if we're at the root).

Not in one case -- out-of-tree GIT_DIR. That is what GIT_WORKING_TREE is about.

Quoted 2 lines

In fact, I'd prefer if _every_ command just did the right thing inside a subdirectory.

Of course.

The case your patch does not cover that I am worried about is where GIT_DIR is totally out of the tree. Something like GIT_DIR=/home/torvalds/uemacs.git and working tree at /tmp/uemacs. There is currently no way for the tools to figure out where the working tree toplevel is in such an arrangement, and that is when GIT_WORKING_TREE becomes useful.

Under normal use pattern, with GIT_DIR not in such a funny place but immediately under working tree root, you do not need GIT_DIR nor GIT_WORKING_TREE. We can figure things ourselves by chdir()-up and looking for '.git/' directory.

Quoted 4 lines

I sent out this patch a week or two ago - it still applies, and it still mostly does the right thing. It makes at least "gitk" work right inside a subdirectory, and might make things like "git commit" and friends do the same.

I am afraid it needs more work --- as long as a script uses only C-level that use setup_git_directory(), everything should work, and in such a case you do not even need sh-setup --- asking "git-rev-parse --git-dir" is enough, just like you did in git-add. If the script does not have to know where GIT_DIR is (and I do not think gitk needs to know it, although it digs there by hand), it does not even need to do that. As you said, git-log and git-whatchanged works without any funny trick and are fine examples of that.

Quoted 4 lines

More testing still needed, but I think this is going in the right direction.

Comments? I got none the first time around.

Among the ones I looked at that use git-sh-setup in Documentation directory of git.git:

- git-checkout nor git-reset do not work because git-read-tree does not use setup_git_directory(), and git-sh-setup does not export GIT_DIR.

And exporting GIT_DIR from git-sh-setup is not a solution. To setup_git_directory(), existence of GIT_DIR environment currently means you cannot tell where your toplevel is anymore. We could check GIT_DIR against getcwd() and if it is a grand*parent directory, do an appropriate thing including chdir("$GIT_DIR/..") and returning an adjusted prefix, but we don't. And that would not work if GIT_DIR is really out-of-tree anyway.

That is why I keep saying GIT_WORKING_TREE. We could export both GIT_DIR and GIT_WORKING_TREE from git-sh-setup, and teach the C-level commands that need access to working tree to look at it, just like we default GIT_OBJECT_DIRECTORY from git-sh-setup. People with out of tree GIT_DIR needs to export both GIT_DIR and GIT_WORKING_TREE to override both, just like people with object directory in nonstandard place need to export GIT_OBJECT_DIRECTORY.

Maybe GIT_WORKING_TREE can default to "$GIT_DIR/..", just like GIT_OBJECT_DIRECTORY defaults to "$GIT_DIR/objects".

Another obvious approach is to stop supporting out-of-tree GIT_DIR, but I suspect that probably means we should ignore GIT_DIR environment and always chdir()-up to find .git/ (which is fine and sane but is probably an uncomfortably big change).

- git-prune does not work because git-fsck-objects does not know where GIT_DIR is (again, GIT_DIR not exported).

- git-tag works.

Here is a list of C-level and their subdirectory-readiness status.

These do not look at .git at all -- automatically subdirectory ready ;-):

check-ref-format get-tar-commit-id git index-pack mailinfo mailsplit patch-id shell show-index stripspace verify-pack

Uses setup_git_directory() and subdirectory ready:

cat-file config-set diff-files diff-index diff-stages diff-tree ls-files name-rev rev-list rev-parse show-branch symbolic-ref update-index update-ref var

Uses enter_repo() to work from the toplevel:

daemon receive-pack upload-pack

Wants GIT_DIR to know where it is and working tree access is always toplevel:

apply checkout-index clone-pack commit-tree convert-objects fetch-pack fsck-objects hash-object http-fetch http-push init-db local-fetch ls-tree merge-base merge-index mktag pack-objects pack-redundant peek-remote prune-packed read-tree send-pack ssh-fetch ssh-upload tar-tree unpack-file unpack-objects update-server-info write-tree

#35 lore raw

PATCH 2/8 peek-remote: honor proxy config even from subdirectory.

In reply to Junio C Hamano

Introduce setup_git_directory_gently() which does not die() if called outside a git repository, and use it so that later git_config() would work as expected even from a subdirectory, without failing the whole command if run outside a git repository.

Use it at the beginning of peek-remote so that git:// proxy can be picked up from the configuration file.

---

 cache.h       |    1 +
 peek-remote.c |    3 +++
 setup.c       |   11 ++++++++---
 3 files changed, 12 insertions(+), 3 deletions(-)

applies-to: 6afe0a2dc5da18d1090e8d660e45e2c777bfeaaa 1fe3fae4e1dcd864af4010ee572a3bc6de996e95

cache.h +1 -0
index 62920ce..13806d3 100644
@@ -147,6 +147,7 @@ extern char *get_graft_file(void);
 #define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES"
 
 extern const char **get_pathspec(const char *prefix, const char **pathspec);
+extern const char *setup_git_directory_gently(int *);
 extern const char *setup_git_directory(void);
 extern const char *prefix_path(const char *prefix, int len, const char *path);
 extern const char *prefix_filename(const char *prefix, int len, const char *path);
peek-remote.c +3 -0
index ee49bf3..a90cf22 100644
@@ -27,6 +27,9 @@ int main(int argc, char **argv)
 	char *dest = NULL;
 	int fd[2];
 	pid_t pid;
+	int nongit = 0;
+
+	setup_git_directory_gently(&nongit);
 
 	for (i = 1; i < argc; i++) {
 		char *arg = argv[i];
setup.c +8 -3
index 54f6a34..b697bf9 100644
@@ -107,7 +107,7 @@ static int is_toplevel_directory(void)
 	return 1;
 }
 
-static const char *setup_git_directory_1(void)
+const char *setup_git_directory_gently(int *nongit_ok)
 {
 	static char cwd[PATH_MAX+1];
 	int len, offset;
@@ -154,8 +154,13 @@ static const char *setup_git_directory_1
 			break;
 		chdir("..");
 		do {
-			if (!offset)
+			if (!offset) {
+				if (nongit_ok) {
+					*nongit_ok = 1;
+					return NULL;
+				}
 				die("Not a git repository");
+			}
 		} while (cwd[--offset] != '/');
 	}
 
@@ -171,6 +176,6 @@ static const char *setup_git_directory_1
 
 const char *setup_git_directory(void)
 {
-	const char *retval = setup_git_directory_1();
+	const char *retval = setup_git_directory_gently(NULL);
 	return retval;
 }

---
0.99.9.GIT

#36 lore raw

PATCH 3/8 fsck-objects: work from subdirectory.

In reply to Junio C Hamano

Not much point making it work from subdirectory, but for a consistency make it so.

---

 fsck-objects.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

applies-to: 802056c105a0cb936137f141a8e6e546224f3a07 1bd646921ec7278fad9a38281678227769046291

fsck-objects.c +2 -0
index 0433a1d..90e638e 100644
@@ -431,6 +431,8 @@ int main(int argc, char **argv)
 {
 	int i, heads;
 
+	setup_git_directory();
+
 	for (i = 1; i < argc; i++) {
 		const char *arg = argv[i];
 

---
0.99.9.GIT

#37 lore raw

PATCH 4/8 checkout-index: work from subdirectory.

In reply to Junio C Hamano

With this, git-checkout-index from a subdirectory works as expected. Note that "git-checkout-index -a" checks out files only in the current directory and under.

---

 checkout-index.c |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)

applies-to: 5609c84ffd98e1b253c4cb46523245c3be553624 556dc2ebd6566fc032444224a145d3cb422eecc4

checkout-index.c +11 -1
index dab3778..f1e716d 100644
@@ -34,6 +34,9 @@
  */
 #include "cache.h"
 
+static const char *prefix;
+static int prefix_length;
+
 static struct checkout state = {
 	.base_dir = "",
 	.base_dir_len = 0,
@@ -69,6 +72,10 @@ static int checkout_all(void)
 		struct cache_entry *ce = active_cache[i];
 		if (ce_stage(ce))
 			continue;
+		if (prefix && *prefix &&
+		    ( ce_namelen(ce) <= prefix_length ||
+		      memcmp(prefix, ce->name, prefix_length) ))
+			continue;
 		if (checkout_entry(ce, &state) < 0)
 			errs++;
 	}
@@ -91,6 +98,9 @@ int main(int argc, char **argv)
 	int newfd = -1;
 	int all = 0;
 
+	prefix = setup_git_directory();
+	prefix_length = prefix ? strlen(prefix) : 0;
+
 	if (read_cache() < 0) {
 		die("invalid cache");
 	}
@@ -155,7 +165,7 @@ int main(int argc, char **argv)
 
 		if (all)
 			die("git-checkout-index: don't mix '--all' and explicit filenames");
-		checkout_file(arg);
+		checkout_file(prefix_path(prefix, prefix_length, arg));
 	}
 
 	if (all)

---
0.99.9.GIT

#38 lore raw

PATCH 5/8 hash-object: work within subdirectory.

In reply to Junio C Hamano

When -w is given, it needs to find out where the .git directory is, so run the setup_git_directory() when we see a -w.

---

 hash-object.c |   19 ++++++++++++++++---
 1 files changed, 16 insertions(+), 3 deletions(-)

applies-to: b0041c758e0fc01e5ec05bd0543d04d1a9cb17f5 61fdef6a50c99c98feebd71f499450cf97a8c169

hash-object.c +16 -3
index c8c9adb..3075328 100644
@@ -6,6 +6,9 @@
  */
 #include "cache.h"
 
+static const char *prefix;
+static int prefix_length = -1;
+
 static void hash_object(const char *path, const char *type, int write_object)
 {
 	int fd;
@@ -36,10 +39,20 @@ int main(int argc, char **argv)
 				die(hash_object_usage);
 			type = argv[i];
 		}
-		else if (!strcmp(argv[i], "-w"))
+		else if (!strcmp(argv[i], "-w")) {
+			if (prefix_length < 0) {
+				prefix = setup_git_directory();
+				prefix_length = prefix ? strlen(prefix) : 0;
+			}
 			write_object = 1;
-		else
-			hash_object(argv[i], type, write_object);
+		}
+		else {
+			char *arg = argv[i];
+			if (0 <= prefix_length)
+				arg = prefix_filename(prefix, prefix_length,
+						      arg);
+			hash_object(arg, type, write_object);
+		}
 	}
 	return 0;
 }

---
0.99.9.GIT

#39 lore raw

PATCH 6/8 ls-tree: work from subdirectory.

In reply to Junio C Hamano

This makes ls-tree to work from subdirectory. It defaults to show the paths under the current subdirectory, and interprets user-supplied paths as relative to the current subdirectory.

---

 ls-tree.c |   21 ++++++++++++++++-----
 1 files changed, 16 insertions(+), 5 deletions(-)

applies-to: 4e55e4796ee699c9361b3751a36a85ba282119a8 40af60bb52cd86e1f089eeb89b2d3d79531c55d1

ls-tree.c +16 -5
index d9f15e3..ed546a5 100644
@@ -8,6 +8,8 @@
 #include "tree.h"
 #include "quote.h"
 
+static const char *prefix;
+
 static int line_termination = '\n';
 #define LS_RECURSIVE 1
 #define LS_TREE_ONLY 2
@@ -204,7 +206,7 @@ static int list_one(const char *path)
 	return err;
 }
 
-static int list(char **path)
+static int list(const char **path)
 {
 	int i;
 	int err = 0;
@@ -216,11 +218,16 @@ static int list(char **path)
 static const char ls_tree_usage[] =
 	"git-ls-tree [-d] [-r] [-z] <tree-ish> [path...]";
 
-int main(int argc, char **argv)
+int main(int argc, const char **argv)
 {
-	static char *path0[] = { "", NULL };
-	char **path;
+	static const char *path0[] = { "", NULL };
+	const char **path;
 	unsigned char sha1[20];
+	int nongit = 0;
+
+	prefix = setup_git_directory_gently(&nongit);
+	if (prefix)
+		path0[0] = prefix;
 
 	while (1 < argc && argv[1][0] == '-') {
 		switch (argv[1][1]) {
@@ -244,7 +251,11 @@ int main(int argc, char **argv)
 	if (get_sha1(argv[1], sha1) < 0)
 		usage(ls_tree_usage);
 
-	path = (argc == 2) ? path0 : (argv + 2);
+	if (argc == 2)
+		path = path0;
+	else
+		path = get_pathspec(prefix, argv + 2);
+
 	prepare_root(sha1);
 	if (list(path) < 0)
 		die("list failed");

---
0.99.9.GIT

#40 lore raw

Re: [PATCH 6/8] ls-tree: work from subdirectory.

ls-tree.c line 12

Quoted 9 lines · Junio C Hamano
ls-tree.c +2 -0
@@ -8,6 +8,8 @@
 #include "tree.h"
 #include "quote.h"
 
+static const char *prefix;
+

No need to have this visible outside of "main()".

Quoted 3 lines
ls-tree.c +3 -0
+	prefix = setup_git_directory_gently(&nongit);
+	if (prefix)
+		path0[0] = prefix;

...

ls-tree.c

Quoted 5 lines
ls-tree.c +5 -0
+	if (argc == 2)
+		path = path0;
+	else
+		path = get_pathspec(prefix, argv + 2);
+

And this is just ugly.

git-ls-tree should be rewritten to use a pathspec the same way everybody else does. Right now it's the odd man out: if you do

git-ls-tree HEAD divers/char drivers/

it will show the same files _twice_, which is not how pathspecs in general work.

How about this patch? It breaks some of the git-ls-tree tests, but it makes git-ls-tree work a lot more like other git pathspec commands, and it removes more than 150 lines by re-using the recursive tree traversal (but the "-d" flag is gone for good, so I'm not pushing this too hard).

Linus

---

ls-tree.c +22 -203
index d9f15e3..598b729 100644
@@ -13,215 +13,32 @@ static int line_termination = '\n';
 #define LS_TREE_ONLY 2
 static int ls_options = 0;
 
-static struct tree_entry_list root_entry;
-
-static void prepare_root(unsigned char *sha1)
-{
-	unsigned char rsha[20];
-	unsigned long size;
-	void *buf;
-	struct tree *root_tree;
-
-	buf = read_object_with_reference(sha1, "tree", &size, rsha);
-	free(buf);
-	if (!buf)
-		die("Could not read %s", sha1_to_hex(sha1));
-
-	root_tree = lookup_tree(rsha);
-	if (!root_tree)
-		die("Could not read %s", sha1_to_hex(sha1));
-
-	/* Prepare a fake entry */
-	root_entry.directory = 1;
-	root_entry.executable = root_entry.symlink = 0;
-	root_entry.mode = S_IFDIR;
-	root_entry.name = "";
-	root_entry.item.tree = root_tree;
-	root_entry.parent = NULL;
-}
-
-static int prepare_children(struct tree_entry_list *elem)
-{
-	if (!elem->directory)
-		return -1;
-	if (!elem->item.tree->object.parsed) {
-		struct tree_entry_list *e;
-		if (parse_tree(elem->item.tree))
-			return -1;
-		/* Set up the parent link */
-		for (e = elem->item.tree->entries; e; e = e->next)
-			e->parent = elem;
-	}
-	return 0;
-}
-
-static struct tree_entry_list *find_entry(const char *path, char *pathbuf)
-{
-	const char *next, *slash;
-	int len;
-	struct tree_entry_list *elem = &root_entry, *oldelem = NULL;
-
-	*(pathbuf) = '\0';
-
-	/* Find tree element, descending from root, that
-	 * corresponds to the named path, lazily expanding
-	 * the tree if possible.
-	 */
-
-	while (path) {
-		/* The fact we still have path means that the caller
-		 * wants us to make sure that elem at this point is a
-		 * directory, and possibly descend into it.  Even what
-		 * is left is just trailing slashes, we loop back to
-		 * here, and this call to prepare_children() will
-		 * catch elem not being a tree.  Nice.
-		 */
-		if (prepare_children(elem))
-			return NULL;
-
-		slash = strchr(path, '/');
-		if (!slash) {
-			len = strlen(path);
-			next = NULL;
-		}
-		else {
-			next = slash + 1;
-			len = slash - path;
-		}
-		if (len) {
-			if (oldelem) {
-				pathbuf += sprintf(pathbuf, "%s/", oldelem->name);
-			}
-
-			/* (len == 0) if the original path was "drivers/char/"
-			 * and we have run already two rounds, having elem
-			 * pointing at the drivers/char directory.
-			 */
-			elem = elem->item.tree->entries;
-			while (elem) {
-				if ((strlen(elem->name) == len) &&
-				    !strncmp(elem->name, path, len)) {
-					/* found */
-					break;
-				}
-				elem = elem->next;
-			}
-			if (!elem)
-				return NULL;
-
-			oldelem = elem;
-		}
-		path = next;
-	}
-
-	return elem;
-}
-
-static const char *entry_type(struct tree_entry_list *e)
-{
-	return (e->directory ? "tree" : "blob");
-}
-
-static const char *entry_hex(struct tree_entry_list *e)
-{
-	return sha1_to_hex(e->directory
-			   ? e->item.tree->object.sha1
-			   : e->item.blob->object.sha1);
-}
-
-/* forward declaration for mutually recursive routines */
-static int show_entry(struct tree_entry_list *, int, char *pathbuf);
-
-static int show_children(struct tree_entry_list *e, int level, char *pathbuf)
-{
-	int oldlen = strlen(pathbuf);
-
-	if (e != &root_entry)
-		sprintf(pathbuf + oldlen, "%s/", e->name);
-
-	if (prepare_children(e))
-		die("internal error: ls-tree show_children called with non tree");
-	e = e->item.tree->entries;
-	while (e) {
-		show_entry(e, level, pathbuf);
-		e = e->next;
-	}
-
-	pathbuf[oldlen] = '\0';
-
-	return 0;
-}
+static const char ls_tree_usage[] =
+	"git-ls-tree [-d] [-r] [-z] <tree-ish> [path...]";
 
-static int show_entry(struct tree_entry_list *e, int level, char *pathbuf)
+static int show_tree(unsigned char *sha1, const char *base, int baselen, const char *pathname, unsigned mode, int stage)
 {
-	int err = 0; 
-
-	if (e != &root_entry) {
-		printf("%06o %s %s	",
-		       e->mode, entry_type(e), entry_hex(e));
-		write_name_quoted(pathbuf, e->name, line_termination, stdout);
-		putchar(line_termination);
-	}
+	const char *type = "blob";
+	int retval = 0;
 
-	if (e->directory) {
-		/* If this is a directory, we have the following cases:
-		 * (1) This is the top-level request (explicit path from the
-		 *     command line, or "root" if there is no command line).
-		 *  a. Without any flag.  We show direct children.  We do not 
-		 *     recurse into them.
-		 *  b. With -r.  We do recurse into children.
-		 *  c. With -d.  We do not recurse into children.
-		 * (2) We came here because our caller is either (1-a) or
-		 *     (1-b).
-		 *  a. Without any flag.  We do not show our children (which
-		 *     are grandchildren for the original request).
-		 *  b. With -r.  We continue to recurse into our children.
-		 *  c. With -d.  We should not have come here to begin with.
-		 */
-		if (level == 0 && !(ls_options & LS_TREE_ONLY))
-			/* case (1)-a and (1)-b */
-			err = err | show_children(e, level+1, pathbuf);
-		else if (level && ls_options & LS_RECURSIVE)
-			/* case (2)-b */
-			err = err | show_children(e, level+1, pathbuf);
+	if (S_ISDIR(mode)) {
+		type = "tree";
+		if (ls_options & LS_RECURSIVE)
+			retval = READ_TREE_RECURSIVE;
 	}
-	return err;
-}
 
-static int list_one(const char *path)
-{
-	int err = 0;
-	char pathbuf[MAXPATHLEN + 1];
-	struct tree_entry_list *e = find_entry(path, pathbuf);
-	if (!e) {
-		/* traditionally ls-tree does not complain about
-		 * missing path.  We may change this later to match
-		 * what "/bin/ls -a" does, which is to complain.
-		 */
-		return err;
-	}
-	err = err | show_entry(e, 0, pathbuf);
-	return err;
+	printf("%06o %s %s\t%.*s%s%c", mode, type, sha1_to_hex(sha1), baselen, base, pathname, line_termination);
+	return retval;
 }
 
-static int list(char **path)
+int main(int argc, const char **argv)
 {
-	int i;
-	int err = 0;
-	for (i = 0; path[i]; i++)
-		err = err | list_one(path[i]);
-	return err;
-}
-
-static const char ls_tree_usage[] =
-	"git-ls-tree [-d] [-r] [-z] <tree-ish> [path...]";
-
-int main(int argc, char **argv)
-{
-	static char *path0[] = { "", NULL };
-	char **path;
+	const char **path, *prefix;
 	unsigned char sha1[20];
+	char *buf;
+	unsigned long size;
 
+	prefix = setup_git_directory();
 	while (1 < argc && argv[1][0] == '-') {
 		switch (argv[1][1]) {
 		case 'z':
@@ -244,9 +61,11 @@ int main(int argc, char **argv)
 	if (get_sha1(argv[1], sha1) < 0)
 		usage(ls_tree_usage);
 
-	path = (argc == 2) ? path0 : (argv + 2);
-	prepare_root(sha1);
-	if (list(path) < 0)
-		die("list failed");
+	path = get_pathspec(prefix, argv + 2);
+	buf = read_object_with_reference(sha1, "tree", &size, NULL);
+	if (!buf)
+		die("not a tree object");
+	read_tree_recursive(buf, size, "", 0, 0, path, show_tree);
+
 	return 0;
 }
tree.c +24 -10
index 8b42a07..043f032 100644
@@ -9,9 +9,16 @@ const char *tree_type = "tree";
 
 static int read_one_entry(unsigned char *sha1, const char *base, int baselen, const char *pathname, unsigned mode, int stage)
 {
-	int len = strlen(pathname);
-	unsigned int size = cache_entry_size(baselen + len);
-	struct cache_entry *ce = xmalloc(size);
+	int len;
+	unsigned int size;
+	struct cache_entry *ce;
+
+	if (S_ISDIR(mode))
+		return READ_TREE_RECURSIVE;
+
+	len = strlen(pathname);
+	size = cache_entry_size(baselen + len);
+	ce = xmalloc(size);
 
 	memset(ce, 0, size);
 
@@ -67,9 +74,10 @@ static int match_tree_entry(const char *
 	return 0;
 }
 
-static int read_tree_recursive(void *buffer, unsigned long size,
-			       const char *base, int baselen,
-			       int stage, const char **match)
+int read_tree_recursive(void *buffer, unsigned long size,
+			const char *base, int baselen,
+			int stage, const char **match,
+			read_tree_fn_t fn)
 {
 	while (size) {
 		int len = strlen(buffer)+1;
@@ -86,6 +94,14 @@ static int read_tree_recursive(void *buf
 		if (!match_tree_entry(base, baselen, path, mode, match))
 			continue;
 
+		switch (fn(sha1, base, baselen, path, mode, stage)) {
+		case 0:
+			continue;
+		case READ_TREE_RECURSIVE:
+			break;;
+		default:
+			return -1;
+		}
 		if (S_ISDIR(mode)) {
 			int retval;
 			int pathlen = strlen(path);
@@ -106,22 +122,20 @@ static int read_tree_recursive(void *buf
 			retval = read_tree_recursive(eltbuf, eltsize,
 						     newbase,
 						     baselen + pathlen + 1,
-						     stage, match);
+						     stage, match, fn);
 			free(eltbuf);
 			free(newbase);
 			if (retval)
 				return -1;
 			continue;
 		}
-		if (read_one_entry(sha1, base, baselen, path, mode, stage) < 0)
-			return -1;
 	}
 	return 0;
 }
 
 int read_tree(void *buffer, unsigned long size, int stage, const char **match)
 {
-	return read_tree_recursive(buffer, size, "", 0, stage, match);
+	return read_tree_recursive(buffer, size, "", 0, stage, match, read_one_entry);
 }
 
 struct tree *lookup_tree(const unsigned char *sha1)
tree.h +9 -0
index 9975e88..768e5e9 100644
@@ -35,4 +35,13 @@ int parse_tree(struct tree *tree);
 /* Parses and returns the tree in the given ent, chasing tags and commits. */
 struct tree *parse_tree_indirect(const unsigned char *sha1);
 
+#define READ_TREE_RECURSIVE 1
+typedef int (*read_tree_fn_t)(unsigned char *, const char *, int, const char *, unsigned int, int);
+
+extern int read_tree_recursive(void *buffer, unsigned long size,
+			const char *base, int baselen,
+			int stage, const char **match,
+			read_tree_fn_t fn);
+
+
 #endif /* TREE_H */
#41 lore raw

PATCH 7/8 Make networking commands to work from a subdirectory.

In reply to Junio C Hamano

These are whole-tree operations and there is not much point making them operable from within a subdirectory, but it is easy to do so, and using setup_git_directory() upfront helps git://
proxy specification picked up from the correct place.

---

 clone-pack.c  |    2 ++
 fetch-pack.c  |    2 ++
 http-fetch.c  |    2 ++
 http-push.c   |    1 +
 local-fetch.c |    2 ++
 send-pack.c   |    1 +
 ssh-fetch.c   |    2 ++
 ssh-upload.c  |    3 +++
 8 files changed, 15 insertions(+), 0 deletions(-)

applies-to: 40288d9fe5f400d387e29cd7ec2fa4f1ee4eecca e01beacec2b24cf1ca59bd8a0fdbe301119ab061

clone-pack.c +2 -0
index 9609219..a99a95c 100644
@@ -271,6 +271,8 @@ int main(int argc, char **argv)
 	int fd[2];
 	pid_t pid;
 
+	setup_git_directory();
+
 	nr_heads = 0;
 	heads = NULL;
 	for (i = 1; i < argc; i++) {
fetch-pack.c +2 -0
index 6565982..58ba209 100644
@@ -424,6 +424,8 @@ int main(int argc, char **argv)
 	int fd[2];
 	pid_t pid;
 
+	setup_git_directory();
+
 	nr_heads = 0;
 	heads = NULL;
 	for (i = 1; i < argc; i++) {
http-fetch.c +2 -0
index 4353173..ad59f1c 100644
@@ -922,6 +922,8 @@ int main(int argc, char **argv)
 	int arg = 1;
 	int rc = 0;
 
+	setup_git_directory();
+
 	while (arg < argc && argv[arg][0] == '-') {
 		if (argv[arg][1] == 't') {
 			get_tree = 1;
http-push.c +1 -0
index 76c7886..250a9b9 100644
@@ -1239,6 +1239,7 @@ int main(int argc, char **argv)
 	int rc = 0;
 	int i;
 
+	setup_git_directory();
 	setup_ident();
 
 	remote = xmalloc(sizeof(*remote));
local-fetch.c +2 -0
index 0931109..fa9e697 100644
@@ -207,6 +207,8 @@ int main(int argc, char **argv)
 	char *commit_id;
 	int arg = 1;
 
+	setup_git_directory();
+
 	while (arg < argc && argv[arg][0] == '-') {
 		if (argv[arg][1] == 't')
 			get_tree = 1;
send-pack.c +1 -0
index 3eeb18f..2a14b00 100644
@@ -273,6 +273,7 @@ int main(int argc, char **argv)
 	int fd[2], ret;
 	pid_t pid;
 
+	setup_git_directory();
 	argv++;
 	for (i = 1; i < argc; i++, argv++) {
 		char *arg = *argv;
ssh-fetch.c +2 -0
index bf01fbc..4eb9e04 100644
@@ -131,6 +131,8 @@ int main(int argc, char **argv)
 	prog = getenv("GIT_SSH_PUSH");
 	if (!prog) prog = "git-ssh-upload";
 
+	setup_git_directory();
+
 	while (arg < argc && argv[arg][0] == '-') {
 		if (argv[arg][1] == 't') {
 			get_tree = 1;
ssh-upload.c +3 -0
index 603abcc..b675a0b 100644
@@ -121,6 +121,9 @@ int main(int argc, char **argv)
 
 	prog = getenv(COUNTERPART_ENV_NAME);
 	if (!prog) prog = COUNTERPART_PROGRAM_NAME;
+
+	setup_git_directory();
+
 	while (arg < argc && argv[arg][0] == '-') {
 		if (argv[arg][1] == 'w')
 			arg++;

---
0.99.9.GIT

#42 lore raw

PATCH 8/8 Make the rest of commands work from a subdirectory.

In reply to Junio C Hamano

These commands are converted to run from a subdirectory.

commit-tree convert-objects merge-base merge-index mktag pack-objects pack-redundant prune-packed read-tree tar-tree unpack-file unpack-objects update-server-info write-tree

---

 commit-tree.c        |    2 ++
 convert-objects.c    |    2 ++
 merge-base.c         |    2 ++
 merge-index.c        |    1 +
 mktag.c              |    2 ++
 pack-objects.c       |    2 ++
 pack-redundant.c     |    2 ++
 prune-packed.c       |    2 ++
 read-tree.c          |    2 ++
 tar-tree.c           |    2 ++
 unpack-file.c        |    2 ++
 unpack-objects.c     |    2 ++
 update-server-info.c |    2 ++
 write-tree.c         |    5 ++++-
 14 files changed, 29 insertions(+), 1 deletions(-)

applies-to: 46e976598ab7b7822d7664fdcc88dc63d2e9cf7a 87a21588fb4f8ed433364716ccb90ef934a99585

commit-tree.c +2 -0
index b60299f..4634b50 100644
@@ -91,6 +91,8 @@ int main(int argc, char **argv)
 	if (argc < 2 || get_sha1_hex(argv[1], tree_sha1) < 0)
 		usage(commit_tree_usage);
 
+	setup_git_directory();
+
 	check_valid(tree_sha1, "tree");
 	for (i = 2; i < argc; i += 2) {
 		char *a, *b;
convert-objects.c +2 -0
index a892013..d78a8b4 100644
@@ -316,6 +316,8 @@ int main(int argc, char **argv)
 	unsigned char sha1[20];
 	struct entry *entry;
 
+	setup_git_directory();
+
 	if (argc != 2 || get_sha1(argv[1], sha1))
 		usage("git-convert-objects <sha1>");
 
merge-base.c +2 -0
index 751c3c2..e73fca7 100644
@@ -236,6 +236,8 @@ int main(int argc, char **argv)
 	struct commit *rev1, *rev2;
 	unsigned char rev1key[20], rev2key[20];
 
+	setup_git_directory();
+
 	while (1 < argc && argv[1][0] == '-') {
 		char *arg = argv[1];
 		if (!strcmp(arg, "-a") || !strcmp(arg, "--all"))
merge-index.c +1 -0
index 727527f..024196e 100644
@@ -102,6 +102,7 @@ int main(int argc, char **argv)
 	if (argc < 3)
 		usage("git-merge-index [-o] [-q] <merge-program> (-a | <filename>*)");
 
+	setup_git_directory();
 	read_cache();
 
 	i = 1;
mktag.c +2 -0
index 585677e..97e270a 100644
@@ -111,6 +111,8 @@ int main(int argc, char **argv)
 	if (argc != 1)
 		usage("cat <signaturefile> | git-mktag");
 
+	setup_git_directory();
+
 	// Read the signature
 	size = 0;
 	for (;;) {
pack-objects.c +2 -0
index 8864a31..a62c9f8 100644
@@ -473,6 +473,8 @@ int main(int argc, char **argv)
 	struct object_entry **list;
 	int i;
 
+	setup_git_directory();
+
 	for (i = 1; i < argc; i++) {
 		const char *arg = argv[i];
 
pack-redundant.c +2 -0
index 793fa08..0a43278 100644
@@ -600,6 +600,8 @@ int main(int argc, char **argv)
 	unsigned char *sha1;
 	char buf[42]; /* 40 byte sha1 + \n + \0 */
 
+	setup_git_directory();
+
 	for (i = 1; i < argc; i++) {
 		const char *arg = argv[i];
 		if(!strcmp(arg, "--")) {
prune-packed.c +2 -0
index 26123f7..d24b097 100644
@@ -58,6 +58,8 @@ int main(int argc, char **argv)
 {
 	int i;
 
+	setup_git_directory();
+
 	for (i = 1; i < argc; i++) {
 		const char *arg = argv[i];
 
read-tree.c +2 -0
index df156ea..e3b9c0d 100644
@@ -629,6 +629,8 @@ int main(int argc, char **argv)
 	unsigned char sha1[20];
 	merge_fn_t fn = NULL;
 
+	setup_git_directory();
+
 	newfd = hold_index_file_for_update(&cache_file, get_index_file());
 	if (newfd < 0)
 		die("unable to create new cachefile");
tar-tree.c +2 -0
index 970c4bb..bacb23a 100644
@@ -407,6 +407,8 @@ int main(int argc, char **argv)
 	void *buffer;
 	unsigned long size;
 
+	setup_git_directory();
+
 	switch (argc) {
 	case 3:
 		basedir = argv[2];
unpack-file.c +2 -0
index d4ac3a5..07303f8 100644
@@ -29,6 +29,8 @@ int main(int argc, char **argv)
 	if (argc != 2 || get_sha1(argv[1], sha1))
 		usage("git-unpack-file <sha1>");
 
+	setup_git_directory();
+
 	puts(create_temp_file(sha1));
 	return 0;
 }
unpack-objects.c +2 -0
index 8490895..cfd61ae 100644
@@ -269,6 +269,8 @@ int main(int argc, char **argv)
 	int i;
 	unsigned char sha1[20];
 
+	setup_git_directory();
+
 	for (i = 1 ; i < argc; i++) {
 		const char *arg = argv[i];
 
update-server-info.c +2 -0
index e824f62..0b6c383 100644
@@ -19,5 +19,7 @@ int main(int ac, char **av)
 	if (i != ac)
 		usage(update_server_info_usage);
 
+	setup_git_directory();
+
 	return !!update_server_info(force);
 }
write-tree.c +4 -1
index 2b2c6b7..0aac32f 100644
@@ -86,9 +86,12 @@ static int write_tree(struct cache_entry
 int main(int argc, char **argv)
 {
 	int i, funny;
-	int entries = read_cache();
+	int entries;
 	unsigned char sha1[20];
 	
+	setup_git_directory();
+
+	entries = read_cache();
 	if (argc == 2) {
 		if (!strcmp(argv[1], "--missing-ok"))
 			missing_ok = 1;

---
0.99.9.GIT

#43 lore raw

Re: [PATCH] Rename git-config-set to git-repo-config

In reply to Junio C Hamano

Hi,

Quoted 1 line · Junio C Hamano

- Natively, they work only from the project toplevel. Period.

How about changing *that*? Like, define a GIT_CWD_PREFIX, and checking in the C parts?

After all, the biggest problem with the scripts in a subdirectory is that they do not necessarily know which parameter means what, i.e. when to prefix it and when not.

A small helper a là git_path() should do, right?

Ciao,
Dscho

#44 lore raw

Re: [PATCH] Rename git-config-set to git-repo-config

Quoted 3 lines · Johannes Schindelin
Quoted 1 line

- Natively, they work only from the project toplevel. Period.

How about changing *that*?

I once advocated for an environment to name the top of working tree directory --- it might make sense to resurrect that one.

"natively" was a bad choice of word. What I meant by the above was that the core library part (what is in read-cache, sha1_file, etc) works on canonical path, which is defined to be project toplevel relative. I do not think changing that is wise nor necessary.

The setup_git_directory() interface is a good way to take path arguments given by the end user and convert them into canonical path form. So instead of punting when GIT_DIR is specified that we have no way knowing where the working tree top is, we could use GIT_WORKING_TREE, if exists, and use that location as the toplevel when we need to access the working tree. That implies we chdir() to that directory and do necessary prefix adjustments before returning. But I'd rather postpone that after 1.0.

#45 lore raw

Re: [PATCH] Rename git-config-set to git-repo-config

Quoted 9 lines · Junio C Hamano
Quoted 3 lines · Johannes Schindelin
Quoted 1 line

- Natively, they work only from the project toplevel. Period.

How about changing *that*?

I once advocated for an environment to name the top of working tree directory --- it might make sense to resurrect that one.

Please don't.

We should just make the scripts do it automatically instead.

"git-rev-parse" already has support for all of this, and you can do

	GIT_DIR=$(git-rev-parse --git-dir)
	GIT_PREFIX=$(git-rev-parse --show-prefix)

where the first one shows the GIT_DIR, and the second one shows where in a git directory we are (empty if we're at the root).

And most of the git commands written in C (where it makes sense) can already handle being inside a subdirectory. So can a number of the shell-scripts (for example, doing a "git log" inside a subdirectory already does the log for just that subdirectory).

In fact, I'd prefer if _every_ command just did the right thing inside a subdirectory.

I sent out this patch a week or two ago - it still applies, and it still mostly does the right thing. It makes at least "gitk" work right inside a subdirectory, and might make things like "git commit" and friends do the same.

More testing still needed, but I think this is going in the right direction.

Comments? I got none the first time around.

Linus

----

NOTE! This has some seriously far-reaching implications. One of them is that a few programs will automagically start working inside some random directories.

And probably others won't. Instead of saying "Not a git archive", they might run and do strange things.

The patch is definitely a big step in the right direction: it makes the shell scripts that include "git-sh-setup" act a lot more like the programs that automatically find the git directory. But everybody that includes git-sh-setup should be verified.

This fixes gitk to also work the same way, btw.

---

git-sh-setup.sh +1 -1
index dbb9884..044b0b4 100755
@@ -3,7 +3,7 @@
 # Set up GIT_DIR and GIT_OBJECT_DIRECTORY
 # and return true if everything looks ok
 #
-: ${GIT_DIR=.git}
+: ${GIT_DIR=$(git-rev-parse --git-dir)} || exit
 : ${GIT_OBJECT_DIRECTORY="$GIT_DIR/objects"}
 
 # Having this variable in your environment would break scripts because
gitk +1 -1
index a9d37d9..a934255 100755
@@ -12,7 +12,7 @@ proc gitdir {} {
     if {[info exists env(GIT_DIR)]} {
 	return $env(GIT_DIR)
     } else {
-	return ".git"
+	return [exec git-rev-parse --git-dir]
     }
 }
 
setup.c +13 -4
index c487d7e..96085dd 100644
@@ -53,11 +53,10 @@ const char **get_pathspec(const char *pr
 	const char **p;
 	int prefixlen;
 
-	if (!prefix && !entry)
-		return NULL;
-
 	if (!entry) {
 		static const char *spec[2];
+		if (!prefix || !*prefix)
+			return NULL;
 		spec[0] = prefix;
 		spec[1] = NULL;
 		return spec;
@@ -120,9 +119,19 @@ const char *setup_git_directory(void)
 
 	if (offset == len)
 		return NULL;
-
 	/* Make "offset" point to past the '/', and add a '/' at the end */
 	offset++;
+
+	/*
+	 * If we're inside the ".git" directory, we have an empty prefix
+	 */
+	if (!strncmp(cwd + offset, ".git", 4)) {
+		switch (cwd[offset+4]) {
+		case '\0': case '/':
+			return "";
+		}
+	}
+
 	cwd[len++] = '/';
 	cwd[len] = 0;
 	return cwd + offset;
#46 lore raw

cover Make C-level operable from subdirectories

Quoted 8 lines · Linus Torvalds
Quoted 3 lines · Junio C Hamano

I once advocated for an environment to name the top of working tree directory --- it might make sense to resurrect that one.

Please don't.

We should just make the scripts do it automatically instead.

Here comes an 8-patch series.

[PATCH 1/8] git-apply: work from subdirectory.
[PATCH 2/8] peek-remote: honor proxy config even from subdirectory. [PATCH 3/8] fsck-objects: work from subdirectory.
[PATCH 4/8] checkout-index: work from subdirectory. [PATCH 5/8] hash-object: work within subdirectory. [PATCH 6/8] ls-tree: work from subdirectory.
[PATCH 7/8] Make networking commands to work from a subdirectory. [PATCH 8/8] Make the rest of commands work from a subdirectory.

#47 lore raw

Re: [PATCH 0/8] Make C-level operable from subdirectories

Quoted 4 lines · Junio C Hamano
Quoted 2 lines · Linus Torvalds
Quoted 1 line · Junio C Hamano
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

I once advocated for an environment to name the top of working tree directory --- it might make sense to resurrect that one.

Please don't.

We should just make the scripts do it automatically instead.

Here comes an 8-patch series.

Should the documentation get an update to mention that using GIT_DIR to create a totally out-of-tree setup is supported, but not recommended?

Signature · 2 lines
Ryan Anderson
  sometimes Pug Majere
#48 lore raw

Re: [PATCH 0/8] Make C-level operable from subdirectories

In reply to Junio C Hamano
Quoted 13 lines · Junio C Hamano
Quoted 8 lines · Linus Torvalds
Quoted 3 lines · Junio C Hamano

I once advocated for an environment to name the top of working tree directory --- it might make sense to resurrect that one.

Please don't.

We should just make the scripts do it automatically instead.

Here comes an 8-patch series.

Quoted 8 lines

[PATCH 1/8] git-apply: work from subdirectory.
[PATCH 2/8] peek-remote: honor proxy config even from subdirectory. [PATCH 3/8] fsck-objects: work from subdirectory.
[PATCH 4/8] checkout-index: work from subdirectory. [PATCH 5/8] hash-object: work within subdirectory. [PATCH 6/8] ls-tree: work from subdirectory.
[PATCH 7/8] Make networking commands to work from a subdirectory. [PATCH 8/8] Make the rest of commands work from a subdirectory.

In case it was not obvious,...

I think your GIT_DIR=git-rev-parse --git-dir patch would make things work better on top of these changes, while making many of them silently do funny things as you warned.

For example, among the ones I mentioned in my previous message:

- git-checkout with or without -b to switch branches work. This is because "git-read-tree -u" is not constrained by the current directory and operates on the whole working tree.

- git-checkout <ent> <path>... works as expected. It takes cwd relative paths and updates the index and working tree for only specified paths from the named ent.

- git-checkout -f works in a confusing way; only the files under the current directory is updated. This is because "git-checkout-index -a" behaves that way. git-checkout -f to revert to the current HEAD is probably good to work this way, but doing this while switching branches is too confusing.

- git-reset --hard also works in a funny way. It leaves paths outside the current directory intact, because ls-tree reports only the files in the current directory while ls-files reports all.

- git-prune works. git-tag works as before.

It could be argued that it was a mistake that [PATCH 4/8] and [PATCH 6/8] changed checkout-index and ls-tree to limit their scope to the current directory, but that is consistent with what rev-list (log and whatchanged) and diff do, and might be debatably useful. Which suggests that things like git-checkout and git-reset whose normal mode of operation should be whole-tree should chdir up and do the path prefixing to convert original cwd relative paths to repository relative.

#49 lore raw

Re: [PATCH 6/8] ls-tree: work from subdirectory.

In reply to Linus Torvalds
Quoted 9 lines · Linus Torvalds

And this is just ugly.

git-ls-tree should be rewritten to use a pathspec the same way everybody else does. Right now it's the odd man out: if you do

git-ls-tree HEAD divers/char drivers/

it will show the same files _twice_, which is not how pathspecs in general work.

True; that is more or less deliberate. The behaviour is modelled after what "/bin/ls -a" does.

Quoted 4 lines

How about this patch? It breaks some of the git-ls-tree tests, but it makes git-ls-tree work a lot more like other git pathspec commands, and it removes more than 150 lines by re-using the recursive tree traversal (but the "-d" flag is gone for good, so I'm not pushing this too hard).

I am all for it if it were just me, and all the more so for its cleanup value. I do not think anybody uses "-d" (none of Cogito, StGIT nor gitweb seems to use it, and I have not seen Jason McMullan, who wanted to have a way in ls-tree to see just the object name of a subtree, on the list for a while); I suspect that nobody would miss that option.

However, this patch changes its behaviour in another way, and that could impact Porcelains more than the removal of the "-d" option. Currently, "git-ls-tree <tree> $dir" shows what "/bin/ls -a -1 $dir" would show --- the tree for $dir itself and its immediate children. This patch changes it to show the tree for $dir and nothing else. In effect, "-d" becomes the default that you cannot turn off, except using "-r" to allow it go all the way down.

I do not think StGIT is affected; it does not use ls-tree at all. gitweb is not affected either. It does not use paths specifier.

Cogito might need a slight adjustment.

- cg-admin-cat may want to use -r for the first one (${ARGS[@]} may name a directory), but that also would change the behaviour. The current one shows only one level, instead of going all the way down.

- cg-log:117 uses ls-tree without -r, but I have a feeling that it might be just a bug, even with the current ls-tree; I suspect the user would not see things in subdirectories. This is only for the initial commit so it may or may not matter much.

- cg-restore already uses ls-tree -r so that would not be affected.

#50 lore raw

Re: [PATCH 6/8] ls-tree: work from subdirectory.

Dear diary, on Sun, Nov 27, 2005 at 10:21:53AM CET, I got a letter where Junio C Hamano <[email protected]> said that...

Quoted 4 lines

- cg-admin-cat may want to use -r for the first one (${ARGS[@]} may name a directory), but that also would change the behaviour. The current one shows only one level, instead of going all the way down.

I think the current behaviour is nonsensical, since it cats all the files in the subdirectory, instead of just listing it. Didn't git-ls-tree already have the -d implicit sometime in the past? At any rate, the change to git-ls-tree would fix this. :-)

Quoted 5 lines

- cg-log:117 uses ls-tree without -r, but I have a feeling that it might be just a bug, even with the current ls-tree; I suspect the user would not see things in subdirectories. This is only for the initial commit so it may or may not matter much.

Thanks, fixed. It uses -r now.

Signature · 4 lines
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
VI has two modes: the one in which it beeps and the one in which
it doesn't.
#51 lore raw

Re: [PATCH 6/8] ls-tree: work from subdirectory.

In reply to Junio C Hamano
Quoted 3 lines · Junio C Hamano

True; that is more or less deliberate. The behaviour is modelled after what "/bin/ls -a" does.

Yes, I did realize, and maybe it's fine. It's just that right now, git-ls-tree doesn't work like git-ls-files, which is kind of sad.

I suspect not a lot of people use git-ls-tree, and that's probably why it never was updated to match anything else.

It would be nice (I think) if git-ls-tree matched git-ls-files the same way git-diff-tree matches git-diff-files: exact same behaviour, except one works on a tree and another on the index. And like the git-diff-*, the index would always default to "-r", while for the tree version you would have to specify it.

(Yeah, there are differences. git-ls-files has the "--others" etc logic, but I think there are more similarities than differences).

Quoted 8 lines

However, this patch changes its behaviour in another way, and that could impact Porcelains more than the removal of the "-d" option. Currently, "git-ls-tree <tree> $dir" shows what "/bin/ls -a -1 $dir" would show --- the tree for $dir itself and its immediate children. This patch changes it to show the tree for $dir and nothing else. In effect, "-d" becomes the default that you cannot turn off, except using "-r" to allow it go all the way down.

No, actually, it's even stranger than that.

If you use "-r", it acts the way you'd expect. If you _don't_ use "-r", it acts strangely, but very consistently with git-diff-tree: it only ever shows the _first_ part of a pathname. So

git-ls-tree HEAD drivers/char/

should show just one entry: "drivers". While adding a "-r" should show all files under drivers (and the trees leading up to it).

And yes, you're right. That's a much bigger change by my suggested diff, and more likely to cause confusion.

Linus

#52 lore raw

Re: [PATCH 6/8] ls-tree: work from subdirectory.

Dear diary, on Sun, Nov 27, 2005 at 07:01:37PM CET, I got a letter where Linus Torvalds <[email protected]> said that...

Quoted 11 lines

If you use "-r", it acts the way you'd expect. If you _don't_ use "-r", it acts strangely, but very consistently with git-diff-tree: it only ever shows the _first_ part of a pathname. So

git-ls-tree HEAD drivers/char/

should show just one entry: "drivers". While adding a "-r" should show all files under drivers (and the trees leading up to it).

And yes, you're right. That's a much bigger change by my suggested diff, and more likely to cause confusion.

Ugh. That's really weird. Wouldn't a better approach be to fix git-ls-files to behave more sanely? (That is, listing the entry for drivers/char instead of drivers?)

Signature · 4 lines
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
VI has two modes: the one in which it beeps and the one in which
it doesn't.
#53 lore raw

Re: [PATCH 6/8] ls-tree: work from subdirectory.

Quoted 11 lines · Petr Baudis

Dear diary, on Sun, Nov 27, 2005 at 07:01:37PM CET, I got a letter where Linus Torvalds <[email protected]> said that...

Quoted 9 lines

If you use "-r", it acts the way you'd expect. If you _don't_ use "-r", it acts strangely, but very consistently with git-diff-tree: it only ever shows the _first_ part of a pathname. So

git-ls-tree HEAD drivers/char/

should show just one entry: "drivers". While adding a "-r" should show all files under drivers (and the trees leading up to it).

Quoted 6 lines
Quoted 2 lines

And yes, you're right. That's a much bigger change by my suggested diff, and more likely to cause confusion.

Ugh. That's really weird. Wouldn't a better approach be to fix git-ls-files to behave more sanely? (That is, listing the entry for drivers/char instead of drivers?)

Well, it's not actually confusing if you see a path spec for what it is:
it's not a filename, it's a _pattern_.

So you should always do

git-ls-tree -r pattern

(and yes, we could even hardcode "-r", because git-ls-tree without it really is a pretty strange thing).

The _real_ strangeness in "git-ls-tree" is that it shows the tree nodes at all, which no other git tool does when it recurses.

To get more a "git-ls-files" approach, this trivial patch (on top of my previous one) enables recursion (and right now you can't disable it any way), and doesn't show partial trees.

I could make it work much more like git-ls-files, in that it could accept wildcards. Something like

	git-ls-tree HEAD '*.c'

would show all C files (recursively), the same way git-ls-files does for the index.

Hmm?

Linus

----

ls-tree.c +4 -5
index 598b729..cf0dbbc 100644
@@ -11,7 +11,7 @@
 static int line_termination = '\n';
 #define LS_RECURSIVE 1
 #define LS_TREE_ONLY 2
-static int ls_options = 0;
+static int ls_options = LS_RECURSIVE;
 
 static const char ls_tree_usage[] =
 	"git-ls-tree [-d] [-r] [-z] <tree-ish> [path...]";
@@ -19,16 +19,15 @@ static const char ls_tree_usage[] =
 static int show_tree(unsigned char *sha1, const char *base, int baselen, const char *pathname, unsigned mode, int stage)
 {
 	const char *type = "blob";
-	int retval = 0;
 
 	if (S_ISDIR(mode)) {
-		type = "tree";
 		if (ls_options & LS_RECURSIVE)
-			retval = READ_TREE_RECURSIVE;
+			return READ_TREE_RECURSIVE;
+		type = "tree";
 	}
 
 	printf("%06o %s %s\t%.*s%s%c", mode, type, sha1_to_hex(sha1), baselen, base, pathname, line_termination);
-	return retval;
+	return 0;
 }
 
 int main(int argc, const char **argv)
#54 lore raw

Re: [PATCH 6/8] ls-tree: work from subdirectory.

Quoted 4 lines · Linus Torvalds
Quoted 3 lines · Petr Baudis

Ugh. That's really weird. Wouldn't a better approach be to fix git-ls-files to behave more sanely? (That is, listing the entry for drivers/char instead of drivers?)

It behaves sanely, just not in the way you are expecting.

Quoted 2 lines

Well, it's not actually confusing if you see a path spec for what it is: it's not a filename, it's a _pattern_.

Well, that is confusing, although it may be sane.

Quoted 6 lines

So you should always do

git-ls-tree -r pattern

(and yes, we could even hardcode "-r", because git-ls-tree without it really is a pretty strange thing).

If you mean "in the presense of pathspec, default to -r", I *might* agree, but I am not convinced yet.

Without pathspec, ls-tree is a pretty-printing version of "git-cat-file tree", and that is how the command is used by the git browsers like gitweb. I have never looked at qgit source, but I'd be surprised if it did not depend on the single-level behaviour of ls-tree for that purpose.

It *is* "/bin/ls" after all, and you _would_ get annoyed if your /bin/ls always recursed if you gave an argument. Imagine going to the kernel source and try "/bin/ls arch" with your version of /bin/ls that always recurses, when you only wanted to get the list of architectures you are supporting ;-).

Quoted 2 lines

The _real_ strangeness in "git-ls-tree" is that it shows the tree nodes at all, which no other git tool does when it recurses.

Very true. I do not think even git browsers need that but I may be mistaken.

Having said all of the above, I do understand why we would _also_ want the behaviour parallel to ls-files, not /bin/ls behaviour. Maybe we should have both? Either rename the current ls-tree to browse-tree, and make the one that parallels ls-files the new ls-tree?

#55 lore raw

Re: [PATCH 6/8] ls-tree: work from subdirectory.

Quoted 6 lines · Junio C Hamano

Without pathspec, ls-tree is a pretty-printing version of "git-cat-file tree", and that is how the command is used by the git browsers like gitweb. I have never looked at qgit source, but I'd be surprised if it did not depend on the single-level behaviour of ls-tree for that purpose.

You're right, we need to keep the "-r" behaviour.

Quoted 5 lines

Having said all of the above, I do understand why we would _also_ want the behaviour parallel to ls-files, not /bin/ls behaviour. Maybe we should have both? Either rename the current ls-tree to browse-tree, and make the one that parallels ls-files the new ls-tree?

If you take my last patch and make "ls_flags" default to 0 again, it should work correctly.

The way to traverse into directories (a la qgit/webgit) is to just give the SHA1 name of the directory. Ie

git-ls-tree HEAD

gives us a single level, we see:

	...
	040000 tree b2d1264f85148d18c5ae9864d73d65737b0a1734    t
	...

and then we can just do

	git-ls-tree b2d1264f85148d18c5ae9864d73d65737b0a1734

to get that level. I assume that that is what qgit/webgit already does (I sure hope so, otherwise they're just wasting time, making the tools re-parse the trees over and over again for no gain).

Linus

#56 lore raw

Re: [PATCH 6/8] ls-tree: work from subdirectory.

Quoted 3 lines · Linus Torvalds

You're right, we need to keep the "-r" behaviour.
If you take my last patch and make "ls_flags" default to 0 again, it should work correctly.

Maybe making "-r" the default and resurrecting "-d" to turn it off would be the approach of least impact (-r becomes a noiseword), if we take this "ls-tree should parallel ls-files" idea.

The merge-recursive strategy uses ls-tree without -r with path specifier to grab the sha1/mode of the three trees involved. git-cvsexportcommit has the same assumption on how ls-tree works. It extracts a single SHA1 for the blob from the commit object by "ls-tree $commit $blob_path".

With your two patches, they need to do this with "-r".

git-checkout and git-reset use -r to grab the whole tree, so they are fine either way. git-svnimport uses -r to read from a tree (potentially a subtree) all the way down, so this one is also fine.

So it probably is safer to default ls_options to LS_RECURSIVE, and use "-d" to restrict it not to recurse.

But after seeing some more examples, I tend to think the current one that models after how "/bin/ls -a" works in a way that is a lot easier to understand. For example, with your two patches (defaulting to recursive)

git-ls-tree HEAD

shows everything from the tree. In order to get prettyprint of HEAD tree (i.e. single level listing):

git-ls-tree -d HEAD

is needed. But there is no way to get the single level with pathspec with these patches, so:

	cd Documentation && git-ls-tree -d HEAD

would not show the single level of Documentation tree, but just a single line "tree" object of Documentation tree. Which means the way it works from the top and the way it works in a subdirectory is quite different.

I'll throw in your two patches to the proposed updates branch so that Porcelain/Browser people can play with it and decide. I really love the decrease of number of lines of code, but I am afraid this would end up breaking things without real merit.

#57 lore raw

Re: [PATCH 6/8] ls-tree: work from subdirectory.

Quoted 3 lines · Junio C Hamano

So it probably is safer to default ls_options to LS_RECURSIVE, and use "-d" to restrict it not to recurse.

I have a patch that solves all the problems, I think.

It modifies the selection a bit, so that a pathspec that is a superset of a particular tree path will always cause it to recurse into that tree.

As an example, let's say that we do

git-ls-tree HEAD drivers/char

_without_ the "-r". What will happen is that it will start out doing all the base tree, and for "drivers" it will notice that it's a proper subset of "drivers/char", so it will always recurse into _that_ tree (but not into other trees).

Then, it will not match anything else than "char" in that subdirectory, and because that's not a proper superset (it's an exact match), it will _not_ recurse into it, so you get:

	[torvalds@g5 linux]$ ~/git/git-ls-tree HEAD drivers/char
	040000 tree 9568cda453aae205bb58983747fa73b9696d9d51    drivers/char

which is what you got with the old git-ls-tree too.

But interestingly, if you add the slash, it will become a proper superset and it will recurse into _that_ subdirectory (but no deeper: so if you want all subdirectories _below_ drivers/char/, you still need to give "-r"):

	[torvalds@g5 linux]$ ~/git/git-ls-tree HEAD drivers/char/
	100644 blob 2b6b1d772ed776fff87927fc34adc2e40500218e    drivers/char/.gitignore
	100644 blob 56b8a2e76ab10a5c21787cb7068a846075cbaffd    drivers/char/ChangeLog
	100644 blob 970f70d498f4c814e1cf3362e33d7e23ac53c299    drivers/char/Kconfig
	...

See? This is on top of the previous two diffs, holler if you want a whole new "everything combined" version..

It hasn't gotten lots of testing, but it should work.

BTW! It fails a few of the tests, but it does so because now, with "-r", it will never show the tree entries, and because of the difference between

git-ls-tree $tree path

and

git-ls-tree $tree path/

that it didn't use to have (oh, and if you give multiple paths, it will now always consider them a "union pathspec", not an "iteration of paths"). But I _think_ the new behaviour is pretty useful and while not the same as "ls", it's perhaps still intuitive enough..

Linus

---

ls-tree.c +26 -4
index cf0dbbc..4df5830 100644
@@ -11,7 +11,8 @@
 static int line_termination = '\n';
 #define LS_RECURSIVE 1
 #define LS_TREE_ONLY 2
-static int ls_options = LS_RECURSIVE;
+static int ls_options = 0;
+const char **pathspec;
 
 static const char ls_tree_usage[] =
 	"git-ls-tree [-d] [-r] [-z] <tree-ish> [path...]";
@@ -21,8 +22,29 @@ static int show_tree(unsigned char *sha1
 	const char *type = "blob";
 
 	if (S_ISDIR(mode)) {
+		const char **s;
 		if (ls_options & LS_RECURSIVE)
 			return READ_TREE_RECURSIVE;
+		s = pathspec;
+		if (s) {
+			for (;;) {
+				const char *spec = *s++;
+				int len, speclen;
+
+				if (!spec)
+					break;
+				if (strncmp(base, spec, baselen))
+					continue;
+				len = strlen(pathname);
+				spec += baselen;
+				speclen = strlen(spec);
+				if (speclen <= len)
+					continue;
+				if (memcmp(pathname, spec, len))
+					continue;
+				return READ_TREE_RECURSIVE;
+			}
+		}
 		type = "tree";
 	}
 
@@ -32,7 +54,7 @@ static int show_tree(unsigned char *sha1
 
 int main(int argc, const char **argv)
 {
-	const char **path, *prefix;
+	const char *prefix;
 	unsigned char sha1[20];
 	char *buf;
 	unsigned long size;
@@ -60,11 +82,11 @@ int main(int argc, const char **argv)
 	if (get_sha1(argv[1], sha1) < 0)
 		usage(ls_tree_usage);
 
-	path = get_pathspec(prefix, argv + 2);
+	pathspec = get_pathspec(prefix, argv + 2);
 	buf = read_object_with_reference(sha1, "tree", &size, NULL);
 	if (!buf)
 		die("not a tree object");
-	read_tree_recursive(buf, size, "", 0, 0, path, show_tree);
+	read_tree_recursive(buf, size, "", 0, 0, pathspec, show_tree);
 
 	return 0;
 }
#58 lore raw

Re: [PATCH 6/8] ls-tree: work from subdirectory.

Quoted 5 lines · Linus Torvalds

BTW! It fails a few of the tests, but it does so because now, with "-r", it will never show the tree entries, and because of the difference between

git-ls-tree $tree path

Quoted 8 lines

and

git-ls-tree $tree path/

that it didn't use to have (oh, and if you give multiple paths, it will now always consider them a "union pathspec", not an "iteration of paths"). But I _think_ the new behaviour is pretty useful and while not the same as "ls", it's perhaps still intuitive enough..

The difference between path and path/ is very cute ;-). I do not do Porcelain myself, so I am OK with this change, but this would involve some changes to the Porcelain.

So let's cook this for a while and have Porcelain people holler if they find something lacking. I'll put this in the proposed updates tonight, and we will plan to push everything in the proposed updates branch to the master branch on Wednesday, with any fixes and updates necessary.

#59 lore raw

Re: [PATCH 6/8] ls-tree: work from subdirectory.

Quoted 5 lines · Junio C Hamano

So let's cook this for a while and have Porcelain people holler if they find something lacking. I'll put this in the proposed updates tonight, and we will plan to push everything in the proposed updates branch to the master branch on Wednesday, with any fixes and updates necessary.

OK, so I did some tests adjustments (they are in "pu"). Most differences are easily explained but some are not.

Easy ones:

- With -r, tree entries are not shown.

- Unlike /bin/ls arguments, the paths are now filters, so no duplicates on the output, nor the output order does not depend on command line argument order.

- "path" shows the tree if path corresponds to a directory; say "path/" to get its contents.

However I do not have an easy way to explain how these two work the way they do. Taken from t/t3101 test.

The first one has both path0/a/b/c and path0/a in the filter, and path0/a tree entry itself is not shown because it "recurses through it".

+# I am not so sure about this one after ls-tree doing pathspec match. +# Having both path0/a and path0/a/b/c makes path0/a redundant, and +# it behaves as if path0/a/b/c, path1/b/c, path2 and path3 are specified.

 test_expect_success \
     'ls-tree filter directories' \
     'git-ls-tree $tree path3 path2 path0/a/b/c path1/b/c path0/a >current &&
      cat >expected <<\EOF &&

-040000 tree X path3
-100644 blob X path3/1.txt
-100644 blob X path3/2.txt
-040000 tree X path2
-100644 blob X path2/1.txt
040000 tree X path0/a/b/c
-100644 blob X path0/a/b/c/1.txt
040000 tree X path1/b/c
-100644 blob X path1/b/c/1.txt
-040000 tree X path0/a
-040000 tree X path0/a/b
+040000 tree X path2
+040000 tree X path3
EOF
test_output'

The second one is the same; since there is path3/, it recurses through it and path3 itself is not shown but its contents are. It is showing both path3/1.txt and path3/2.txt not because path3/1.txt is specified but path3/ was specified.

+# Again, duplicates are filtered away so this is equivalent to +# having 1.txt and path3/

 test_expect_success \
     'ls-tree filter odd names' \
     'git-ls-tree $tree 1.txt /1.txt //1.txt path3/1.txt /path3/1.txt //path3//1.txt path3 /path3/ path3// >current &&
      cat >expected <<\EOF &&

100644 blob X 1.txt
-100644 blob X 1.txt
-100644 blob X 1.txt
-100644 blob X path3/1.txt
-100644 blob X path3/1.txt
-100644 blob X path3/1.txt
-040000 tree X path3
-100644 blob X path3/1.txt
-100644 blob X path3/2.txt
-040000 tree X path3
-100644 blob X path3/1.txt
-100644 blob X path3/2.txt
-040000 tree X path3
100644 blob X path3/1.txt
100644 blob X path3/2.txt
EOF

#60 lore raw

PATCH 1/1 ls-tree: Resurrect funny name quoting lost during rewrite.

In reply to Linus Torvalds

The rewrite to match ls-files/diff-tree behaviour accidentally lost the name quoting. I am not proud about this code, but this would get the test going.

---

 ls-tree.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)

applies-to: 4db95789ce3af40091ead2a97a72e75f9a0b8384 e7cdcbbbbd2fd2848244f998a0b92338fc68fe78

ls-tree.c +9 -1
index 4df5830..df3bcec 100644
@@ -48,7 +48,15 @@ static int show_tree(unsigned char *sha1
 		type = "tree";
 	}
 
-	printf("%06o %s %s\t%.*s%s%c", mode, type, sha1_to_hex(sha1), baselen, base, pathname, line_termination);
+	printf("%06o %s %s\t", mode, type, sha1_to_hex(sha1));
+	if (1) {
+		/* NEEDSWORK: */
+		char base_[baselen + 1];
+		memcpy(base_, base, baselen);
+		base_[baselen] = 0;
+		write_name_quoted(base_, pathname, line_termination, stdout);
+	}
+	putchar(line_termination);
 	return 0;
 }
 

---
0.99.9.GIT

#61 lore raw

Re: [PATCH] Rename git-config-set to git-repo-config

In reply to Linus Torvalds
Quoted 3 lines · Linus Torvalds

In fact, I'd prefer if _every_ command just did the right thing inside a subdirectory.

Side note: the thing I like best about the patch I just sent out is that it also makes things automagically work when you're inside the ".git" directory. So you should be able to do a "git log" inside a "raw" archive without setting GIT_DIR=. explicitly.

Linus

#62 lore raw
In reply to Josef Weidendorfer

Hi,

Quoted 10 lines · Josef Weidendorfer
Quoted 3 lines · Linus Torvalds

[branches.origin]
url = master.kernel.org:/pub/scm/git/git.git pull = master:origin

Two things:
* base names are case insensitive. Repository shortcuts are case sensitive (and head names, too)
* to get rid of .git/branches/XXX, XXX has to be allowed as base name. But XXX can contain anything a head name can (including ".").

Is it that important that nicks can be case sensitive or contain spaces or dots? I.e. is it sensible to make a difference between

git pull Weidendorfer

and

git pull weidendorfer
???

Also, I'd rather write

git pull josef

than

git pull "Josef Weidendorfer, III"

Quoted 7 lines

Not really a problem. Use the ' for ' syntax:

[remotes]
url = master.kernel.org:/pub/scm/git/git.git for origin pull = master:origin for origin

Not really nice. We can not have "for" as head name.

Not really nice. Looks ugly. Violates DRY. ("for blabla" would not need to be a problem; just enforce quotes around the name.)

Ciao,
Dscho