git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 08/32] Add $GIT_DIR/narrow check
Date: Wed, 25 Aug 2010 08:19:58 +1000	[thread overview]
Message-ID: <1282688422-7738-9-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1282688422-7738-1-git-send-email-pclouds@gmail.com>

This file contains the narrow prefix. With get_narrow_prefix() being
non-empty behavior of git may be totally different.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 Makefile      |    2 ++
 cache.h       |    3 +++
 environment.c |    2 ++
 narrow-tree.c |   31 +++++++++++++++++++++++++++++++
 narrow-tree.h |    1 +
 5 files changed, 39 insertions(+), 0 deletions(-)
 create mode 100644 narrow-tree.c
 create mode 100644 narrow-tree.h

diff --git a/Makefile b/Makefile
index 1f11618..54c435e 100644
--- a/Makefile
+++ b/Makefile
@@ -525,6 +525,7 @@ LIB_H += sigchain.h
 LIB_H += strbuf.h
 LIB_H += string-list.h
 LIB_H += submodule.h
+LIB_H += narrow-tree.h
 LIB_H += tag.h
 LIB_H += transport.h
 LIB_H += tree.h
@@ -629,6 +630,7 @@ LIB_OBJS += sigchain.o
 LIB_OBJS += strbuf.o
 LIB_OBJS += string-list.o
 LIB_OBJS += submodule.o
+LIB_OBJS += narrow-tree.o
 LIB_OBJS += symlinks.o
 LIB_OBJS += tag.o
 LIB_OBJS += trace.o
diff --git a/cache.h b/cache.h
index 37ef9d8..ff401ec 100644
--- a/cache.h
+++ b/cache.h
@@ -1101,4 +1101,7 @@ int split_cmdline(char *cmdline, const char ***argv);
 /* builtin/merge.c */
 int checkout_fast_forward(const unsigned char *from, const unsigned char *to);
 
+/* narrow-tree.c */
+extern const char *get_narrow_prefix();
+
 #endif /* CACHE_H */
diff --git a/environment.c b/environment.c
index 83d38d3..41fcbd4 100644
--- a/environment.c
+++ b/environment.c
@@ -8,6 +8,7 @@
  * are.
  */
 #include "cache.h"
+#include "narrow-tree.h"
 
 char git_default_email[MAX_GITNAME];
 char git_default_name[MAX_GITNAME];
@@ -105,6 +106,7 @@ static void setup_git_env(void)
 		git_graft_file = git_pathdup("info/grafts");
 	if (getenv(NO_REPLACE_OBJECTS_ENVIRONMENT))
 		read_replace_refs = 0;
+	check_narrow_prefix();
 }
 
 int is_bare_repository(void)
diff --git a/narrow-tree.c b/narrow-tree.c
new file mode 100644
index 0000000..46e913d
--- /dev/null
+++ b/narrow-tree.c
@@ -0,0 +1,31 @@
+#include "cache.h"
+#include "narrow-tree.h"
+
+static const char *narrow_prefix;
+
+int check_narrow_prefix()
+{
+	int fd;
+	static char buf[PATH_MAX];
+	int ret;
+
+	fd = open(git_path("narrow"), O_RDONLY);
+	if (fd == -1)
+		return 0;
+
+	ret = read(fd, buf, PATH_MAX);
+	if (ret > 0) {
+		/* $GIT_DIR/narrow is not meant for manual editing, anyway.. */
+		while (ret && buf[ret-1] == '\n')
+			ret--;
+		buf[ret] = '\0';
+		narrow_prefix = buf;
+	}
+	close(fd);
+	return 0;
+}
+
+const char *get_narrow_prefix()
+{
+	return narrow_prefix;
+}
diff --git a/narrow-tree.h b/narrow-tree.h
new file mode 100644
index 0000000..aa8c94f
--- /dev/null
+++ b/narrow-tree.h
@@ -0,0 +1 @@
+extern int check_narrow_prefix();
-- 
1.7.1.rc1.69.g24c2f7

  parent reply	other threads:[~2010-08-24 22:22 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-24 22:19 [RFD PATCH 00/32] subtree clone v2 Nguyễn Thái Ngọc Duy
2010-08-24 22:19 ` [PATCH 01/32] add const to ce_write() Nguyễn Thái Ngọc Duy
2010-08-24 22:19 ` [PATCH 02/32] cache-tree: abstract out write_sha1_file from cache_tree_update() Nguyễn Thái Ngọc Duy
2010-08-24 22:41   ` Jonathan Nieder
2010-08-24 22:19 ` [PATCH 03/32] cache-tree: ignore CE_REMOVE entries in verify_cache() Nguyễn Thái Ngọc Duy
2010-08-24 23:15   ` Jonathan Nieder
2010-08-25  0:23     ` Nguyen Thai Ngoc Duy
2010-08-25  0:48       ` Jonathan Nieder
2010-08-24 22:19 ` [PATCH 04/32] move do_compress() from pack-objects.c to pack-write.c Nguyễn Thái Ngọc Duy
2010-08-24 23:25   ` Jonathan Nieder
2010-08-25  3:19     ` Nguyen Thai Ngoc Duy
2010-08-24 22:19 ` [PATCH 05/32] pack-write: add functions for creating simple packs Nguyễn Thái Ngọc Duy
2010-08-24 22:19 ` [PATCH 06/32] tree.c: Add {set,clear}_tree_marks Nguyễn Thái Ngọc Duy
2010-08-24 22:19 ` [PATCH 07/32] tree.c: find_subtree() to search for a tree Nguyễn Thái Ngọc Duy
2010-08-25  3:35   ` Elijah Newren
2010-08-25  3:43     ` Nguyen Thai Ngoc Duy
2010-08-25  5:35       ` Elijah Newren
2010-08-24 22:19 ` Nguyễn Thái Ngọc Duy [this message]
2010-08-24 22:19 ` [PATCH 09/32] index: make narrow index incompatible with older git Nguyễn Thái Ngọc Duy
2010-08-24 23:43   ` Jonathan Nieder
2010-08-25  0:25     ` Nguyen Thai Ngoc Duy
2010-08-24 22:20 ` [PATCH 10/32] rev-list: support traversing in narrow repository mode Nguyễn Thái Ngọc Duy
2010-08-25  4:11   ` Elijah Newren
2010-08-24 22:20 ` [PATCH 11/32] rev-list: support --narrow-tree Nguyễn Thái Ngọc Duy
2010-08-25  3:59   ` Elijah Newren
2010-08-25 22:11     ` Nguyen Thai Ngoc Duy
2010-08-24 22:20 ` [PATCH 12/32] pack-objects: " Nguyễn Thái Ngọc Duy
2010-08-24 22:20 ` [PATCH 13/32] upload-pack: support narrow-tree capability Nguyễn Thái Ngọc Duy
2010-08-24 22:20 ` [PATCH 14/32] fetch-pack: support --narrow-tree Nguyễn Thái Ngọc Duy
2010-08-24 22:20 ` [PATCH 15/32] unpack_trees: only unpack $GIT_DIR/narrow subtree in narrow repository Nguyễn Thái Ngọc Duy
2010-08-25  5:04   ` Elijah Newren
2010-08-25  5:38     ` Nguyen Thai Ngoc Duy
2010-08-24 22:20 ` [PATCH 16/32] cache-tree: only cache tree within narrow area Nguyễn Thái Ngọc Duy
2010-08-24 22:20 ` [PATCH 17/32] tree-diff: add narrow versions of diff_{root_,}tree_sha1 Nguyễn Thái Ngọc Duy
2010-08-24 22:20 ` [PATCH 18/32] log-tree: use narrow version of diff_tree_sha1 Nguyễn Thái Ngọc Duy
2010-08-24 22:20 ` [PATCH 19/32] clone: support --narrow option Nguyễn Thái Ngọc Duy
2010-08-24 22:20 ` [PATCH 20/32] narrow-tree: add join_narrow_tree to do tree fixup for commits Nguyễn Thái Ngọc Duy
2010-08-24 22:20 ` [PATCH 21/32] commit: add narrow's commit_tree version Nguyễn Thái Ngọc Duy
2010-08-24 22:20 ` [PATCH 22/32] commit: use commit_narrow_tree() to support narrow repo Nguyễn Thái Ngọc Duy
2010-08-24 22:20 ` [PATCH 23/32] commit-tree: require --narrow-base in " Nguyễn Thái Ngọc Duy
2010-08-24 22:20 ` [PATCH 24/32] merge: refuse to merge if narrow bases are different Nguyễn Thái Ngọc Duy
2010-08-24 22:20 ` [PATCH 25/32] merge: prepare commit properly in narrow mode Nguyễn Thái Ngọc Duy
2010-08-24 22:20 ` [PATCH 26/32] Add upload-narrow-base command Nguyễn Thái Ngọc Duy
2010-08-24 22:20 ` [PATCH 27/32] rev-list: traverse some more trees to make upload-narrow-base happy Nguyễn Thái Ngọc Duy
2010-08-24 22:20 ` [PATCH 28/32] narrow-tree: add oldest_narrow_base() Nguyễn Thái Ngọc Duy
2010-08-24 22:20 ` [PATCH 29/32] Add command fetch-narrow-base Nguyễn Thái Ngọc Duy
2010-08-24 22:20 ` [PATCH 30/32] merge: support merging when narrow bases are different Nguyễn Thái Ngọc Duy
2010-08-24 22:20 ` [PATCH 31/32] send-pack: do not use thin pack in narrow mode Nguyễn Thái Ngọc Duy
2010-08-24 22:20 ` [PATCH 32/32] daemon: support upload-narrow-base Nguyễn Thái Ngọc Duy
2010-08-24 22:37 ` [RFD PATCH 00/32] subtree clone v2 Jonathan Nieder
2010-08-24 22:47   ` Nguyen Thai Ngoc Duy
2010-08-24 23:09     ` Jonathan Nieder
2010-08-25  0:20       ` Nguyen Thai Ngoc Duy
2010-08-25  4:37     ` Elijah Newren
2010-08-25  5:21       ` Nguyen Thai Ngoc Duy
2010-08-25  5:31         ` Elijah Newren
2010-08-25  6:21           ` Nguyen Thai Ngoc Duy
2010-08-25 13:06             ` Elijah Newren
2010-08-25 22:13           ` Nguyen Thai Ngoc Duy
2010-08-26  2:50             ` Elijah Newren
2010-08-26  3:52               ` Nguyen Thai Ngoc Duy
2010-08-26  4:39                 ` Elijah Newren
2010-08-26  4:45                   ` Nguyen Thai Ngoc Duy
2010-08-25  5:21       ` Elijah Newren
2010-08-25 19:27       ` Junio C Hamano
2010-08-25 20:43         ` Elijah Newren

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

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

  git send-email \
    --in-reply-to=1282688422-7738-9-git-send-email-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=git@vger.kernel.org \
    /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.
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 NNTP newsgroup(s).