Re: [PATCH] More readable 'Not a git repository' messages
On Tue, Aug 10, 2010 at 3:24 AM, Ralf Ebert <info@ralfebert.de> wrote:
Show 47 quoted lines
> Stating the folder concerned with the operation and wording the
> messages differently make them slightly more readable.
>
> old: Not a git repository (or any of the parent directories): .git
> new: Not in a git repository: /home/bob/somefolder
>
> old: Not a git repository (or any parent up to mount parent /home/bob)
> old: Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not
> set).
> new: Not in a git repository: /home/bob/somefolder
> new: (stopped searching at /home because GIT_DISCOVERY_ACROSS_FILESYSTEM is
> not set)
>
> Signed-off-by: Ralf Ebert <info@ralfebert.de>
> ---
> setup.c | 11 +++++++----
> 1 files changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/setup.c b/setup.c
> index 2769160..e27fbf1 100644
> --- a/setup.c
> +++ b/setup.c
> @@ -321,6 +321,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
> {
> const char *work_tree_env = getenv(GIT_WORK_TREE_ENVIRONMENT);
> const char *env_ceiling_dirs =
> getenv(CEILING_DIRECTORIES_ENVIRONMENT);
> + char cwd_orig[PATH_MAX];
> static char cwd[PATH_MAX+1];
> const char *gitdirenv;
> const char *gitfile_dir;
> @@ -376,8 +377,9 @@ const char *setup_git_directory_gently(int *nongit_ok)
> die("Not a git repository: '%s'", gitdirenv);
> }
> - if (!getcwd(cwd, sizeof(cwd)-1))
> + if (!getcwd(cwd_orig, sizeof(cwd_orig)))
> die_errno("Unable to read current working directory");
> + strcpy(cwd, cwd_orig);
> ceil_offset = longest_ancestor_length(cwd, env_ceiling_dirs);
> if (ceil_offset < 0 && has_dos_drive_prefix(cwd))
> @@ -431,7 +433,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
> *nongit_ok = 1;
> return NULL;
> }
> - die("Not a git repository (or any of the parent
> directories): %s", DEFAULT_GIT_DIR_ENVIRONMENT);
> + die("Not in a git repository: %s", cwd_orig);cwd can be used in this case.
Show 15 quoted lines
> }
> if (one_filesystem) {
> if (stat("..", &buf)) {
> @@ -446,8 +448,9 @@ const char *setup_git_directory_gently(int *nongit_ok)
> return NULL;
> }
> cwd[offset] = '\0';
> - die("Not a git repository (or any parent up
> to mount parent %s)\n"
> - "Stopping at filesystem boundary
> (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).", cwd);
> + die("Not in a git repository: %s\n"
> + "(stopped searching at %s because "
> + "GIT_DISCOVERY_ACROSS_FILESYSTEM is not
> set)", cwd_orig, cwd);How about this and avoid adding cwd_orig?
- cwd[offset] = '\0';
- die("Not a git repository (or any
parent up to mount parent %s)\n"
- "Stopping at filesystem boundary
(GIT_DISCOVERY_ACROSS_FILESYSTEM not set).", cwd);
+ die("Not in a git repository: %s\n"
+ "(stopped searching at %.*s because "
+ "GIT_DISCOVERY_ACROSS_FILESYSTEM is
not set)", cwd, offset, cwd);--
Duy