git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Git Mailing List <git@vger.kernel.org>, Junio C Hamano <junkio@cox.net>
Subject: [PATCH 6/6] Teach core object handling functions about gitlinks
Date: Mon, 9 Apr 2007 21:20:29 -0700 (PDT)	[thread overview]
Message-ID: <Pine.LNX.4.64.0704092115350.6730@woody.linux-foundation.org> (raw)
In-Reply-To: <Pine.LNX.4.64.0704092100110.6730@woody.linux-foundation.org>


This teaches the really fundamental core SHA1 object handling routines
about gitlinks.  We can compare trees with gitlinks in them (although we
can not actually generate patches for them yet - just raw git diffs),
and they show up as commits in "git ls-tree".

We also know to compare gitlinks as if they were directories (ie the
normal "sort as trees" rules apply).

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
---

Ok, that's it for now.

NOTE NOTE NOTE! I'd like to note once more that this doesn't actually get 
you working subproject support. Not only do I need to connect up a few 
more low-level helper functions (things like "git diff" don't know how to 
generate even rudimentary "subproject X changed" patches, nor can you 
actually yet *add* subprojects), but quite apart from that low-level 
stuff, anything more high-level (like "git fetch" and friends) will need 
to know about subprojects.

In general, think of this like the early git plumbing: it's the early
"content-addressable filesystem" part. The actual SCM parts going on top 
of it are yet to be done.

I'm hoping/expecting that there are more people who have the ability and 
the interest to work on the higher-level interfaces once the core plumbing 
support is there. There's still some plumbing to be done, but after that, 
maybe more people (and maybe the SoC people) can start filling out the 
higher-level details..

Comments on the patches/approach so far?

 builtin-ls-tree.c |   20 +++++++++++++++++++-
 cache-tree.c      |    2 +-
 read-cache.c      |   35 +++++++++++++++++++++++++++++++----
 sha1_file.c       |    3 +++
 4 files changed, 54 insertions(+), 6 deletions(-)

diff --git a/builtin-ls-tree.c b/builtin-ls-tree.c
index 6472610..1cb4dca 100644
--- a/builtin-ls-tree.c
+++ b/builtin-ls-tree.c
@@ -6,6 +6,7 @@
 #include "cache.h"
 #include "blob.h"
 #include "tree.h"
+#include "commit.h"
 #include "quote.h"
 #include "builtin.h"
 
@@ -59,7 +60,24 @@ static int show_tree(const unsigned char *sha1, const char *base, int baselen,
 	int retval = 0;
 	const char *type = blob_type;
 
-	if (S_ISDIR(mode)) {
+	if (S_ISDIRLNK(mode)) {
+		/*
+		 * Maybe we want to have some recursive version here?
+		 *
+		 * Something like:
+		 *
+		if (show_subprojects(base, baselen, pathname)) {
+			if (fork()) {
+				chdir(base);
+				exec ls-tree;
+			}
+			waitpid();
+		}
+		 *
+		 * ..or similar..
+		 */
+		type = commit_type;
+	} else if (S_ISDIR(mode)) {
 		if (show_recursive(base, baselen, pathname)) {
 			retval = READ_TREE_RECURSIVE;
 			if (!(ls_options & LS_SHOW_TREES))
diff --git a/cache-tree.c b/cache-tree.c
index 9b73c86..6369cc7 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -326,7 +326,7 @@ static int update_one(struct cache_tree *it,
 			mode = ntohl(ce->ce_mode);
 			entlen = pathlen - baselen;
 		}
-		if (!missing_ok && !has_sha1_file(sha1))
+		if (mode != S_IFDIRLNK && !missing_ok && !has_sha1_file(sha1))
 			return error("invalid object %s", sha1_to_hex(sha1));
 
 		if (!ce->ce_mode)
diff --git a/read-cache.c b/read-cache.c
index 54573ce..8fe94cd 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -5,6 +5,7 @@
  */
 #include "cache.h"
 #include "cache-tree.h"
+#include "refs.h"
 
 /* Index extensions.
  *
@@ -91,6 +92,23 @@ static int ce_compare_link(struct cache_entry *ce, size_t expected_size)
 	return match;
 }
 
+static int ce_compare_gitlink(struct cache_entry *ce)
+{
+	unsigned char sha1[20];
+
+	/*
+	 * We don't actually require that the .git directory
+	 * under DIRLNK directory be a valid git directory. It
+	 * might even be missing (in case nobody populated that
+	 * sub-project).
+	 *
+	 * If so, we consider it always to match.
+	 */
+	if (resolve_gitlink_ref(ce->name, "HEAD", sha1) < 0)
+		return 0;
+	return hashcmp(sha1, ce->sha1);
+}
+
 static int ce_modified_check_fs(struct cache_entry *ce, struct stat *st)
 {
 	switch (st->st_mode & S_IFMT) {
@@ -102,6 +120,9 @@ static int ce_modified_check_fs(struct cache_entry *ce, struct stat *st)
 		if (ce_compare_link(ce, xsize_t(st->st_size)))
 			return DATA_CHANGED;
 		break;
+	case S_IFDIRLNK:
+		/* No need to do anything, we did the exact compare in "match_stat_basic" */
+		break;
 	default:
 		return TYPE_CHANGED;
 	}
@@ -127,6 +148,12 @@ static int ce_match_stat_basic(struct cache_entry *ce, struct stat *st)
 		    (has_symlinks || !S_ISREG(st->st_mode)))
 			changed |= TYPE_CHANGED;
 		break;
+	case S_IFDIRLNK:
+		if (!S_ISDIR(st->st_mode))
+			changed |= TYPE_CHANGED;
+		else if (ce_compare_gitlink(ce))
+			changed |= DATA_CHANGED;
+		break;
 	default:
 		die("internal error: ce_mode is %o", ntohl(ce->ce_mode));
 	}
@@ -250,9 +277,9 @@ int base_name_compare(const char *name1, int len1, int mode1,
 		return cmp;
 	c1 = name1[len];
 	c2 = name2[len];
-	if (!c1 && S_ISDIR(mode1))
+	if (!c1 && (S_ISDIR(mode1) || S_ISDIRLNK(mode1)))
 		c1 = '/';
-	if (!c2 && S_ISDIR(mode2))
+	if (!c2 && (S_ISDIR(mode2) || S_ISDIRLNK(mode1)))
 		c2 = '/';
 	return (c1 < c2) ? -1 : (c1 > c2) ? 1 : 0;
 }
@@ -334,8 +361,8 @@ int add_file_to_cache(const char *path, int verbose)
 	if (lstat(path, &st))
 		die("%s: unable to stat (%s)", path, strerror(errno));
 
-	if (!S_ISREG(st.st_mode) && !S_ISLNK(st.st_mode))
-		die("%s: can only add regular files or symbolic links", path);
+	if (!S_ISREG(st.st_mode) && !S_ISLNK(st.st_mode) && !S_ISDIR(st.st_mode))
+		die("%s: can only add regular files, symbolic links or git-directories", path);
 
 	namelen = strlen(path);
 	size = cache_entry_size(namelen);
diff --git a/sha1_file.c b/sha1_file.c
index 4304fe9..ab915fa 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -13,6 +13,7 @@
 #include "commit.h"
 #include "tag.h"
 #include "tree.h"
+#include "refs.h"
 
 #ifndef O_NOATIME
 #if defined(__linux__) && (defined(__i386__) || defined(__PPC__))
@@ -2332,6 +2333,8 @@ int index_path(unsigned char *sha1, const char *path, struct stat *st, int write
 				     path);
 		free(target);
 		break;
+	case S_IFDIR:
+		return resolve_gitlink_ref(path, "HEAD", sha1);
 	default:
 		return error("%s: unsupported file type", path);
 	}
-- 
1.5.1.110.g1e4c

  parent reply	other threads:[~2007-04-10  4:20 UTC|newest]

Thread overview: 101+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-04-10  4:12 [PATCH 0/6] Initial subproject support (RFC?) Linus Torvalds
     [not found] ` <Pi ne.LNX.4.64.0704092115020.6730@woody.linux-foundation.org>
2007-04-10  4:13 ` [PATCH 1/6] diff-lib: use ce_mode_from_stat() rather than messing with modes manually Linus Torvalds
2007-04-10  4:13 ` [PATCH 2/6] Avoid overflowing name buffer in deep directory structures Linus Torvalds
2007-04-10  4:14 ` [PATCH 3/6] Add 'resolve_gitlink_ref()' helper function Linus Torvalds
2007-04-10  9:38   ` Alex Riesen
2007-04-10 14:58     ` Linus Torvalds
2007-04-10 15:35       ` Alex Riesen
2007-04-10 15:52         ` Linus Torvalds
2007-04-10 15:57           ` Alex Riesen
2007-04-10 16:16             ` Linus Torvalds
2007-04-10 15:54       ` Josef Weidendorfer
2007-04-10  4:14 ` [PATCH 4/6] Add "S_IFDIRLNK" file mode infrastructure for git links Linus Torvalds
2007-04-10  4:15 ` [PATCH 5/6] Teach "fsck" not to follow subproject links Linus Torvalds
2007-04-11 22:41   ` Sam Vilain
2007-04-11 22:48     ` Linus Torvalds
2007-04-11 22:59       ` Sam Vilain
2007-04-11 23:16         ` Linus Torvalds
2007-04-11 23:05           ` David Lang
2007-04-11 23:53             ` Linus Torvalds
2007-04-11 23:30               ` David Lang
2007-04-12  2:14                 ` Linus Torvalds
2007-04-12  2:30                   ` Junio C Hamano
2007-04-12 17:18                   ` David Lang
2007-04-12 18:32                   ` Dana How
2007-04-12 19:17                     ` Linus Torvalds
2007-04-13  9:00                       ` Rogan Dawes
2007-04-13 15:23                         ` Linus Torvalds
2007-04-15  6:50                       ` Dana How
2007-04-12  0:00               ` Dana How
2007-04-12  0:03               ` Sam Vilain
2007-04-12  0:34           ` Junio C Hamano
2007-04-12  1:52             ` Linus Torvalds
2007-04-12  2:00               ` Junio C Hamano
2007-04-12  2:06                 ` Junio C Hamano
2007-04-12  2:28                   ` Linus Torvalds
2007-04-11 23:30         ` Dana How
2007-04-10  4:20 ` Linus Torvalds [this message]
2007-04-10  8:40   ` [PATCH 6/6] Teach core object handling functions about gitlinks Frank Lichtenheld
2007-04-10 11:31     ` Alex Riesen
2007-04-10 14:55     ` Linus Torvalds
2007-04-10 16:28   ` Josef Weidendorfer
2007-04-10 16:50     ` Alex Riesen
2007-04-10 17:23       ` Josef Weidendorfer
2007-04-10 18:45     ` Linus Torvalds
2007-04-10 19:04       ` Andy Parkins
2007-04-10 19:20         ` Linus Torvalds
2007-04-10 20:19           ` Junio C Hamano
2007-04-10 20:33             ` Linus Torvalds
2007-04-12  0:12               ` Sam Vilain
2007-04-12  0:35                 ` Martin Waitz
2007-04-12  2:01                 ` Linus Torvalds
2007-04-12  3:56                   ` Sam Vilain
2007-04-10 19:41         ` David Lang
2007-04-10 20:06         ` Junio C Hamano
2007-04-10 19:29       ` Josef Weidendorfer
2007-04-10 19:45         ` Linus Torvalds
2007-04-11 23:47           ` Sam Vilain
2007-04-12  0:13             ` Linus Torvalds
2007-04-12  0:42       ` Torgil Svensson
2007-04-12  0:56         ` Martin Waitz
2007-04-12 21:23           ` Torgil Svensson
2007-04-11 23:36     ` Sam Vilain
2007-04-11  8:06   ` Martin Waitz
2007-04-11  8:29     ` Alex Riesen
2007-04-11  8:36       ` Martin Waitz
2007-04-11  8:49         ` Alex Riesen
2007-04-11  9:20           ` Martin Waitz
2007-04-11  9:15         ` Junio C Hamano
2007-04-11 10:03           ` Martin Waitz
2007-04-11 20:01             ` Junio C Hamano
2007-04-11 22:19               ` Martin Waitz
2007-04-11 22:36                 ` Linus Torvalds
2007-04-11  9:47     ` Andy Parkins
2007-04-11 11:31       ` Martin Waitz
2007-04-11 15:16     ` Linus Torvalds
2007-04-11 22:49       ` Sam Vilain
2007-04-11 23:54       ` Martin Waitz
2007-04-12  1:57         ` Brian Gernhardt
2007-04-12 15:12         ` Josef Weidendorfer
2007-04-10  4:46 ` [PATCH 0/6] Initial subproject support (RFC?) Linus Torvalds
2007-04-10 13:04   ` Alex Riesen
2007-04-10 15:13     ` Linus Torvalds
2007-04-10 15:48       ` Alex Riesen
2007-04-10 16:07         ` Linus Torvalds
2007-04-10 16:43           ` Alex Riesen
2007-04-10 19:32           ` Junio C Hamano
2007-04-10 20:11             ` Linus Torvalds
2007-04-10 20:52               ` Junio C Hamano
2007-04-10 21:02                 ` Sam Ravnborg
2007-04-10 21:27                   ` Junio C Hamano
2007-04-10 21:03                 ` Nicolas Pitre
2007-04-15 23:21                   ` J. Bruce Fields
2007-04-11  8:08                 ` David Kågedal
2007-04-11  9:32                   ` Junio C Hamano
2007-04-15 23:25                     ` J. Bruce Fields
2007-04-11  8:32     ` Martin Waitz
2007-04-11  8:42       ` Alex Riesen
2007-04-11  8:57         ` Martin Waitz
2007-04-10 13:39   ` [PATCH] allow git-update-index work on subprojects Alex Riesen
2007-04-10 23:19     ` [PATCH] Allow " Alex Riesen
2007-04-11  2:55       ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.64.0704092115350.6730@woody.linux-foundation.org \
    --to=torvalds@linux-foundation.org \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).