git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] cg-Xlib: use git-rev-parse to locate .git dir and set relpath

From
Jonas Fonseca <fonseca@diku.dk>
Date
Nov 27, 2005, 15:55 UTC
Message-ID
<20051127155521.GA9558@diku.dk>
Signed-off-by: Jonas Fonseca <fonseca@diku.dk>
---
diff --git a/cg-Xlib b/cg-Xlib
index dedbb62..e3c365f 100755
--- a/cg-Xlib
+++ b/cg-Xlib
@@ -502,16 +502,10 @@ fi
 
 _git=${GIT_DIR:-.git}
 if [ ! "$_git_repo_unneeded" ] && [ ! "$GIT_DIR" ] && [ ! -d $_git ]; then
-	rootpath=.
-	# while not /
-	while [ ! -d $rootpath/.git ] && [ "$(stat -c %i $rootpath)" != "$(stat -c %i $rootpath/..)" ]; do
-		rootpath=../$rootpath
-	done
-	if [ -d $rootpath/.git ]; then
-		mainpath="$(echo "$(pwd)/$rootpath" | normpath)"
-		_git_relpath=$(pwd)/
-		export _git_relpath=${_git_relpath:$((${#mainpath}+1))}
-		cd "$rootpath"
+	_git_abs_path="$(git-rev-parse --git-dir 2>/dev/null)"
+	if [ -d "$_git_abs_path" ]; then
+		export _git_relpath="$(git-rev-parse --show-prefix)"
+		cd "$_git_abs_path/.."
 	fi
 fi
 _git_objects="${GIT_OBJECT_DIRECTORY:-$_git/objects}"
-- 
Jonas Fonseca
Message 1 of 1 in “cg-Xlib: use git-rev-parse to locate .git dir and set relpath”
  1. cg-Xlib: use git-rev-parse to locate .git dir and set relpathJonas Fonseca, Nov 27, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.