Support ent:relative_path
PATCH v2 1/1 Support ent:relative_path
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
--- cache.h | 2 ++ config.c | 5 +++++ environment.c | 1 + setup.c | 5 ++++- sha1_name.c | 29 ++++++++++++++++++++++++++--- 5 files changed, 38 insertions(+), 4 deletions(-)
cache.h +2 -0
@@ -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;
config.c +5 -0
@@ -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 ;
environment.c +1 -0
@@ -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 */
setup.c +4 -1
@@ -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)
sha1_name.c +26 -3
@@ -592,6 +592,26 @@ 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) +return ; +if (!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 +701,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 +729,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; }
Signature · 1 line
1.5.2.rc0.787.g0014
Dana How, Fri, May 04, 2007 09:43:00 +0200:
config.c int git_default_config(const char *var, const char *value) · line 285
Quoted 4 lines
config.c +4
-0+if (!strcmp (var,"core.relativepaths" )) { + assume_relative_paths =git_config_bool (var, value); +return 0 ; + }
Still don't like it. What good is a syntax you cannot depend upon?
Quoted 6 lines · Alex Riesen
Dana How, Fri, May 04, 2007 09:43:00 +0200:
config.c int git_default_config(const char *var, const char *value) · line 285
Quoted 4 lines
config.c +4
-0+if (!strcmp (var,"core.relativepaths" )) { + assume_relative_paths =git_config_bool (var, value); +return 0 ; + }Still don't like it. What good is a syntax you cannot depend upon?
No worry.
Junio already squashed this, and I agreed.
Signature · 1 line
Dana L. How [email protected] +1 650 804 5991 cell