Skip to contentSkip to conversation

Introducing the .git file

PATCH New Lars Hjemli 1 participant 5 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

v3 cover Introducing the .git file

This is a resend of my previous series implementing the .git file,
rebased on top of todays master (e3c58f8b). The patches are identical
to the final suggestions in http://thread.gmane.org/gmane.comp.version-control.git/74258
except for the previous 1/5 which is dropped from the series (since it already appears in master). There are also some minor touch-ups to the commit messages.

Shortlog:
Add platform-independent .git "symlink"
Teach resolve_gitlink_ref() about the .git file
Teach git-submodule.sh about 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-submodule.sh                    |    4 +-
 refs.c                              |   17 +++++-
 setup.c                             |   47 ++++++++++++++++
 t/t0002-gitfile.sh                  |  103 +++++++++++++++++++++++++++++++++++
 8 files changed, 174 insertions(+), 7 deletions(-)
#1 lore raw

PATCH v3 1/4 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                  |  103 +++++++++++++++++++++++++++++++++++
 5 files changed, 157 insertions(+), 1 deletions(-)
 create mode 100755 t/t0002-gitfile.sh
Documentation/repository-layout.txt +4 -1
index 6939130..bbaed2e 100644
@@ -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
index e1000bc..1ad822a 100644
@@ -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
index 3527f16..8058e7b 100644
@@ -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
#2 lore raw

PATCH v3 2/4 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
index 67d2a50..56de5cf 100644
@@ -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 *re
 		return -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
#3 lore raw

PATCH v3 3/4 Teach git-submodule.sh about 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
index a6aaf40..e7c08b5 100755
@@ -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
#4 lore raw

PATCH v3 4/4 Teach GIT-VERSION-GEN about the .git file

The presence of a .git directory used to be good enough evidence that GIT-VERSION-GEN could use 'git describe' to get a version number. But now .git might as well be a file so the test must be extended to cater for such setups.

---
 GIT-VERSION-GEN |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
GIT-VERSION-GEN +1 -1
index 1ad324e..10fe488 100755
@@ -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