Skip to contentSkip to conversation

git-shortlog hangs on bare repo without --bare option

DISCUSSION Garry Dolley 5 participants 12 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

I didn't see this happen with git 1.5.x, but if you do git-shortlog on a bare repo, without specifying --bare, the command will seemingly hang indefinitely.

Here's my output:

[garry@garry-thinkpad] ~/dev (master) $ cd ebay4r/ <----- Repo with working tree (non-bare)
[garry@garry-thinkpad] ~/dev/ebay4r (master) $ git shortlog -e -s
130 Garry Dolley <[email protected]>
[garry@garry-thinkpad] ~/dev/ebay4r (master) $ cd .. [garry@garry-thinkpad] ~/dev (master) $ git clone --mirror ebay4r/ ebay4r-bare Initialized empty Git repository in /home/garry/dev/ebay4r-bare/ [garry@garry-thinkpad] ~/dev (master) $ cd ebay4r-bare/ [garry@garry-thinkpad] ~/dev/ebay4r-bare (master) $ git shortlog -e -s
<hang> <----- *** It hangs here ***

[garry@garry-thinkpad] ~/dev/ebay4r-bare (master) $ git --bare shortlog -e -s
130 Garry Dolley <[email protected]>
[garry@garry-thinkpad] ~/dev/ebay4r-bare (master) $

If newlines break this output in your reader, you can also view it
here: http://pastie.org/261134

I'm using git 1.6.0.1

Is this a bug?

Signature · 5 lines
Garry Dolley
ARP Networks, Inc.
818-206-0181
Los Angeles County REACT, Unit 336
WQGK336
#1 lore raw
Quoted 2 lines · Garry Dolley

I didn't see this happen with git 1.5.x, but if you do git-shortlog on a bare repo, without specifying --bare, the command will seemingly hang indefinitely.

FWIW, I tried git 1.5.0 and it hangs, too. Which exact version did work for you? Could you, based on it, bisect the commit that introduced this behaviour?

As a workaround, you can use "git log | git shortlog".

René

#2 lore raw
Quoted 7 lines · Ren?? Scharfe
Quoted 2 lines · Garry Dolley

I didn't see this happen with git 1.5.x, but if you do git-shortlog on a bare repo, without specifying --bare, the command will seemingly hang indefinitely.

FWIW, I tried git 1.5.0 and it hangs, too. Which exact version did work for you? Could you, based on it, bisect the commit that introduced this behaviour?

I just tried it with 1.5.6.2, and it hung. Unfortunately, I had several versions of git inside my ~/src as I upgraded over the months, and just last week I decided to blow away the old ones, so I don't know what version it was that I saw this work. :(

Either way, it's too big a deal, I just wanted to point out what I saw.

If it helps, this is the last few lines of strace before it hangs:

stat(".git", 0x7fff6e44dd90)            = -1 ENOENT (No such file or directory)
open(".git/config", O_RDONLY)           = -1 ENOENT (No such file or directory)
pipe([3, 4])                            = 0
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f7a6642d790) = 12674
dup2(3, 0)                              = 0
close(3)                                = 0
close(4)                                = 0

select(1, [0], NULL, [0], NULL

So looks like it is waiting to be fed some input? It's hungry :)

Quoted 1 line

As a workaround, you can use "git log | git shortlog".

Also, 'git --bare shortlog' works too.

Signature · 6 lines
Garry Dolley
http://scie.nti.st
ARP Networks, Inc.
818-206-0181
Los Angeles County REACT, Unit 336
WQGK336
#3 lore raw
In reply to René Scharfe
Quoted 9 lines · René Scharfe
Quoted 2 lines · Garry Dolley

I didn't see this happen with git 1.5.x, but if you do git-shortlog on a bare repo, without specifying --bare, the command will seemingly hang indefinitely.

FWIW, I tried git 1.5.0 and it hangs, too. Which exact version did work for you? Could you, based on it, bisect the commit that introduced this behaviour?

As a workaround, you can use "git log | git shortlog".

It is not a workaround. Shortlog can work as a filter to "git log", but if you give revs to work on, e.g. "git shortlog -s -n v1.5.6.5.." or "git shortlog HEAD", it can generate the log and feed to itself.

Somehow it (perhaps incorrectly, I did not look at the command line input) judging that your command line is telling it not to do the log generation itself but instead you will feed the log from its standard input, which happens to be your terminal. So another workaround would be to type the series of log messages ;-)

#4 lore raw
Quoted 16 lines · Junio C Hamano
Quoted 9 lines · René Scharfe
Quoted 2 lines · Garry Dolley

I didn't see this happen with git 1.5.x, but if you do git-shortlog on a bare repo, without specifying --bare, the command will seemingly hang indefinitely.

FWIW, I tried git 1.5.0 and it hangs, too. Which exact version did work for you? Could you, based on it, bisect the commit that introduced this behaviour?

As a workaround, you can use "git log | git shortlog".

It is not a workaround. Shortlog can work as a filter to "git log", but if you give revs to work on, e.g. "git shortlog -s -n v1.5.6.5.." or "git shortlog HEAD", it can generate the log and feed to itself.

Quoted 5 lines

Somehow it (perhaps incorrectly, I did not look at the command line input) judging that your command line is telling it not to do the log generation itself but instead you will feed the log from its standard input, which happens to be your terminal. So another workaround would be to type the series of log messages ;-)

And I think this is related to the complexity that snuck in when worktree feature was added to the setup sequence.

Untested, but I think this would help.

 setup.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
setup.c +1 -1
index 6cf9094..296f712 100644
@@ -461,7 +461,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
 			inside_git_dir = 1;
 			if (!work_tree_env)
 				inside_work_tree = 0;
-			setenv(GIT_DIR_ENVIRONMENT, ".", 1);
+			set_git_dir(".");
 			check_repository_format_gently(nongit_ok);
 			return NULL;
 		}
#5 lore raw
Quoted 4 lines · Junio C Hamano

And I think this is related to the complexity that snuck in when worktree feature was added to the setup sequence.

Untested, but I think this would help.

While this might help, I see there are more serious issues here.

If you start "git-shortlog" (or anything that has USE_PAGER but not RUN_SETUP in git.c) inside your project/.git directory (or a bare one, for that matter), the call sequence would become like this:

git.c::main()
-> handle_internal_command()
-> run_command()

     -> commit_pager_choice()
       -> setup_pager() (this is in pager.c)
         -> git_config(git_default_config, NULL)
           -> git_path("config")
             -> get_git_dir()
               -> setup_git_env()
                 This sets git_dir to ".git"!!!!

And that was part of the reason why "git-shortlog" started from a bare repository did not even notice that the default "HEAD" that is given internally by the program is not a valid ref (because it tries to read from .git/HEAD without the patch I sent earlier). Oh, of course that git_config() won't read from the right config file either.

This may be repeating what Jeff said earlier in another thread, but I think we should rethink the start-up sequence carefully. Ideally (I am thinking aloud)...

* Have a single function "git_setup()" that notices --bare and --git-dir from the command line and GIT_DIR environment, and does the discovery of git_dir (if not told with the command line or environment explicitly); if we do not find it, do *NOT* barf. Just record the facts it finds somewhere (e.g. the location of git_dir, absense of git_dir, if the repository is explicitly bare, etc.).

* As the next step, still in this single function, if we have git_dir, find out where the work_tree is, paying attention to --work-tree from the command line and GIT_WORK_TREE environment if exists. If we do not have work tree, do *NOT* barf. Again, just record the facts it finds. If we do not have --work-tree from the command line and if we are not told that it is --bare from the command line, then we may need to open the config to see where core.worktree points at.

* Before returning from that single setup function, i think it is Ok to make it mimick the current git_setup_directory_gently(), cd up to the normal work-tree top if needed, and make it return prefix.

* After all of the above is done, then we can start futzing with other things such as pager. At that point we know we can read from the correct configuratoin.

* Each individual command may decide to refuse to work in the absense of git_dir and/or work_tree, by calling require_work_tree(), etc.

Hmm?

#6 lore raw
Quoted 16 lines · Junio C Hamano

While this might help, I see there are more serious issues here.

If you start "git-shortlog" (or anything that has USE_PAGER but not RUN_SETUP in git.c) inside your project/.git directory (or a bare one, for that matter), the call sequence would become like this:

git.c::main()
-> handle_internal_command()
-> run_command()

     -> commit_pager_choice()
       -> setup_pager() (this is in pager.c)
         -> git_config(git_default_config, NULL)
           -> git_path("config")
             -> get_git_dir()
               -> setup_git_env()
                 This sets git_dir to ".git"!!!!
Quoted 4 lines

[...]
This may be repeating what Jeff said earlier in another thread, but I think we should rethink the start-up sequence carefully. Ideally (I am thinking aloud)...

Yep. This is the exact same problem I have been complaining about for a while.

Quoted 1 line

[some implementation ideas]

Yes, this is roughly what I have been thinking of, as well. IOW, unconditionally find everything right at the beginning, but let us decide whether to barf later, when we know what command we are running.

A few complexities I found were:

- some things really want no setup, like init and clone. I don't recall the exact issues, but trying obvious things caused breakage there.

- the setup needs to not just be part of git.c, but factored out so non-builtin C programs can use it. I don't recall if there are issues related to git-sh-setup that need to be dealt with.

I think my approach was something like "let's just unconditionally call setup_git_directory() in git.c, and wrap it with a static variable to make sure we don't run it twice." but I ran into a host of issues. Sorry I can't remember specifics.

-Peff

#7 lore raw
Quoted 5 lines · Jeff King

A few complexities I found were:

- some things really want no setup, like init and clone. I don't recall the exact issues, but trying obvious things caused breakage there.

An obvious thing is to start these commands in a subdirectory of an existing git worktree.

Quoted 2 lines

- the setup needs to not just be part of git.c, but factored out so non-builtin C programs can use it.

Obviously.

#9 lore raw
In reply to Junio C Hamano
Quoted 4 lines · Junio C Hamano

And I think this is related to the complexity that snuck in when worktree feature was added to the setup sequence.

Untested, but I think this would help.

While it might help, I see there are more serious issue here.

If you start "git-shortlog" (or anything that has USE_PAGER but not RUN_SETUP in git.c) inside your project/.git directory (or a bare one, for that matter), the call sequence would become like this:

git.c::main()
-> handle_internal_command()
-> run_command()

     -> commit_pager_choice()
       -> setup_pager() (this is in pager.c)
         -> git_config(git_default_config, NULL)
           -> git_path("config")
             -> get_git_dir()
               -> setup_git_env()
                 This sets git_dir to ".git"!!!!

And that was part of the reason why "git-shortlog" started from a bare repository did not even notice that the default "HEAD" that is given internally by the program is not a valid ref (because it tries to read from .git/HEAD without the patch I sent earlier).

This may be repeating what Jeff said earlier in another thread, but I think we should rethink the start-up sequence carefully. Ideally (I am thinking aloud)...

* Have a single function "git_setup()" that notices --bare and --git-dir from the command line and GIT_DIR environment, and does the discovery of git_dir (if not told with the command line or environment explicitly); if we do not find it, do *NOT* barf. Just record the facts it finds somewhere (e.g. the location of git_dir, absense of git_dir, if the repository is explicitly bare, etc.).

* As the next step, still in this single function, if we have git_dir, find out where the work_tree is, paying attention to --work-tree from the command line and GIT_WORK_TREE environment if exists. If we do not have work tree, do *NOT* barf. Again, just record the facts it finds. If we do not have --work-tree from the command line and if we are not told that it is --bare from the command line, then we may need to open the config to see where core.worktree points at.

* Before returning from that single setup function, i think it is Ok to make it mimick the current git_setup_directory_gently(), cd up to the normal work-tree top if needed, and make it return prefix.

* After all of the above is done, then we can start futzing with other things such as pager. At that point we know we can read from the correct configuratoin.

* Each individual command may decide to refuse to work in the absense of git_dir and/or work_tree, by calling require_work_tree(), etc.

Hmm?

#10 lore raw
In reply to Garry Dolley
Quoted 2 lines · Garry Dolley

[garry@garry-thinkpad] ~/dev/ebay4r-bare (master) $ git shortlog -e -s
<hang> <----- *** It hangs here ***

Tryp typing ^D here. I think it is operating in the filter mode.

#11 lore raw
Quoted 6 lines · Junio C Hamano
Quoted 2 lines · Garry Dolley

[garry@garry-thinkpad] ~/dev/ebay4r-bare (master) $ git shortlog -e -s
<hang> <----- *** It hangs here ***

Tryp typing ^D here. I think it is operating in the filter mode.

Yeah, ^D just gets me back to the prompt, no output. It does indeed seem to be waiting for something.

Signature · 2 lines
Garry Dolley
http://scie.nti.st
#8 lore raw
In reply to Junio C Hamano
Quoted 11 lines · Junio C Hamano

This may be repeating what Jeff said earlier in another thread, but I think we should rethink the start-up sequence carefully. Ideally (I am thinking aloud)...

* Have a single function "git_setup()" that notices --bare and --git-dir from the command line and GIT_DIR environment, and does the discovery of git_dir (if not told with the command line or environment explicitly); if we do not find it, do *NOT* barf. Just record the facts it finds somewhere (e.g. the location of git_dir, absense of git_dir, if the repository is explicitly bare, etc.).

Quoted 7 lines

* As the next step, still in this single function, if we have git_dir, find out where the work_tree is, paying attention to --work-tree from the command line and GIT_WORK_TREE environment if exists. If we do not have work tree, do *NOT* barf. Again, just record the facts it finds. If we do not have --work-tree from the command line and if we are not told that it is --bare from the command line, then we may need to open the config to see where core.worktree points at.

Part of worktree issues comes from the fact that worktree setup is spread over many functions, starting at setup_git_dir*() and ending at setup_work_tree().
So setting it up in a single function and turning setup_work_tree() into "check and die()" logic sounds great.

Signature · 1 line
Duy