# [RFC/PATCH] lockfile: show absolute filename in unable_to_lock_message.

5 messages from 2010-01-06 to 2010-01-13. Participants: Matthieu Moy, Johannes Sixt, Junio C Hamano.
Thread: https://gitlist.dev/t/22105

## Matthieu Moy, 2010-01-06 17:01

Subject: [RFC/PATCH] lockfile: show absolute filename in unable_to_lock_message.
Message-ID: <1262797288-23004-1-git-send-email-Matthieu.Moy@imag.fr>
URL: https://gitlist.dev/e/1262797288-23004-1-git-send-email-Matthieu.Moy%40imag.fr

```
When calling a git command from a subdirectory and a file locking fails,
the user will get a path relative to the root of the worktree, which is
invalid from the place where the command is ran. Make it easy for the
user to know which file it is.

Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
---
I'm writting this because I just got the situation with students:

- Sir, we broke our repository (git commit interrupted violently).
- See, the error message tells you what to do.
- But sir, where is .git/index.lock, we can't find it.

This patch would have solved their problem. OTOH, an absolute path can
be rather long and painfull to read/cut-and-paste. I've tried to show
a path relative to where the command was ran (like
"../../.git/index.lock"), but that's really a painfull to implement
(one has to provide a prefix argument to all the calls to
unable_to_lock_*, and even with this, I didn't find the simple way to
make the relative path (probably exists somewhere in Git since 'git
status' does this). Then I gave up :-(.

 lockfile.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/lockfile.c b/lockfile.c
index 6851fa5..e31cbc7 100644
--- a/lockfile.c
+++ b/lockfile.c
@@ -164,9 +164,10 @@ static char *unable_to_lock_message(const char *path, int err)
 		    "If no other git process is currently running, this probably means a\n"
 		    "git process crashed in this repository earlier. Make sure no other git\n"
 		    "process is running and remove the file manually to continue.",
-		    path, strerror(err));
+			    make_absolute_path(path), strerror(err));
 	} else
-		strbuf_addf(&buf, "Unable to create '%s.lock': %s", path, strerror(err));
+		strbuf_addf(&buf, "Unable to create '%s.lock': %s",
+			    make_absolute_path(path), strerror(err));
 	return strbuf_detach(&buf, NULL);
 }
 
-- 
1.6.6.76.gd6b23.dirty

```

## Johannes Sixt, 2010-01-06 18:50

Subject: Re: [RFC/PATCH] lockfile: show absolute filename in unable_to_lock_message.
Message-ID: <4B44DB6A.2050804@kdbg.org>
URL: https://gitlist.dev/e/4B44DB6A.2050804%40kdbg.org
In-Reply-To: <1262797288-23004-1-git-send-email-Matthieu.Moy@imag.fr>

```
Matthieu Moy schrieb:
> -		    path, strerror(err));
> +			    make_absolute_path(path), strerror(err));
>  	} else
> -		strbuf_addf(&buf, "Unable to create '%s.lock': %s", path, strerror(err));
> +		strbuf_addf(&buf, "Unable to create '%s.lock': %s",
> +			    make_absolute_path(path), strerror(err));

Since these are merely informative, wouldn't it be more suitable to use 
make_nonrelative_path()?

-- Hannes

```

## Matthieu Moy, 2010-01-07 14:54

Subject: [PATCH] lockfile: show absolute filename in unable_to_lock_message.
Message-ID: <1262876050-345-1-git-send-email-Matthieu.Moy@imag.fr>
URL: https://gitlist.dev/e/1262876050-345-1-git-send-email-Matthieu.Moy%40imag.fr
In-Reply-To: <4B44DB6A.2050804@kdbg.org>

```
When calling a git command from a subdirectory and a file locking fails,
the user will get a path relative to the root of the worktree, which is
invalid from the place where the command is ran. Make it easy for the
user to know which file it is.

Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
---
> Since these are merely informative, wouldn't it be more suitable to
> use make_nonrelative_path()?

Sensible, yes.

 lockfile.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/lockfile.c b/lockfile.c
index 6851fa5..b0d74cd 100644
--- a/lockfile.c
+++ b/lockfile.c
@@ -164,9 +164,10 @@ static char *unable_to_lock_message(const char *path, int err)
 		    "If no other git process is currently running, this probably means a\n"
 		    "git process crashed in this repository earlier. Make sure no other git\n"
 		    "process is running and remove the file manually to continue.",
-		    path, strerror(err));
+			    make_nonrelative_path(path), strerror(err));
 	} else
-		strbuf_addf(&buf, "Unable to create '%s.lock': %s", path, strerror(err));
+		strbuf_addf(&buf, "Unable to create '%s.lock': %s",
+			    make_nonrelative_path(path), strerror(err));
 	return strbuf_detach(&buf, NULL);
 }
 
-- 
1.6.6.81.gda96d0

```

## Matthieu Moy, 2010-01-12 10:20

Subject: Re: [PATCH] lockfile: show absolute filename in unable_to_lock_message.
Message-ID: <vpq1vhvk4km.fsf@bauges.imag.fr>
URL: https://gitlist.dev/e/vpq1vhvk4km.fsf%40bauges.imag.fr
In-Reply-To: <1262876050-345-1-git-send-email-Matthieu.Moy@imag.fr>

```
Just ping-ing ...

I think the patch makes sense. Junio, can you either queue the patch,
or argue against it? I promise I'll be nice if you chose the second
option ;-).

Thanks,

Matthieu Moy <Matthieu.Moy@imag.fr> writes:

> When calling a git command from a subdirectory and a file locking fails,
> the user will get a path relative to the root of the worktree, which is
> invalid from the place where the command is ran. Make it easy for the
> user to know which file it is.
>
> Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
> ---
>> Since these are merely informative, wouldn't it be more suitable to
>> use make_nonrelative_path()?
>
> Sensible, yes.
>
>  lockfile.c |    5 +++--
>  1 files changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/lockfile.c b/lockfile.c
> index 6851fa5..b0d74cd 100644
> --- a/lockfile.c
> +++ b/lockfile.c
> @@ -164,9 +164,10 @@ static char *unable_to_lock_message(const char *path, int err)
>  		    "If no other git process is currently running, this probably means a\n"
>  		    "git process crashed in this repository earlier. Make sure no other git\n"
>  		    "process is running and remove the file manually to continue.",
> -		    path, strerror(err));
> +			    make_nonrelative_path(path), strerror(err));
>  	} else
> -		strbuf_addf(&buf, "Unable to create '%s.lock': %s", path, strerror(err));
> +		strbuf_addf(&buf, "Unable to create '%s.lock': %s",
> +			    make_nonrelative_path(path), strerror(err));
>  	return strbuf_detach(&buf, NULL);
>  }
>  
> -- 
> 1.6.6.81.gda96d0

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

```

## Junio C Hamano, 2010-01-13 06:56

Subject: Re: [PATCH] lockfile: show absolute filename in unable_to_lock_message.
Message-ID: <7vk4vmsdbg.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vk4vmsdbg.fsf%40alter.siamese.dyndns.org
In-Reply-To: <1262876050-345-1-git-send-email-Matthieu.Moy@imag.fr>

```
Thanks.

```
