git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Dana How" <danahow@gmail.com>
To: "Junio C Hamano" <junkio@cox.net>
Cc: "Git Mailing List" <git@vger.kernel.org>, danahow@gmail.com
Subject: Re: [PATCH] Support ent:relative_path
Date: Fri, 4 May 2007 00:22:28 -0700	[thread overview]
Message-ID: <56b7f5510705040022x2e4903d3hbe4ac1ee1a2e096f@mail.gmail.com> (raw)
In-Reply-To: <463ADE51.2030108@gmail.com>

Yikes... the if's in prepend_prefix() need to be re-arranged.

Dana

On 5/4/07, Dana How <danahow@gmail.com> wrote:
>
> Most commands accept relative paths,  but this is
> not true of arguments in ent:path format.  This
> patch makes all 3 of the following git-show commands
> work in the git source tree (not just the first):
>  % cd xdiff
>  % git-show v1.5.2-rc0:xdiff/xemit.h
>  % git-show v1.5.2-rc0:./xemit.h
>  % git-config --bool core.relativepaths yes
>  % git-show v1.5.2-rc0:xemit.h
>
> Signed-off-by: Dana L. How <danahow@gmail.com>
> ---
>  cache.h       |    2 ++
>  config.c      |    5 +++++
>  environment.c |    1 +
>  setup.c       |    5 ++++-
>  sha1_name.c   |   27 ++++++++++++++++++++++++---
>  5 files changed, 36 insertions(+), 4 deletions(-)
>
> diff --git a/cache.h b/cache.h
> index 8e76152..fc3fcb1 100644
> --- a/cache.h
> +++ b/cache.h
> @@ -215,6 +215,7 @@ extern char *get_graft_file(void);
>
>  #define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES"
>
> +extern const char *prefix_to_cwd;
>  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);
> @@ -276,6 +277,7 @@ extern int delete_ref(const char *, const unsigned char *sha1);
>  extern int use_legacy_headers;
>  extern int trust_executable_bit;
>  extern int has_symlinks;
> +extern int assume_relative_paths;
>  extern int assume_unchanged;
>  extern int prefer_symlink_refs;
>  extern int log_all_ref_updates;
> diff --git a/config.c b/config.c
> index 70d1055..7525965 100644
> --- a/config.c
> +++ b/config.c
> @@ -279,6 +279,11 @@ int git_default_config(const char *var, const char *value)
>                 return 0;
>         }
>
> +       if (!strcmp(var, "core.relativepaths")) {
> +               assume_relative_paths = git_config_bool(var, value);
> +               return 0;
> +       }
> +
>         if (!strcmp(var, "core.ignorestat")) {
>                 assume_unchanged = git_config_bool(var, value);
>                 return 0;
> diff --git a/environment.c b/environment.c
> index 2231659..f1b867d 100644
> --- a/environment.c
> +++ b/environment.c
> @@ -14,6 +14,7 @@ char git_default_name[MAX_GITNAME];
>  int use_legacy_headers = 1;
>  int trust_executable_bit = 1;
>  int has_symlinks = 1;
> +int assume_relative_paths;
>  int assume_unchanged;
>  int prefer_symlink_refs;
>  int is_bare_repository_cfg = -1; /* unspecified */
> diff --git a/setup.c b/setup.c
> index a45ea83..46ae6e3 100644
> --- a/setup.c
> +++ b/setup.c
> @@ -1,5 +1,7 @@
>  #include "cache.h"
>
> +const char *prefix_to_cwd;
> +
>  const char *prefix_path(const char *prefix, int len, const char *path)
>  {
>         const char *orig = path;
> @@ -252,7 +254,8 @@ const char *setup_git_directory_gently(int *nongit_ok)
>         cwd[len++] = '/';
>         cwd[len] = 0;
>         inside_git_dir = !prefixcmp(cwd + offset, ".git/");
> -       return cwd + offset;
> +       prefix_to_cwd = cwd + offset;
> +       return prefix_to_cwd;
>  }
>
>  int git_config_perm(const char *var, const char *value)
> diff --git a/sha1_name.c b/sha1_name.c
> index 55f25a2..0b9e92c 100644
> --- a/sha1_name.c
> +++ b/sha1_name.c
> @@ -592,6 +592,24 @@ static int handle_one_ref(const char *path,
>         return 0;
>  }
>
> +static void prepend_prefix(const char **cp, int *namelen)
> +{
> +       static char fullpath[PATH_MAX];
> +       if (*namelen > 2 && !memcmp(*cp, "./", 2)) {
> +               *cp += 2;
> +               *namelen -= 2;
> +       } else
> +       if (!assume_relative_paths || !prefix_to_cwd)
> +               return;
> +
> +       *namelen += strlen(prefix_to_cwd);
> +       if (*namelen >= PATH_MAX)
> +               die("path too long");
> +       strcpy(fullpath, prefix_to_cwd);
> +       strcat(fullpath, *cp);
> +       *cp = fullpath;
> +}
> +
>  /*
>   * This interprets names like ':/Initial revision of "git"' by searching
>   * through history and returning the first commit whose message starts
> @@ -681,6 +699,7 @@ int get_sha1_with_mode(const char *name, unsigned char *sha1, unsigned *mode)
>                         read_cache();
>                 if (active_nr < 0)
>                         return -1;
> +               prepend_prefix(&cp, &namelen);
>                 pos = cache_name_pos(cp, namelen);
>                 if (pos < 0)
>                         pos = -pos - 1;
> @@ -708,9 +727,11 @@ int get_sha1_with_mode(const char *name, unsigned char *sha1, unsigned *mode)
>         }
>         if (*cp == ':') {
>                 unsigned char tree_sha1[20];
> -               if (!get_sha1_1(name, cp-name, tree_sha1))
> -                       return get_tree_entry(tree_sha1, cp+1, sha1,
> -                                             mode);
> +               if (!get_sha1_1(name, cp - name, tree_sha1)) {
> +                       namelen -= ++cp - name;
> +                       prepend_prefix(&cp, &namelen);
> +                       return get_tree_entry(tree_sha1, cp, sha1, mode);
> +               }
>         }
>         return ret;
>  }
> --
> 1.5.2.rc0.787.g0014
>
>


-- 
Dana L. How  danahow@gmail.com  +1 650 804 5991 cell

  reply	other threads:[~2007-05-04  7:22 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-04  7:18 [PATCH] Support ent:relative_path Dana How
2007-05-04  7:22 ` Dana How [this message]
2007-05-04  8:21   ` Junio C Hamano
2007-05-04  8:45     ` Dana How
2007-05-04  8:47     ` Alex Riesen
2007-05-04  8:53       ` Dana How
2007-05-04  9:17         ` Alex Riesen
2007-05-04  9:26           ` Dana How
2007-05-04  9:46             ` Alex Riesen
2007-05-04 16:57               ` Dana How
2007-05-04 17:17                 ` Alex Riesen
2007-05-04 19:00                   ` Johannes Schindelin
2007-05-04 20:23                     ` Alex Riesen
2007-05-04  9:19       ` Johannes Sixt
2007-05-04 17:17         ` Junio C Hamano
2007-05-04 18:23           ` Dana How
2007-05-04 19:06           ` Johannes Schindelin
2007-05-04 19:22             ` Junio C Hamano
2007-05-04 19:31               ` Johannes Schindelin
2007-05-04 19:38                 ` Junio C Hamano
2007-05-04 19:42                   ` Johannes Schindelin
2007-05-04 20:21           ` Alex Riesen
2007-05-04 23:36           ` Jakub Narebski
2007-05-05  0:04             ` Junio C Hamano
2007-05-05  0:52               ` Dana How
2007-05-05  1:06                 ` Jakub Narebski
2007-05-05  1:15                 ` Junio C Hamano
2007-05-04  8:20 ` Alex Riesen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=56b7f5510705040022x2e4903d3hbe4ac1ee1a2e096f@mail.gmail.com \
    --to=danahow@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).