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 15/17] write-tree: requires --narrow-base in narrow repository
Date: Sun, 5 Sep 2010 16:47:42 +1000 [thread overview]
Message-ID: <1283669264-15759-16-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1283669264-15759-1-git-send-email-pclouds@gmail.com>
Without a base, a full tree cannot be generated, because the index
does not contain all trees.
--narrow-base is ignored if the repository is not a narrow one.
git-am is modified to "test" write-tree, which makes git-rebase works
in simple cases.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
builtin/write-tree.c | 25 +++++++++++++++++++++++++
git-am.sh | 2 +-
2 files changed, 26 insertions(+), 1 deletions(-)
diff --git a/builtin/write-tree.c b/builtin/write-tree.c
index b223af4..5da3cb3 100644
--- a/builtin/write-tree.c
+++ b/builtin/write-tree.c
@@ -8,6 +8,7 @@
#include "tree.h"
#include "cache-tree.h"
#include "parse-options.h"
+#include "narrow-tree.h"
static const char * const write_tree_usage[] = {
"git write-tree [--missing-ok] [--prefix=<prefix>/]",
@@ -18,6 +19,7 @@ int cmd_write_tree(int argc, const char **argv, const char *unused_prefix)
{
int flags = 0, ret;
const char *prefix = NULL;
+ const char *narrow_str = NULL;
unsigned char sha1[20];
const char *me = "git-write-tree";
struct option write_tree_options[] = {
@@ -26,6 +28,9 @@ int cmd_write_tree(int argc, const char **argv, const char *unused_prefix)
{ OPTION_STRING, 0, "prefix", &prefix, "<prefix>/",
"write tree object for a subdirectory <prefix>" ,
PARSE_OPT_LITERAL_ARGHELP },
+ { OPTION_STRING, 0, "narrow-base", &narrow_str, "base tree",
+ "base tree in narrow index" ,
+ PARSE_OPT_LITERAL_ARGHELP },
{ OPTION_BIT, 0, "ignore-cache-tree", &flags, NULL,
"only useful for debugging",
PARSE_OPT_HIDDEN | PARSE_OPT_NOARG, NULL,
@@ -40,6 +45,26 @@ int cmd_write_tree(int argc, const char **argv, const char *unused_prefix)
ret = write_cache_as_tree(sha1, flags, prefix);
switch (ret) {
case 0:
+ if (get_narrow_prefix()) {
+ unsigned char sha1_param[20];
+ unsigned char narrow_base[20];
+ unsigned char old_sha1[20];
+ unsigned long size;
+ void *buf;
+
+ if (!narrow_str)
+ die("write-tree in narrow repo requires --narrow-base");
+
+ if (get_sha1(narrow_str, sha1_param))
+ die("Invalid SHA1 %s", narrow_str);
+ buf = read_object_with_reference(sha1_param, tree_type, &size, narrow_base);
+ if (!buf)
+ die("Bad treeish %s", sha1_to_hex(sha1));
+ free(buf);
+ hashcpy(old_sha1, sha1);
+ if (join_narrow_tree(sha1, narrow_base, old_sha1, get_narrow_prefix()))
+ die("Failed to join tree");
+ }
printf("%s\n", sha1_to_hex(sha1));
break;
case WRITE_TREE_UNREADABLE_INDEX:
diff --git a/git-am.sh b/git-am.sh
index e7f008c..6adda43 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -783,7 +783,7 @@ do
"$GIT_DIR"/hooks/pre-applypatch || stop_here $this
fi
- tree=$(git write-tree) &&
+ tree=$(git write-tree --narrow-base=HEAD) &&
commit=$(
if test -n "$ignore_date"
then
--
1.7.1.rc1.69.g24c2f7
next prev parent reply other threads:[~2010-09-05 6:50 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 ` [PATCH 04/17] index: make narrow index incompatible with older git Nguyễn Thái Ngọc Duy
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 ` Nguyễn Thái Ngọc Duy [this message]
2010-09-05 6:47 ` [PATCH 16/17] merge: try to do local merge if possible in " 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-16-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).