Introduce the .gitfile
v2 cover Introduce the .gitfile
The patch-series has been reordered and updated according to comments on the earlier series.
Shortlog:
Simplify setup of $GIT_DIR in git-sh-setup.sh
Add platform-independent .git "symlink"
Teach resolve_gitlink_ref() about the .git file
git-submodule: prepare for the .git-file
Teach GIT-VERSION-GEN about the .git file
Diffstat:
Documentation/repository-layout.txt | 5 ++- GIT-VERSION-GEN | 2 +- cache.h | 1 + environment.c | 2 + git-sh-setup.sh | 8 +--- git-submodule.sh | 4 +- refs.c | 17 +++++++- setup.c | 47 ++++++++++++++++++++++ t/t0002-gitfile.sh | 74 +++++++++++++++++++++++++++++++++++ 9 files changed, 146 insertions(+), 14 deletions(-)
PATCH v2 1/5 Simplify setup of $GIT_DIR in git-sh-setup.sh
Using 'git rev-parse --git-dir' makes the code shorter and more future- proof.
--- git-sh-setup.sh | 8 +------- 1 files changed, 1 insertions(+), 7 deletions(-)
git-sh-setup.sh +1 -7
@@ -127,20 +127,14 @@ get_author_ident_from_commit () { # if we require to be in a git repository. if test -z "$NONGIT_OK" then + GIT_DIR=$(git rev-parse --git-dir) || exit if [ -z "$SUBDIRECTORY_OK" ] then - : ${GIT_DIR=.git} test -z "$(git rev-parse --show-cdup)" || { exit=$? echo >&2 "You need to run this command from the toplevel of the working tree." exit $exit } - else - GIT_DIR=$(git rev-parse --git-dir) || { - exit=$? - echo >&2 "Failed to find a valid git directory." - exit $exit - } fi test -n "$GIT_DIR" && GIT_DIR=$(cd "$GIT_DIR" && pwd) || { echo >&2 "Unable to determine absolute path of git directory"
Signature · 1 line
1.5.4.1.188.g3ea1f5
PATCH v2 2/5 Add platform-independent .git "symlink"
This patch allows .git to be a regular textfile containing the path of the real git directory (prefixed with "gitdir: "), which can be useful on platforms lacking support for real symlinks.
--- Documentation/repository-layout.txt | 5 ++- cache.h | 1 + environment.c | 2 + setup.c | 47 ++++++++++++++++++++++ t/t0002-gitfile.sh | 74 +++++++++++++++++++++++++++++++++++ 5 files changed, 128 insertions(+), 1 deletions(-) create mode 100755 t/t0002-gitfile.sh
Documentation/repository-layout.txt +4 -1
@@ -3,7 +3,10 @@ git repository layout You may find these things in your git repository (`.git` directory for a repository associated with your working tree, or -`'project'.git` directory for a public 'bare' repository). +`'project'.git` directory for a public 'bare' repository. It is +also possible to have a working tree where `.git` is a plain +ascii file containing `gitdir: <path>`, i.e. the path to the +real git repository). objects:: Object store associated with this repository. Usually
cache.h +1 -0
@@ -277,6 +277,7 @@ extern char *get_index_file(void);extern char *get_graft_file (void );extern int set_git_dir (const char *path);extern const char *get_git_work_tree (void ); +extern const char *read_gitfile_gently (const char *path);#define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES"
environment.c +2 -0
@@ -49,6 +49,8 @@ static void setup_git_env(void) { git_dir =getenv (GIT_DIR_ENVIRONMENT );if (!git_dir) + git_dir =read_gitfile_gently (DEFAULT_GIT_DIR_ENVIRONMENT ); +if (!git_dir) git_dir =DEFAULT_GIT_DIR_ENVIRONMENT ; git_object_dir =getenv (DB_ENVIRONMENT );if (!git_object_dir) {
setup.c +47 -0
73 lines not on this page · raw message
t/t0002-gitfile.sh new file +74 -0
74 lines not on this page · raw message
Signature · 1 line
1.5.4.1.188.g3ea1f5
PATCH v2 3/5 Teach resolve_gitlink_ref() about the .git file
When .git in a submodule is a file, resolve_gitlink_ref() needs to pick up the real GIT_DIR of the submodule from that file.
--- refs.c | 17 ++++++++++++++--- 1 files changed, 14 insertions(+), 3 deletions(-)
refs.c +14 -3
@@ -351,6 +351,7 @@ int resolve_gitlink_ref(const char *path, const char *refname, unsigned char *re {int len =strlen (path), retval;char *gitdir; +const char *tmp;while (len && path[len-1 ] =='/' ) len--;
@@ -358,9 +359,19 @@ int resolve_gitlink_ref(const char *path, const char *refname, unsigned char *rereturn -1 ; gitdir =xmalloc (len +MAXREFLEN +8 );memcpy (gitdir, path, len); -memcpy (gitdir + len,"/.git/" ,7 ); - - retval =resolve_gitlink_ref_recursive (gitdir, len+6 , refname, result,0 ); +memcpy (gitdir + len,"/.git" ,6 ); + len +=5 ; + + tmp =read_gitfile_gently (gitdir); +if (tmp) { +free (gitdir); + len =strlen (tmp); + gitdir =xmalloc (len +MAXREFLEN +3 ); +memcpy (gitdir, tmp, len); + } + gitdir[len] ='/' ; + gitdir[++len] ='\0' ; + retval =resolve_gitlink_ref_recursive (gitdir, len, refname, result,0 );free (gitdir);return retval; }
Signature · 1 line
1.5.4.1.188.g3ea1f5
PATCH v2 4/5 git-submodule: prepare for the .git-file
When git-submodule tries to detect 'active' submodules, it checks for the existence of a directory named '.git'. This isn't good enough now that .git can be a file pointing to the real $GIT_DIR so the tests are changed to reflect this.
--- git-submodule.sh | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
git-submodule.sh +2 -2
@@ -288,7 +288,7 @@ cmd_update() continue fi - if ! test -d "$path"/.git + if ! test -d "$path"/.git -o -f "$path"/.git then module_clone "$path" "$url" || exit subsha1=
@@ -362,7 +362,7 @@ cmd_status() do name=$(module_name "$path") || exit url=$(git config submodule."$name".url) - if test -z "url" || ! test -d "$path"/.git + if test -z "url" || ! test -d "$path"/.git -o -f "$path"/.git then say "-$sha1 $path" continue;
Signature · 1 line
1.5.4.1.188.g3ea1f5
PATCH v2 5/5 Teach GIT-VERSION-GEN about the .git file
--- GIT-VERSION-GEN | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
GIT-VERSION-GEN +1 -1
@@ -11,7 +11,7 @@ LF=' if test -f version then VN=$(cat version) || VN="$DEF_VER" -elif test -d .git && +elif test -d .git -o -f .git && VN=$(git describe --abbrev=4 HEAD 2>/dev/null) && case "$VN" in *$LF*) (exit 1) ;;
Signature · 1 line
1.5.4.1.188.g3ea1f5
Re: [PATCH 2/5] Add platform-independent .git "symlink"
In reply to Lars HjemliHi,
environment.c static void setup_git_env(void) · line 54
Quoted 11 lines · Lars Hjemli
environment.c +2
-0@@ -49,6 +49,8 @@ static void setup_git_env(void) { git_dir =getenv (GIT_DIR_ENVIRONMENT );if (!git_dir) + git_dir =read_gitfile_gently (DEFAULT_GIT_DIR_ENVIRONMENT ); +if (!git_dir) git_dir =DEFAULT_GIT_DIR_ENVIRONMENT ;
I still maintain that the code (maybe not the diff) is easier to read like this:
if (!git_dir) {
git_dir = read_gitfile_gently(DEFAULT_GIT_DIR_ENVIRONMENT);
if (!git_dir)
git_dir = DEFAULT_GIT_DIR_ENVIRONMENT;
}Quoted 15 lines
setup.c +7
-0@@ -239,6 +239,44 @@ static int check_repository_format_gently(int *nongit_ok) }/* +* Try to read the location of the git directory from the .git file, +* return path to git directory if found. +*/ +const char *read_gitfile_gently (const char *path) +{ +char *buf; +struct stat st;
setup.c static int check_repository_format_gently(int *nongit_ok) · line 258
Quoted 10 lines
setup.c +10
-0+int fd; +size_t len; + +if (stat (path, &st)) +return NULL ; +if (!S_ISREG (st.st_mode)) +return NULL ; + fd =open (path,O_RDONLY ); +if (fd <0 ) +die ("Error opening %s: %s" , path,strerror (errno));
Hmm. Like I said, in the "gently" case, we might want to just print a warning and return NULL.
However, since you have 5 die()s in this function that would clutter the code tremendously. I briefly considered (shut your eyes now if you do not like ugly code):
int (*show_error)(const char *format, ...) = nongit_ok ? error : (int (*)(const char *format, ...))die;
but now I think a better method would be
static int show_error(int die_on_error, const char *format, ...)
{
va_list params;
va_start(params, err);
if (die_on_error)
die_routine(err, params);
else
error_routine(err, params);
va_end(params);
return -1;
}This would even be a candidate for a global function die_or_error().
Then you could use it like this:
if (fd < 0 && die("Error opening %s: %s", path, strerror(errno))
return NULL;Hmm. Seeing what I wrote, it does not really feel elegant.
So maybe we can just scratch all that, and I agree that an invalid .git file means "no repository" (as opposed to "no valid repository").
In that case, you might want to test for that, too...
Speaking about tests:
setup.c static int check_repository_format_gently(int *nongit_ok) · line 263
Quoted 5 lines
setup.c +5
-0+test_expect_success 'setup' ' +REAL ="$(pwd)/.real" && + mv .git "$REAL" && + echo "gitdir: $REAL" >.git +'
Let's not do this. It would clutter the t/ directory unnecessarily. Instead, do something like this:
test_expect_success setup '
REAL="$(pwd)/.real" && mkdir test && cd test && echo "gitdir: $REAL" > .git
'
Hmm?
Ciao,
Dscho "who likes to write 'Hmm' three times in a mail"
Re: [PATCH 2/5] Add platform-independent .git "symlink"
Quoted 19 lines · Johannes Schindelin
Hi,
environment.c static void setup_git_env(void) · line 54
Quoted 11 lines · Lars Hjemli
environment.c +2
-0@@ -49,6 +49,8 @@ static void setup_git_env(void) { git_dir =getenv (GIT_DIR_ENVIRONMENT );if (!git_dir) + git_dir =read_gitfile_gently (DEFAULT_GIT_DIR_ENVIRONMENT ); +if (!git_dir) git_dir =DEFAULT_GIT_DIR_ENVIRONMENT ;I still maintain that the code (maybe not the diff) is easier to read like this:
Quoted 5 lines
if (!git_dir) {
git_dir = read_gitfile_gently(DEFAULT_GIT_DIR_ENVIRONMENT);
if (!git_dir)
git_dir = DEFAULT_GIT_DIR_ENVIRONMENT;
}IMHO such constructs are butt ugly, but if there's consensus for your way, I'll abide...
Quoted 6 lines
[* snip *]
So maybe we can just scratch all that, and I agree that an invalid .git file means "no repository" (as opposed to "no valid repository").
In that case, you might want to test for that, too...
I think I do, did you find a loophole in the testing?
Quoted 10 lines
Speaking about tests:
environment.c static void setup_git_env(void)
Quoted 5 lines
environment.c +5
-0+test_expect_success 'setup' ' +REAL ="$(pwd)/.real" && + mv .git "$REAL" && + echo "gitdir: $REAL" >.git +'Let's not do this. It would clutter the t/ directory unnecessarily.
What do you mean? The test just moves t/trash/.git to t/trash/.real...
--
larsh
Re: [PATCH 2/5] Add platform-independent .git "symlink"
Hi,
Quoted 11 lines · Lars Hjemli
Quoted 7 lines · Johannes Schindelin
[* snip *]
So maybe we can just scratch all that, and I agree that an invalid .git file means "no repository" (as opposed to "no valid repository").
In that case, you might want to test for that, too...
I think I do, did you find a loophole in the testing?
I meant writing a readable, but invalid .git file. Then testing that Git die()s with the correct message.
Quoted 11 lines
Quoted 9 lines
Speaking about tests:
t/t0002-gitfile.sh line 26
Quoted 5 lines
t/t0002-gitfile.sh new file +5
-0+test_expect_success 'setup' ' + REAL="$(pwd)/.real" && + mv .git "$REAL" && + echo "gitdir: $REAL" >.git +'Let's not do this. It would clutter the t/ directory unnecessarily.
What do you mean? The test just moves t/trash/.git to t/trash/.real...
Oh, well. I'll go and buy me some new glasses.
Thanks,
Dscho
PATCH v2 2/5 Add platform-independent .git "symlink"
This patch allows .git to be a regular textfile containing the path of the real git directory (prefixed with "gitdir: "), which can be useful on platforms lacking support for real symlinks.
---
Quoted 2 lines · Johannes Schindelin
I meant writing a readable, but invalid .git file. Then testing that Git die()s with the correct message.
Something like this?
Documentation/repository-layout.txt | 5 ++- cache.h | 1 + environment.c | 2 + setup.c | 47 ++++++++++++++++ t/t0002-gitfile.sh | 103 +++++++++++++++++++++++++++++++++++ 5 files changed, 157 insertions(+), 1 deletions(-) create mode 100755 t/t0002-gitfile.sh
Documentation/repository-layout.txt +4 -1
@@ -3,7 +3,10 @@ git repository layout You may find these things in your git repository (`.git` directory for a repository associated with your working tree, or -`'project'.git` directory for a public 'bare' repository). +`'project'.git` directory for a public 'bare' repository. It is +also possible to have a working tree where `.git` is a plain +ascii file containing `gitdir: <path>`, i.e. the path to the +real git repository). objects:: Object store associated with this repository. Usually
cache.h +1 -0
@@ -277,6 +277,7 @@ extern char *get_index_file(void);extern char *get_graft_file (void );extern int set_git_dir (const char *path);extern const char *get_git_work_tree (void ); +extern const char *read_gitfile_gently (const char *path);#define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES"
environment.c +2 -0
@@ -49,6 +49,8 @@ static void setup_git_env(void) { git_dir =getenv (GIT_DIR_ENVIRONMENT );if (!git_dir) + git_dir =read_gitfile_gently (DEFAULT_GIT_DIR_ENVIRONMENT ); +if (!git_dir) git_dir =DEFAULT_GIT_DIR_ENVIRONMENT ; git_object_dir =getenv (DB_ENVIRONMENT );if (!git_object_dir) {
setup.c +47 -0
73 lines not on this page · raw message
t/t0002-gitfile.sh new file +103 -0
103 lines not on this page · raw message
Signature · 1 line
1.5.4.1.188.g3ea1f5
Re: [PATCH 2/5] Add platform-independent .git "symlink"
Hi,
Quoted 5 lines · Lars Hjemli
Quoted 2 lines · Johannes Schindelin
I meant writing a readable, but invalid .git file. Then testing that Git die()s with the correct message.
Something like this?
Sure.
Ciao,
Dscho
Re: [PATCH 2/5] Add platform-independent .git "symlink"
In reply to Johannes SchindelinQuoted 11 lines · Johannes Schindelin
Hi,
Quoted 7 lines · Lars Hjemli
Quoted 6 lines · Johannes Schindelin
[* snip *]
So maybe we can just scratch all that, and I agree that an invalid .git file means "no repository" (as opposed to "no valid repository").
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
In that case, you might want to test for that, too...
I think I do, did you find a loophole in the testing?
I meant writing a readable, but invalid .git file. Then testing that Git die()s with the correct message.
Ah, sorry for being slow, that's an excellent suggestion. I'll update the test-script and resend 2/5.
--
larsh
Re: [PATCH 2/5] Add platform-independent .git "symlink"
In reply to Lars HjemliQuoted 18 lines · Lars Hjemli
Quoted 17 lines · Johannes Schindelin
environment.c static void setup_git_env(void) · line 54
Quoted 11 lines · Lars Hjemli
environment.c +2
-0@@ -49,6 +49,8 @@ static void setup_git_env(void) { git_dir = getenv(GIT_DIR_ENVIRONMENT); if (!git_dir) + git_dir = read_gitfile_gently(DEFAULT_GIT_DIR_ENVIRONMENT); + if (!git_dir) git_dir = DEFAULT_GIT_DIR_ENVIRONMENT;I still maintain that the code (maybe not the diff) is easier to read like this:
Quoted 8 lines
Quoted 5 lines
if (!git_dir) {
git_dir=read_gitfile_gently(DEFAULT_GIT_DIR_ENVIRONMENT); if (!git_dir)
git_dir=DEFAULT_GIT_DIR_ENVIRONMENT; }IMHO such constructs are butt ugly, but if there's consensus for your way, I'll abide...
I prefer the original variant. It is IMHO no less, and perhaps even more readable, and it is not soo deeply nested.
Signature · 3 lines
Jakub Narebski Warsaw, Poland ShadeHawk on #git
Hi,
Quoted 2 lines · Lars Hjemli
The patch-series has been reordered and updated according to comments on the earlier series.
It would be easier on a stupid reviewer like me, if you summarised what you changed. In the case of patch "1/5 => 2/5", I would even have appreciated an interdiff...
Oh, and I was kind of surprised to learn that it is the ".gitfile", not the ".git file"... I ran to your patch straight away, and was relieved when I found out that you still call it ".git".
Ciao,
Dscho
Quoted 7 lines · Johannes Schindelin
Quoted 2 lines · Lars Hjemli
The patch-series has been reordered and updated according to comments on the earlier series.
It would be easier on a stupid reviewer like me, if you summarised what you changed.
Ok, I'll keep that in mind next time, and here's a quick summary (from the top of my head) of this series vs. the previous:
* patch 1 and 2 are swapped, since the changes to git-sh-setup.sh can be applied onto master regardless of the rest of the patch series (while the other patches still rely on 1/5).
* git-sh-setup.sh is simplified even further, and relies on git-rev-parse to produce the error message when no gitdir can be found.
* read_gitfile_gently() is moved from environment.c into setup.c since it now invokes is_git_directory().
* read_gitfile_gently() will gently ignore a 'missing' .git or a .git which isn't a regular file, but die()s on all other errors.
Quoted 2 lines
In the case of patch "1/5 => 2/5", I would even have appreciated an interdiff...
Sorry, but I don't think I understand what you mean by interdiff.
Quoted 4 lines
Oh, and I was kind of surprised to learn that it is the ".gitfile", not the ".git file"... I ran to your patch straight away, and was relieved when I found out that you still call it ".git".
Yeah, I suck really bad on consistency ;-)
--
lh
Hi,
Quoted 10 lines · Lars Hjemli
Quoted 7 lines · Johannes Schindelin
Quoted 2 lines · Lars Hjemli
The patch-series has been reordered and updated according to comments on the earlier series.
It would be easier on a stupid reviewer like me, if you summarised what you changed.
Quoted 12 lines
Ok, I'll keep that in mind next time, and here's a quick summary (from the top of my head) of this series vs. the previous:
* patch 1 and 2 are swapped, since the changes togit-sh-setup.shcan be applied onto master regardless of the rest of the patch series (while the other patches still rely on 1/5).
*git-sh-setup.shis simplified even further, and relies on git-rev-parse to produce the error message when no gitdir can be found.
*read_gitfile_gently()is moved fromenvironment.cintosetup.csince it now invokesis_git_directory().
*read_gitfile_gently()will gently ignore a 'missing' .git or a .git which isn't a regular file, but die()s on all other errors.
Thanks.
Quoted 4 lines
Quoted 2 lines
In the case of patch "1/5 => 2/5", I would even have appreciated an interdiff...
Sorry, but I don't think I understand what you mean by interdiff.
The tool interdiff of patchutils is really nice: you can visualise what would be the diff between the state after applying the first patch, and the state after applying the second patch, without applying anything at all:
$ interdiff <patch1> <patch2>
Ciao,
Dscho
Quoted 8 lines · Johannes Schindelin
Hi,
Quoted 4 lines · Lars Hjemli
Quoted 2 lines · Johannes Schindelin
In the case of patch "1/5 => 2/5", I would even have appreciated an interdiff...
Quoted 8 lines
Quoted 1 line
Sorry, but I don't think I understand what you mean by interdiff.
The tool interdiff of patchutils is really nice: you can visualise what would be the diff between the state after applying the first patch, and the state after applying the second patch, without applying anything at all:
$ interdiff <patch1> <patch2>
Ok, that sounds useful (I was kind of confused since 'man interdiff' gave me nothing: being on slackware I'm so spoiled with preinstalled dev-tools that I see no point in consulting google ;).
Something like this (possibly mangled by gmail)?
$ interdiff prev-patch-2 curr-patch-1
diff -u b/git-sh-setup.sh b/git-sh-setup.sh
--- b/git-sh-setup.sh
+++ b/git-sh-setup.sh
@@ -127,11 +127,7 @@
# if we require to be in a git repository.
if test -z "$NONGIT_OK"
then
- GIT_DIR=$(git rev-parse --git-dir) || {
- exit=$?
- echo >&2 "Failed to find a valid git directory."
- exit $exit
- }
+ GIT_DIR=$(git rev-parse --git-dir) || exit
if [ -z "$SUBDIRECTORY_OK" ]
then
test -z "$(git rev-parse --show-cdup)" || {$ interdiff prev-patch-1 curr-patch-2 diff -u b/Documentation/repository-layout.txt b/Documentation/repository-layout.txt --- b/Documentation/repository-layout.txt +++ b/Documentation/repository-layout.txt @@ -5,7 +5,7 @@ directory for a repository associated with your working tree, or `'project'.git` directory for a public 'bare' repository. It is also possible to have a working tree where `.git` is a plain -ascii file containing `gitdir: <path>\n`, i.e. the path to the +ascii file containing `gitdir: <path>`, i.e. the path to the real git repository).
objects::
environment.c +0 -36
@@ -45,42 +45,6 @@static const char *git_dir;static char *git_object_dir, *git_index_file, *git_refs_dir, *git_graft_file; -/* -* Try to read the location of the git directory from the .git file, -* return path to git directory if found. -* Format of the .git file is -* gitdir: <path>\n -*/ -const char *read_gitfile_gently (const char *path) -{ -static char buf[PATH_MAX +9 ];/* "gitdir: " + "\n" */ -struct stat st; -int fd; -size_t len; - -if (stat (path, &st)) -return NULL ; -if (!S_ISREG (st.st_mode) || st.st_size >=sizeof (buf)) -return NULL ; - fd =open (path,O_RDONLY ); -if (fd <0 ) -return NULL ; - len =read_in_full (fd, buf,sizeof (buf)); -close (fd); -if (len != st.st_size) -return NULL ; -if (!len || buf[len -1 ] !='\n' ) -return NULL ; - buf[len -1 ] ='\0' ; -if (prefixcmp (buf,"gitdir: " )) -return NULL ; -/* -if (!is_git_directory(buf + 8)) -return NULL; -*/ -return make_absolute_path (buf +8 ); -} -static void setup_git_env (void ) { git_dir =getenv (GIT_DIR_ENVIRONMENT );
setup.c +42 -4
67 lines not on this page · raw message
--
larsh
Hi,
Quoted 15 lines · Lars Hjemli
Quoted 13 lines · Johannes Schindelin
Quoted 5 lines · Lars Hjemli
Quoted 2 lines · Johannes Schindelin
In the case of patch "1/5 => 2/5", I would even have appreciated an interdiff...
Sorry, but I don't think I understand what you mean by interdiff.
The tool interdiff of patchutils is really nice: you can visualise what would be the diff between the state after applying the first patch, and the state after applying the second patch, without applying anything at all:
Quoted 7 lines
Quoted 1 line
$ interdiff <patch1> <patch2>Ok, that sounds useful (I was kind of confused since 'man interdiff' gave me nothing: being on slackware I'm so spoiled with preinstalled dev-tools that I see no point in consulting google ;).
Something like this (possibly mangled by gmail)?
Heh, thank you! The mangling does not matter, since this is purely for reviewing pleasure.
Thanks,
Dscho