From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org, Elijah Newren <newren@gmail.com>
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 04/17] index: make narrow index incompatible with older git
Date: Sun, 5 Sep 2010 16:47:31 +1000 [thread overview]
Message-ID: <1283669264-15759-5-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1283669264-15759-1-git-send-email-pclouds@gmail.com>
Index in narrow repos is also narrowed and should not be used to
create commits straight away (to be explained later on). On the other
hand, while normal index can still be used in narrow repos, it should
be narrowed when the repo becomes narrow. Disallow that case too.
Add non-optional extension "narw" so that older git will refuse to
read it. Also check narrow prefix in index against $GIT_DIR/narrow,
just in case.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
cache.h | 1 +
read-cache.c | 32 ++++++++++++++++++++++++++++++--
t/t0063-narrow-repo.sh | 28 ++++++++++++++++++++++++++++
3 files changed, 59 insertions(+), 2 deletions(-)
diff --git a/cache.h b/cache.h
index d09c4fc..88a2ec6 100644
--- a/cache.h
+++ b/cache.h
@@ -292,6 +292,7 @@ struct index_state {
struct string_list *resolve_undo;
struct cache_tree *cache_tree;
struct cache_time timestamp;
+ char *narrow_prefix;
void *alloc;
unsigned name_hash_initialized : 1,
initialized : 1;
diff --git a/read-cache.c b/read-cache.c
index 1f42473..250013c 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -12,6 +12,7 @@
#include "commit.h"
#include "blob.h"
#include "resolve-undo.h"
+#include "narrow-tree.h"
static struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int really);
@@ -25,8 +26,9 @@ static struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int reall
*/
#define CACHE_EXT(s) ( (s[0]<<24)|(s[1]<<16)|(s[2]<<8)|(s[3]) )
-#define CACHE_EXT_TREE 0x54524545 /* "TREE" */
-#define CACHE_EXT_RESOLVE_UNDO 0x52455543 /* "REUC" */
+#define CACHE_EXT_TREE 0x54524545 /* "TREE" */
+#define CACHE_EXT_RESOLVE_UNDO 0x52455543 /* "REUC" */
+#define CACHE_EXT_NARROW 0x6e617277 /* "narw" */
struct index_state the_index;
@@ -1188,6 +1190,9 @@ static int read_index_extension(struct index_state *istate,
case CACHE_EXT_RESOLVE_UNDO:
istate->resolve_undo = resolve_undo_read(data, sz);
break;
+ case CACHE_EXT_NARROW:
+ istate->narrow_prefix = xstrdup(data);
+ break;
default:
if (*ext < 'A' || 'Z' < *ext)
return error("index uses %.4s extension, which we do not understand",
@@ -1352,6 +1357,18 @@ int read_index_from(struct index_state *istate, const char *path)
src_offset += extsize;
}
munmap(mmap, mmap_size);
+
+ if ((!get_narrow_prefix() && !istate->narrow_prefix))
+ ; /* good */
+ else if (get_narrow_prefix() && istate->narrow_prefix) {
+ char *buf = get_narrow_string();
+ if (strcmp(buf, istate->narrow_prefix))
+ die("Invalid index, narrow prefix does not match $GIT_DIR/narrow");
+ free(buf);
+ }
+ else
+ die("Invalid index, not suitable for narrow repository");
+
return istate->cache_nr;
unmap:
@@ -1378,6 +1395,8 @@ int discard_index(struct index_state *istate)
free(istate->alloc);
istate->alloc = NULL;
istate->initialized = 0;
+ free(istate->narrow_prefix);
+ istate->narrow_prefix = NULL;
/* no need to throw away allocated active_cache */
return 0;
@@ -1607,6 +1626,15 @@ int write_index(struct index_state *istate, int newfd)
if (err)
return -1;
}
+ if (get_narrow_prefix()) {
+ char *buf = get_narrow_string();
+ int len = strlen(buf)+1;
+ err = write_index_ext_header(&c, newfd, CACHE_EXT_NARROW, len) < 0 ||
+ ce_write(&c, newfd, buf, len) < 0;
+ free(buf);
+ if (err)
+ return -1;
+ }
if (ce_flush(&c, newfd) || fstat(newfd, &st))
return -1;
diff --git a/t/t0063-narrow-repo.sh b/t/t0063-narrow-repo.sh
index 51b753d..926802c 100755
--- a/t/t0063-narrow-repo.sh
+++ b/t/t0063-narrow-repo.sh
@@ -43,4 +43,32 @@ test_expect_success 'unsorted multiple prefix' '
test_must_fail git rev-parse --narrow-prefix
'
+test_expect_success 'create narrow index' '
+ echo a >.git/narrow &&
+ : >foo
+ git add foo &&
+ test -f .git/index
+'
+
+test_expect_success '$GIT_DIR/narrow and index do not match' '
+ echo b >.git/narrow &&
+ test_must_fail git add foo
+'
+
+test_expect_success 'narrow index and normal repo' '
+ rm .git/narrow &&
+ test_must_fail git add foo
+'
+
+test_expect_success 'turn to normal index again' '
+ rm .git/index &&
+ git add foo &&
+ test -f .git/index
+'
+
+test_expect_success 'normal index and narrow repo' '
+ echo a >.git/narrow &&
+ test_must_fail git add foo
+'
+
test_done
--
1.7.1.rc1.69.g24c2f7
next prev parent reply other threads:[~2010-09-05 6:49 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-05 6:47 [PATCH 00/17] Narrow clone v3 (was subtree clone) Nguyễn Thái Ngọc Duy
2010-09-05 6:47 ` [PATCH 01/17] rev-list: do not do commit simplification if simplify_history = 0 Nguyễn Thái Ngọc Duy
2010-09-05 6:47 ` [PATCH 02/17] tree.c: add path_to_sha1() Nguyễn Thái Ngọc Duy
2010-09-05 6:47 ` [PATCH 03/17] Introduce $GIT_DIR/narrow Nguyễn Thái Ngọc Duy
2010-09-05 6:47 ` Nguyễn Thái Ngọc Duy [this message]
2010-09-05 6:47 ` [PATCH 05/17] pack-objects: support narrow packs with pathspecs Nguyễn Thái Ngọc Duy
2010-09-05 6:47 ` [PATCH 06/17] {fetch,upload}-pack: support narrow repository Nguyễn Thái Ngọc Duy
2010-09-05 6:47 ` [PATCH 07/17] unpack-trees: split traverse_trees() code into a separate function Nguyễn Thái Ngọc Duy
2010-09-05 6:47 ` [PATCH 08/17] unpack-trees: support unpack trees in narrow repository Nguyễn Thái Ngọc Duy
2010-09-05 6:47 ` [PATCH 09/17] cache-tree: only cache tree within narrow area Nguyễn Thái Ngọc Duy
2010-09-05 6:47 ` [PATCH 10/17] get_pathspec(): support narrow pathspec rewriting Nguyễn Thái Ngọc Duy
2010-09-05 6:47 ` [PATCH 11/17] pathspec retrieval fix Nguyễn Thái Ngọc Duy
2010-09-05 6:47 ` [PATCH 12/17] clone: support --narrow option Nguyễn Thái Ngọc Duy
2010-09-05 6:47 ` [PATCH 13/17] commit: add narrow's commit_tree version Nguyễn Thái Ngọc Duy
2010-09-05 6:47 ` [PATCH 14/17] commit: use commit_narrow_tree() to support narrow repo Nguyễn Thái Ngọc Duy
2010-09-05 6:47 ` [PATCH 15/17] write-tree: requires --narrow-base in narrow repository Nguyễn Thái Ngọc Duy
2010-09-05 6:47 ` [PATCH 16/17] merge: try to do local merge if possible in narrow repo Nguyễn Thái Ngọc Duy
2010-09-05 6:47 ` [PATCH 17/17] Add narrow clone demonstration test Nguyễn Thái Ngọc Duy
2010-09-05 6:55 ` [PATCH 00/17] Narrow clone v3 (was subtree clone) Sverre Rabbelier
2010-09-05 7:13 ` Nguyen Thai Ngoc Duy
2010-09-05 21:05 ` Elijah Newren
2010-09-06 5:17 ` Elijah Newren
2010-09-06 5:24 ` Nguyen Thai Ngoc Duy
2010-09-06 20:29 ` Sverre Rabbelier
2010-09-06 20:40 ` 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=1283669264-15759-5-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
--cc=newren@gmail.com \
/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).