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

Re: [PATCH 0/5 v2] Introduce the .gitfile

From
LHLars Hjemli <hjemli@gmail.com>
Date
Feb 18, 2008, 14:01 UTC
Message-ID
<8c5c35580802180601h5cf01c5h583458fee61caa7a@mail.gmail.com>
In-Reply-To
<alpine.LSU.1.00.0802181330030.30505@racer.site>
On Feb 18, 2008 2:31 PM, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
Show 16 quoted lines
> Hi,
>
> On Mon, 18 Feb 2008, Lars Hjemli wrote:
>
> > On Feb 18, 2008 1:17 PM, Johannes Schindelin wrote:
> > > 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>

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::
diff -u b/environment.c b/environment.c
--- b/environment.c
+++ b/environment.c
@@ -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);
diff -u b/setup.c b/setup.c
--- b/setup.c
+++ b/setup.c
@@ -239,6 +239,44 @@
 }

 /*
+ * 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;
+       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));
+       buf = xmalloc(st.st_size + 1);
+       len = read_in_full(fd, buf, st.st_size);
+       close(fd);
+       if (len != st.st_size)
+               die("Error reading %s", path);
+       buf[len] = '\0';
+       if (prefixcmp(buf, "gitdir: "))
+               die("Invalid gitfile format: %s", path);
+       while (buf[len - 1] == '\n' || buf[len - 1] == '\r')
+               len--;
+       if (len < 9)
+               die("No path in gitfile: %s", path);
+       buf[len] = '\0';
+       if (!is_git_directory(buf + 8))
+               die("Not a git repository: %s", buf + 8);
+       path = make_absolute_path(buf + 8);
+       free(buf);
+       return path;
+}
+
+/*
  * We cannot decide in this function whether we are in the work tree or
  * not, since the config can only be read _after_ this function was called.
  */
@@ -294,10 +332,10 @@

        /*
         * Test in the following order (relative to the cwd):
-        * - .git (file containing "gitdir: <path>\n")
+        * - .git (file containing "gitdir: <path>")
         * - .git/
         * - ./ (bare)
-        * - ../.git (file containing "gitdir: <path>\n")
+        * - ../.git
         * - ../.git/
         * - ../ (bare)
         * - ../../.git/
@@ -306,9 +344,9 @@
        offset = len = strlen(cwd);
        for (;;) {
                gitfile_dir = read_gitfile_gently(DEFAULT_GIT_DIR_ENVIRONMENT);
-               if (gitfile_dir && is_git_directory(gitfile_dir)) {
+               if (gitfile_dir) {
                        if (set_git_dir(gitfile_dir))
-                               return NULL;
+                               die("Repository setup failed");
                        break;
                }
                if (is_git_directory(DEFAULT_GIT_DIR_ENVIRONMENT))


--
larsh
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 17 of 18 in “Introduce the .gitfile”
  1. 0/5 Introduce the .gitfileLars Hjemli, Feb 18, 2008
  2. 1/5 Simplify setup of $GIT_DIR in git-sh-setup.shLars Hjemli, Feb 18, 2008
  3. 2/5 Add platform-independent .git "symlink"Lars Hjemli, Feb 18, 2008
  4. 3/5 Teach resolve_gitlink_ref() about the .git fileLars Hjemli, Feb 18, 2008
  5. 4/5 git-submodule: prepare for the .git-fileLars Hjemli, Feb 18, 2008
  6. 5/5 Teach GIT-VERSION-GEN about the .git fileLars Hjemli, Feb 18, 2008
  7. Johannes SchindelinFeb 18, 2008
  8. Lars HjemliFeb 18, 2008
  9. Jakub NarebskiFeb 18, 2008
  10. Johannes SchindelinFeb 18, 2008
  11. Lars HjemliFeb 18, 2008
  12. 2/5 Add platform-independent .git "symlink"Lars Hjemli, Feb 18, 2008
  13. Johannes SchindelinFeb 18, 2008
  14. Johannes SchindelinFeb 18, 2008
  15. Lars HjemliFeb 18, 2008
  16. Johannes SchindelinFeb 18, 2008
  17. Lars HjemliFeb 18, 2008
  18. Johannes SchindelinFeb 18, 2008

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.