* Re: [PATCH] Allow cloning an empty repository
From: Junio C Hamano @ 2009-01-23 1:24 UTC (permalink / raw)
To: Sverre Rabbelier; +Cc: git
In-Reply-To: <1232669252-21881-1-git-send-email-srabbelier@gmail.com>
Sverre Rabbelier <srabbelier@gmail.com> writes:
> diff --git a/builtin-clone.c b/builtin-clone.c
> index f7e5a7b..d5bba0e 100644
> --- a/builtin-clone.c
> +++ b/builtin-clone.c
> @@ -522,14 +522,23 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
> option_upload_pack);
>
> refs = transport_get_remote_refs(transport);
> - transport_fetch_refs(transport, refs);
> + if(refs)
> + transport_fetch_refs(transport, refs);
Thanks.
I think the basic idea is Ok, but is it a reliable check at this point to
see if (refs == NULL) to tell if the target repository is an empty one?
I am mostly worried about a failure case (connected but couldn't get the
refs, or perhaps connection failed to start). If you get a NULL in such a
case you may end up saying "oh you cloned a void" when you should say
"nah, such a remote repository does not exist".
If transport_get_remote_refs() dies without returning NULL, that would be
sufficient, but I didn't check.
^ permalink raw reply
* Re: [PATCH 3/3] Add --contains flag to git tag
From: Junio C Hamano @ 2009-01-23 1:18 UTC (permalink / raw)
To: Jake Goulding; +Cc: git
In-Reply-To: <497913EE.9040608@vivisimo.com>
Jake Goulding <goulding@vivisimo.com> writes:
> @@ -34,7 +35,6 @@ static int show_reference(const char *refname, const
> unsigned char *sha1,
> int flag, void *cb_data)
> {
> struct tag_filter *filter = cb_data;
> -
> if (!fnmatch(filter->pattern, refname, 0)) {
> int i;
> unsigned long size;
Here you can see a long line wrapped.
What does this hunk have to do with adding --contains option anyway?
> @@ -42,6 +42,18 @@ static int show_reference(const char *refname, const
> unsigned char *sha1,
> char *buf, *sp, *eol;
> size_t len;
>
> + if (filter->with_commit) {
> + struct commit *commit;
> +
> + commit = lookup_commit_reference_gently(sha1, 1);
> + if (!commit) {
> + error("tag '%s' does not point at a commit", refname);
> + return 0;
Drop this error() call, and just return silently. A tag that does not
point at a commit is not an error at all.
^ permalink raw reply
* Re: [PATCH 2/3] Make has_commit non-static
From: Junio C Hamano @ 2009-01-23 1:13 UTC (permalink / raw)
To: Jake Goulding; +Cc: git
In-Reply-To: <497913E4.6050806@vivisimo.com>
Jake Goulding <goulding@vivisimo.com> writes:
> Moving has_commit from branch to a common location in preparation for
> using it in tag.
has_commit() may have been a good enough name when it was a static in
builtin-branch.c but with much wider visibility, it is not specific
enough.
Perhaps you would want to rename it to something more descriptive.
Also it seems that your patch is garbled and won't apply. A blank
context line lost the leading (and only) SP, and long lines are wrapped.
> Signed-off-by: Jake Goulding <goulding@vivisimo.com>
> ---
> builtin-branch.c | 15 ---------------
> commit.c | 15 +++++++++++++++
> commit.h | 1 +
> 3 files changed, 16 insertions(+), 15 deletions(-)
>
> diff --git a/builtin-branch.c b/builtin-branch.c
> index 82d6fb2..bb42911 100644
> --- a/builtin-branch.c
> +++ b/builtin-branch.c
> @@ -193,21 +193,6 @@ struct ref_list {
> int kinds;
> };
>
> -static int has_commit(struct commit *commit, struct commit_list
> *with_commit)
> -{
> - if (!with_commit)
> - return 1;
> - while (with_commit) {
> - struct commit *other;
> -
> - other = with_commit->item;
> - with_commit = with_commit->next;
> - if (in_merge_bases(other, &commit, 1))
> - return 1;
> - }
> - return 0;
> -}
> -
> static int append_ref(const char *refname, const unsigned char *sha1,
> int flags, void *cb_data)
> {
> struct ref_list *ref_list = (struct ref_list*)(cb_data);
> diff --git a/commit.c b/commit.c
> index c99db16..5ccb338 100644
> --- a/commit.c
> +++ b/commit.c
> @@ -705,6 +705,21 @@ struct commit_list *get_merge_bases(struct commit
> *one, struct commit *two,
> return get_merge_bases_many(one, 1, &two, cleanup);
> }
>
> +int has_commit(struct commit *commit, struct commit_list *with_commit)
> +{
> + if (!with_commit)
> + return 1;
> + while (with_commit) {
> + struct commit *other;
> +
> + other = with_commit->item;
> + with_commit = with_commit->next;
> + if (in_merge_bases(other, &commit, 1))
> + return 1;
> + }
> + return 0;
> +}
> +
> int in_merge_bases(struct commit *commit, struct commit **reference,
> int num)
> {
> struct commit_list *bases, *b;
> diff --git a/commit.h b/commit.h
> index 3a7b06a..1b8444f 100644
> --- a/commit.h
> +++ b/commit.h
> @@ -133,6 +133,7 @@ extern int is_repository_shallow(void);
> extern struct commit_list *get_shallow_commits(struct object_array *heads,
> int depth, int shallow_flag, int not_shallow_flag);
>
> +int has_commit(struct commit *, struct commit_list *);
> int in_merge_bases(struct commit *, struct commit **, int);
>
> extern int interactive_add(int argc, const char **argv, const char
> *prefix);
> --
> 1.6.0.4
^ permalink raw reply
* [PATCH] Allow cloning an empty repository
From: Sverre Rabbelier @ 2009-01-23 0:07 UTC (permalink / raw)
To: git; +Cc: Sverre Rabbelier
Cloning an empty repository manually (that is, doing 'git init' and
then doing all configuration by hand) can be a lot of work. Save the
user this work by allowing the cloning of empty repositories.
Signed-off-by: Sverre Rabbelier <srabbelier@gmail.com>
---
Thanks to Dscho for giving some pointers on how to do this.
builtin-clone.c | 17 +++++++++++++----
t/t5701-clone-local.sh | 16 ++++++++++++++++
2 files changed, 29 insertions(+), 4 deletions(-)
diff --git a/builtin-clone.c b/builtin-clone.c
index f7e5a7b..d5bba0e 100644
--- a/builtin-clone.c
+++ b/builtin-clone.c
@@ -522,14 +522,23 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
option_upload_pack);
refs = transport_get_remote_refs(transport);
- transport_fetch_refs(transport, refs);
+ if(refs)
+ transport_fetch_refs(transport, refs);
}
- clear_extra_refs();
+ if(refs) {
+ clear_extra_refs();
- mapped_refs = write_remote_refs(refs, &refspec, reflog_msg.buf);
+ mapped_refs = write_remote_refs(refs, &refspec, reflog_msg.buf);
- head_points_at = locate_head(refs, mapped_refs, &remote_head);
+ head_points_at = locate_head(refs, mapped_refs, &remote_head);
+ }
+ else {
+ warning("You appear to have cloned an empty repository.");
+ head_points_at = NULL;
+ remote_head = NULL;
+ option_no_checkout = 1;
+ }
if (head_points_at) {
/* Local default branch link */
diff --git a/t/t5701-clone-local.sh b/t/t5701-clone-local.sh
index 8dfaaa4..fbd9bfa 100755
--- a/t/t5701-clone-local.sh
+++ b/t/t5701-clone-local.sh
@@ -116,4 +116,20 @@ test_expect_success 'bundle clone with nonexistent HEAD' '
test ! -e .git/refs/heads/master
'
+test_expect_success 'clone empty repository' '
+ cd "$D" &&
+ mkdir empty &&
+ (cd empty && git init) &&
+ git clone empty empty-clone &&
+ test_tick &&
+ (cd empty-clone
+ echo "content" >> foo &&
+ git add foo &&
+ git commit -m "Initial commit" &&
+ git push origin master &&
+ expected=$(git rev-parse master) &&
+ actual=$(git --git-dir=../empty/.git rev-parse master) &&
+ test $actual = $expected)
+'
+
test_done
--
1.6.1.399.g0d272.dirty
^ permalink raw reply related
* [PATCH 3/3] Add --contains flag to git tag
From: Jake Goulding @ 2009-01-23 0:48 UTC (permalink / raw)
To: git
In-Reply-To: <1232671630-19683-2-git-send-email-goulding@vivisimo.com>
This functions similar to git branch --contains - it will show all
tags that contain the specified commit. Indeed, it uses the same
lookup mechanisms as git branch.
Also adding documentation and tests for new option.
Signed-off-by: Jake Goulding <goulding@vivisimo.com>
---
Reworked with feedback from the list.
Moved commit testing inside of the regex match, instead of before.
Moved test cases into existing test.
Squashed code / doc / test into one commit.
Documentation/git-tag.txt | 5 ++-
builtin-tag.c | 32 +++++++++++-
t/t7004-tag.sh | 115
+++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 148 insertions(+), 4 deletions(-)
diff --git a/Documentation/git-tag.txt b/Documentation/git-tag.txt
index e44f543..533d18b 100644
--- a/Documentation/git-tag.txt
+++ b/Documentation/git-tag.txt
@@ -12,7 +12,7 @@ SYNOPSIS
'git tag' [-a | -s | -u <key-id>] [-f] [-m <msg> | -F <file>]
<name> [<commit> | <object>]
'git tag' -d <name>...
-'git tag' [-n[<num>]] -l [<pattern>]
+'git tag' [-n[<num>]] -l [--contains <commit>] [<pattern>]
'git tag' -v <name>...
DESCRIPTION
@@ -68,6 +68,9 @@ OPTIONS
List tags with names that match the given pattern (or all if no
pattern is given).
Typing "git tag" without arguments, also lists all tags.
+--contains <commit>::
+ Only list tags which contain the specified commit.
+
-m <msg>::
Use the given tag message (instead of prompting).
If multiple `-m` options are given, their values are
diff --git a/builtin-tag.c b/builtin-tag.c
index a398499..33424c0 100644
--- a/builtin-tag.c
+++ b/builtin-tag.c
@@ -26,6 +26,7 @@ static char signingkey[1000];
struct tag_filter {
const char *pattern;
int lines;
+ struct commit_list *with_commit;
};
#define PGP_SIGNATURE "-----BEGIN PGP SIGNATURE-----"
@@ -34,7 +35,6 @@ static int show_reference(const char *refname, const
unsigned char *sha1,
int flag, void *cb_data)
{
struct tag_filter *filter = cb_data;
-
if (!fnmatch(filter->pattern, refname, 0)) {
int i;
unsigned long size;
@@ -42,6 +42,18 @@ static int show_reference(const char *refname, const
unsigned char *sha1,
char *buf, *sp, *eol;
size_t len;
+ if (filter->with_commit) {
+ struct commit *commit;
+
+ commit = lookup_commit_reference_gently(sha1, 1);
+ if (!commit) {
+ error("tag '%s' does not point at a commit", refname);
+ return 0;
+ }
+ if (!has_commit(commit, filter->with_commit))
+ return 0;
+ }
+
if (!filter->lines) {
printf("%s\n", refname);
return 0;
@@ -79,7 +91,8 @@ static int show_reference(const char *refname, const
unsigned char *sha1,
return 0;
}
-static int list_tags(const char *pattern, int lines)
+static int list_tags(const char *pattern, int lines,
+ struct commit_list *with_commit)
{
struct tag_filter filter;
@@ -88,6 +101,7 @@ static int list_tags(const char *pattern, int lines)
filter.pattern = pattern;
filter.lines = lines;
+ filter.with_commit = with_commit;
for_each_tag_ref(show_reference, (void *) &filter);
@@ -360,6 +374,7 @@ int cmd_tag(int argc, const char **argv, const char
*prefix)
list = 0, delete = 0, verify = 0;
const char *msgfile = NULL, *keyid = NULL;
struct msg_arg msg = { 0, STRBUF_INIT };
+ struct commit_list *with_commit = NULL;
struct option options[] = {
OPT_BOOLEAN('l', NULL, &list, "list tag names"),
{ OPTION_INTEGER, 'n', NULL, &lines, NULL,
@@ -378,6 +393,14 @@ int cmd_tag(int argc, const char **argv, const char
*prefix)
OPT_STRING('u', NULL, &keyid, "key-id",
"use another key to sign the tag"),
OPT_BOOLEAN('f', NULL, &force, "replace the tag if exists"),
+
+ OPT_GROUP("Tag listing options"),
+ {
+ OPTION_CALLBACK, 0, "contains", &with_commit, "commit",
+ "print only tags that contain the commit",
+ PARSE_OPT_LASTARG_DEFAULT,
+ parse_opt_with_commit, (intptr_t)"HEAD",
+ },
OPT_END()
};
@@ -402,9 +425,12 @@ int cmd_tag(int argc, const char **argv, const char
*prefix)
if (list + delete + verify > 1)
usage_with_options(git_tag_usage, options);
if (list)
- return list_tags(argv[0], lines == -1 ? 0 : lines);
+ return list_tags(argv[0], lines == -1 ? 0 : lines,
+ with_commit);
if (lines != -1)
die("-n option is only allowed with -l.");
+ if (with_commit)
+ die("--contains option is only allowed with -l.");
if (delete)
return for_each_tag_name(argv, delete_tag);
if (verify)
diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh
index f377fea..69501e2 100755
--- a/t/t7004-tag.sh
+++ b/t/t7004-tag.sh
@@ -1090,6 +1090,121 @@ test_expect_success 'filename for the message is
relative to cwd' '
git cat-file tag tag-from-subdir-2 | grep "in sub directory"
'
+# create a few more commits to test --contains
+
+hash1=$(git rev-parse HEAD)
+
+test_expect_success 'creating second commit and tag' '
+ echo foo-2.0 >foo &&
+ git add foo &&
+ git commit -m second
+ git tag v2.0
+'
+
+hash2=$(git rev-parse HEAD)
+
+test_expect_success 'creating third commit without tag' '
+ echo foo-dev >foo &&
+ git add foo &&
+ git commit -m third
+'
+
+hash3=$(git rev-parse HEAD)
+
+# simple linear checks of --continue
+
+cat > expected <<EOF
+v0.2.1
+v1.0
+v1.0.1
+v1.1.3
+v2.0
+EOF
+
+test_expect_success 'checking that first commit is in all tags (hash)' "
+ git tag -l --contains $hash1 v* >actual
+ test_cmp expected actual
+"
+
+# other ways of specifying the commit
+test_expect_success 'checking that first commit is in all tags (tag)' "
+ git tag -l --contains v1.0 v* >actual
+ test_cmp expected actual
+"
+
+test_expect_success 'checking that first commit is in all tags
(relative)' "
+ git tag -l --contains HEAD~2 v* >actual
+ test_cmp expected actual
+"
+
+cat > expected <<EOF
+v2.0
+EOF
+
+test_expect_success 'checking that second commit only has one tag' "
+ git tag -l --contains $hash2 v* >actual
+ test_cmp expected actual
+"
+
+
+cat > expected <<EOF
+EOF
+
+test_expect_success 'checking that third commit has no tags' "
+ git tag -l --contains $hash3 v* >actual
+ test_cmp expected actual
+"
+
+# how about a simple merge?
+
+test_expect_success 'creating simple branch' '
+ git branch stable v2.0 &&
+ git checkout stable &&
+ echo foo-3.0 > foo &&
+ git commit foo -m fourth
+ git tag v3.0
+'
+
+hash4=$(git rev-parse HEAD)
+
+cat > expected <<EOF
+v3.0
+EOF
+
+test_expect_success 'checking that branch head only has one tag' "
+ git tag -l --contains $hash4 v* >actual
+ test_cmp expected actual
+"
+
+test_expect_success 'merging original branch into this branch' '
+ git merge --strategy=ours master &&
+ git tag v4.0
+'
+
+cat > expected <<EOF
+v4.0
+EOF
+
+test_expect_success 'checking that original branch head has one tag now' "
+ git tag -l --contains $hash3 v* >actual
+ test_cmp expected actual
+"
+
+cat > expected <<EOF
+v0.2.1
+v1.0
+v1.0.1
+v1.1.3
+v2.0
+v3.0
+v4.0
+EOF
+
+test_expect_success 'checking that initial commit is in all tags' "
+ git tag -l --contains $hash1 v* >actual
+ test_cmp expected actual
+"
+
# mixing modes and options:
test_expect_success 'mixing incompatibles modes and options is forbidden' '
--
1.6.0.4
^ permalink raw reply related
* [PATCH 2/3] Make has_commit non-static
From: Jake Goulding @ 2009-01-23 0:48 UTC (permalink / raw)
To: git
In-Reply-To: <1232671630-19683-1-git-send-email-goulding@vivisimo.com>
Moving has_commit from branch to a common location in preparation for
using it in tag.
Signed-off-by: Jake Goulding <goulding@vivisimo.com>
---
builtin-branch.c | 15 ---------------
commit.c | 15 +++++++++++++++
commit.h | 1 +
3 files changed, 16 insertions(+), 15 deletions(-)
diff --git a/builtin-branch.c b/builtin-branch.c
index 82d6fb2..bb42911 100644
--- a/builtin-branch.c
+++ b/builtin-branch.c
@@ -193,21 +193,6 @@ struct ref_list {
int kinds;
};
-static int has_commit(struct commit *commit, struct commit_list
*with_commit)
-{
- if (!with_commit)
- return 1;
- while (with_commit) {
- struct commit *other;
-
- other = with_commit->item;
- with_commit = with_commit->next;
- if (in_merge_bases(other, &commit, 1))
- return 1;
- }
- return 0;
-}
-
static int append_ref(const char *refname, const unsigned char *sha1,
int flags, void *cb_data)
{
struct ref_list *ref_list = (struct ref_list*)(cb_data);
diff --git a/commit.c b/commit.c
index c99db16..5ccb338 100644
--- a/commit.c
+++ b/commit.c
@@ -705,6 +705,21 @@ struct commit_list *get_merge_bases(struct commit
*one, struct commit *two,
return get_merge_bases_many(one, 1, &two, cleanup);
}
+int has_commit(struct commit *commit, struct commit_list *with_commit)
+{
+ if (!with_commit)
+ return 1;
+ while (with_commit) {
+ struct commit *other;
+
+ other = with_commit->item;
+ with_commit = with_commit->next;
+ if (in_merge_bases(other, &commit, 1))
+ return 1;
+ }
+ return 0;
+}
+
int in_merge_bases(struct commit *commit, struct commit **reference,
int num)
{
struct commit_list *bases, *b;
diff --git a/commit.h b/commit.h
index 3a7b06a..1b8444f 100644
--- a/commit.h
+++ b/commit.h
@@ -133,6 +133,7 @@ extern int is_repository_shallow(void);
extern struct commit_list *get_shallow_commits(struct object_array *heads,
int depth, int shallow_flag, int not_shallow_flag);
+int has_commit(struct commit *, struct commit_list *);
int in_merge_bases(struct commit *, struct commit **, int);
extern int interactive_add(int argc, const char **argv, const char
*prefix);
--
1.6.0.4
^ permalink raw reply related
* [PATCH 1/3] Make opt_parse_with_commit non-static
From: Jake Goulding @ 2009-01-23 0:48 UTC (permalink / raw)
To: git
Moving opt_parse_with_commit from branch to a common location in
preparation for using it in tag. Renamed it to correspond to naming
convention of other option parsing functions.
Signed-off-by: Jake Goulding <goulding@vivisimo.com>
---
builtin-branch.c | 20 ++------------------
parse-options.c | 17 +++++++++++++++++
parse-options.h | 1 +
3 files changed, 20 insertions(+), 18 deletions(-)
diff --git a/builtin-branch.c b/builtin-branch.c
index 02fa38f..82d6fb2 100644
--- a/builtin-branch.c
+++ b/builtin-branch.c
@@ -466,22 +466,6 @@ static void rename_branch(const char *oldname,
const char *newname, int force)
strbuf_release(&newsection);
}
-static int opt_parse_with_commit(const struct option *opt, const char
*arg, int unset)
-{
- unsigned char sha1[20];
- struct commit *commit;
-
- if (!arg)
- return -1;
- if (get_sha1(arg, sha1))
- die("malformed object name %s", arg);
- commit = lookup_commit_reference(sha1);
- if (!commit)
- die("no such commit %s", arg);
- commit_list_insert(commit, opt->value);
- return 0;
-}
-
static int opt_parse_merge_filter(const struct option *opt, const char
*arg, int unset)
{
merge_filter = ((opt->long_name[0] == 'n')
@@ -517,13 +501,13 @@ int cmd_branch(int argc, const char **argv, const
char *prefix)
OPTION_CALLBACK, 0, "contains", &with_commit, "commit",
"print only branches that contain the commit",
PARSE_OPT_LASTARG_DEFAULT,
- opt_parse_with_commit, (intptr_t)"HEAD",
+ parse_opt_with_commit, (intptr_t)"HEAD",
},
{
OPTION_CALLBACK, 0, "with", &with_commit, "commit",
"print only branches that contain the commit",
PARSE_OPT_HIDDEN | PARSE_OPT_LASTARG_DEFAULT,
- opt_parse_with_commit, (intptr_t) "HEAD",
+ parse_opt_with_commit, (intptr_t) "HEAD",
},
OPT__ABBREV(&abbrev),
diff --git a/parse-options.c b/parse-options.c
index 9eb55cc..4c5d09d 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -1,6 +1,7 @@
#include "git-compat-util.h"
#include "parse-options.h"
#include "cache.h"
+#include "commit.h"
#define OPT_SHORT 1
#define OPT_UNSET 2
@@ -506,6 +507,22 @@ int parse_opt_verbosity_cb(const struct option
*opt, const char *arg,
return 0;
}
+int parse_opt_with_commit(const struct option *opt, const char *arg,
int unset)
+{
+ unsigned char sha1[20];
+ struct commit *commit;
+
+ if (!arg)
+ return -1;
+ if (get_sha1(arg, sha1))
+ return error("malformed object name %s", arg);
+ commit = lookup_commit_reference(sha1);
+ if (!commit)
+ return error("no such commit %s", arg);
+ commit_list_insert(commit, opt->value);
+ return 0;
+}
+
/*
* This should really be OPTION_FILENAME type as a part of
* parse_options that take prefix to do this while parsing.
diff --git a/parse-options.h b/parse-options.h
index 034162e..9122905 100644
--- a/parse-options.h
+++ b/parse-options.h
@@ -151,6 +151,7 @@ extern int parse_options_end(struct parse_opt_ctx_t
*ctx);
extern int parse_opt_abbrev_cb(const struct option *, const char *, int);
extern int parse_opt_approxidate_cb(const struct option *, const char
*, int);
extern int parse_opt_verbosity_cb(const struct option *, const char *,
int);
+extern int parse_opt_with_commit(const struct option *, const char *, int);
#define OPT__VERBOSE(var) OPT_BOOLEAN('v', "verbose", (var), "be verbose")
#define OPT__QUIET(var) OPT_BOOLEAN('q', "quiet", (var), "be quiet")
--
1.6.0.4
^ permalink raw reply related
* Re: how to force a commit date matching info from a mbox ?
From: Nanako Shiraishi @ 2009-01-23 0:45 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git list, Christian MICHON
In-Reply-To: <7vljt26fp9.fsf@gitster.siamese.dyndns.org>
Quoting Junio C Hamano <gitster@pobox.com>:
> Christian MICHON <christian.michon@gmail.com> writes:
>
>> I'd like to force the commit date to match the info/date from the time
>> I received the email (and therefore always get back the right
>> sha1sums).
>>
>> is this possible ?
>
> "am" being a tool to accept patches written in some past to faithfully
> record both author timestamp and committer timestamp, what you seem to
> want is outside of the current scope of the tool.
>
> A patch to butcher "git-am" to copy GIT_COMMITTER_DATE from
> GIT_AUTHOR_DATE and export it should be trivial to implement, though.
>
> Perhaps something like this totally untested patch.
You have test scripts already, but you say it is untested?
I often wanted to have an opposite of what Christian wants. I always have some changes I am holding off, and when I decide to trickle them out to the main repository, I do not want the resulting commit to carry old dates that are recorded in the format-patch output. Instead I want to pretend that I worked on them today. Is this something you can teach git-am and git-rebase to do easily?
--
Nanako Shiraishi
http://ivory.ap.teacup.com/nanako3/
^ permalink raw reply
* Re: Short "git commit $file" syntax fails in the face of a resolved conflict
From: Nanako Shiraishi @ 2009-01-23 0:45 UTC (permalink / raw)
To: Johannes Sixt; +Cc: Nathan Yergler, Michael J Gruber, Asheesh Laroia, git
In-Reply-To: <4978202C.3090703@viscovery.net>
Quoting Johannes Sixt <j.sixt@viscovery.net>:
> Please don't top-post.
>
> Nathan Yergler schrieb:
>> Can you elaborate on why doing -i automatically is a bad idea in this
>> case? [It may really be, I don't pretend to have enough knowledge
>> about git's internals to make a reasoned argument.] This was
>> unexpected behavior for me as I'd always experienced "git add path &&
>> git commit" and "git commit path" as being equivalent and so I assumed
>> they would work equivalently in this situation.
>
> They are not equivalent. 'git add path && git commit' commits changes to
> path *in addition* to what is already staged before you run this command
> sequence. But 'git commit path' commits *only* changes to path, leaving
> other changes that might be staged uncommitted.
>
> It may become obvious why the latter behavior is unwanted if a merge is in
> progress: The merge left changes (and conflicts) in the index; but with
> 'git commit path' you say that you are not interested in what the index has.
Your explanation is a good answer to Nathan's misunderstanding; "git add path && git commit" and "git commit path" are different.
But Nathan's first sentence is a different matter. I do not think it is coming from the same confusion, and I think the question is a valid one. Your answer does not explain why it is a bad idea to change the behavior of "git commit path" to what "git commit -i path" does during a merge.
The answer of course can be "because it changes the behavior people are very much used to."
--
Nanako Shiraishi
http://ivory.ap.teacup.com/nanako3/
^ permalink raw reply
* Re: RFC: git diff colorization idea
From: Junio C Hamano @ 2009-01-23 0:32 UTC (permalink / raw)
To: Wincent Colaiuta; +Cc: git@vger.kernel.org List
In-Reply-To: <53497057-1ADE-4300-9F35-B218959606FE@wincent.com>
Wincent Colaiuta <win@wincent.com> writes:
> I'm also thinking that perhaps a per-character approach might be
> useful here instead of a per-word one (it would make that last hunk
> look better in the mock-up screenshot that I posted); if I go the per-
> character route then that suggests that "--color-chars" might be the
> right option name, and the color slots would then be
> color.diff.new.char and color.diff.old.char.
>
> Any feedback or suggestions before I get in too deep?
I personally find your "prposal" picture too loud to my eye.
I would have expected you to propose something like this:
| _git_remote ()
| {
|- local subcommands="add rm show prune <red>update</red>"
|+ local subcommands="add <green>rename</green> rm show prune"
| local subcommand=$(__git_find_subcommand "$subcommands")"
| if ...
if the patch were to remove update and add rename, that is. If there is
no deletion but only insertion, you would only see green.
And that way you do not need new color slots. You can use new color and
old color as before, and the coloring will be done to highlight only the
parts that really matter.
If you were to go this route, I suspect that showing the unchanged part on
the preimage line in light gray might make sense, like:
| _git_remote ()
| {
|- <gray>local subcommands="add rm show prune<gray> <red>update</red>"
|+ local subcommands="add <green>rename</green> rm show prune"
| local subcommand=$(__git_find_subcommand "$subcommands")"
| if ...
because there will be the same chars/words on the postimage line anyway.
Just 2c from somebody who does not like colors very much.
^ permalink raw reply
* [PATCH] git-am: implement --reject option passed to git-apply
From: martin f. krafft @ 2009-01-23 0:31 UTC (permalink / raw)
To: git; +Cc: martin f. krafft, penny leach
With --reject, git-am simply passes the --reject option to git-apply and thus
allows people to work with reject files if they so prefer.
The patch does not touch t/t4252-am-options.sh (yet) because I do not really
understand how the testing system works.
Signed-off-by: martin f. krafft <madduck@madduck.net>
---
Documentation/git-am.txt | 2 ++
git-am.sh | 3 +++
2 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/Documentation/git-am.txt b/Documentation/git-am.txt
index 5cbbe76..efd311b 100644
--- a/Documentation/git-am.txt
+++ b/Documentation/git-am.txt
@@ -12,6 +12,7 @@ SYNOPSIS
'git am' [--signoff] [--keep] [--utf8 | --no-utf8]
[--3way] [--interactive]
[--whitespace=<option>] [-C<n>] [-p<n>] [--directory=<dir>]
+ [--reject]
[<mbox> | <Maildir>...]
'git am' (--skip | --resolved | --abort)
@@ -63,6 +64,7 @@ default. You could use `--no-utf8` to override this.
-C<n>::
-p<n>::
--directory=<dir>::
+--reject::
These flags are passed to the 'git-apply' (see linkgit:git-apply[1])
program that applies
the patch.
diff --git a/git-am.sh b/git-am.sh
index e20dd88..b1c05c9 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -19,6 +19,7 @@ whitespace= pass it through git-apply
directory= pass it through git-apply
C= pass it through git-apply
p= pass it through git-apply
+reject pass it through git-apply
resolvemsg= override error message when patch failure occurs
r,resolved to be used after a patch failure
skip skip the current patch
@@ -168,6 +169,8 @@ do
git_apply_opt="$git_apply_opt $(sq "$1=$2")"; shift ;;
-C|-p)
git_apply_opt="$git_apply_opt $(sq "$1$2")"; shift ;;
+ --reject)
+ git_apply_opt="$git_apply_opt $1" ;;
--)
shift; break ;;
*)
--
tg: (9a01387..) git-am--reject (depends on: master)
^ permalink raw reply related
* [kha/safe PATCH] completion bugfix: Place double pipes in front of alternate command.
From: Ted Pavlic @ 2009-01-23 0:26 UTC (permalink / raw)
To: gitster, kha; +Cc: git, catalin.marinas, Ted Pavlic
In-Reply-To: <20090122232928.GA23456@diana.vm.bytemark.co.uk>
Signed-off-by: Ted Pavlic <ted@tedpavlic.com>
---
This is a patch against
git://repo.or.cz/stgit/kha.git stable
Unfortunately, the previous "[StGit PATCH 2/2]" had a small bug in it. A
bugfix was posted, but it didn't get picked up in kha/safe. This commit
should be applied against kha/safe to fix the problem.
Alternatively, the patch provided in
<1232642662-12851-1-git-send-email-ted@tedpavlic.com>
is the proper patch to stgit/master.
Sorry for the extra bother.
stgit/completion.py | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/stgit/completion.py b/stgit/completion.py
index 56e81c2..38f0670 100644
--- a/stgit/completion.py
+++ b/stgit/completion.py
@@ -130,7 +130,7 @@ def main_switch(commands):
def install():
return ['complete -o bashdefault -o default -F _stg stg 2>/dev/null \\', [
- 'complete -o default -F _stg stg' ] ]
+ '|| complete -o default -F _stg stg' ] ]
def write_completion(f):
commands = stgit.commands.get_commands(allow_cached = False)
--
1.6.1.213.g28da8
^ permalink raw reply related
* Re: how to force a commit date matching info from a mbox ?
From: Johannes Schindelin @ 2009-01-23 0:21 UTC (permalink / raw)
To: Christian MICHON; +Cc: git list
In-Reply-To: <46d6db660901221441q60eb90bdge601a7a250c3a247@mail.gmail.com>
Hi,
On Thu, 22 Jan 2009, Christian MICHON wrote:
> I've a big set of patches in a mbox file: there's sufficient info inside
> for git-am to work.
>
> Yet, each time I do import these, my sha1sums are changing because of
> different commit dates.
>
> I'd like to force the commit date to match the info/date from the time I
> received the email (and therefore always get back the right sha1sums).
>
> is this possible ?
Have you tried setting GIT_COMMITTER_DATE to the given date?
Alternatively, you can always use a commit-message filter with
filter-branch to fix it up.
Ciao,
Dscho
^ permalink raw reply
* Re: how to force a commit date matching info from a mbox ?
From: Junio C Hamano @ 2009-01-23 0:14 UTC (permalink / raw)
To: Christian MICHON; +Cc: git list
In-Reply-To: <46d6db660901221441q60eb90bdge601a7a250c3a247@mail.gmail.com>
Christian MICHON <christian.michon@gmail.com> writes:
> I'd like to force the commit date to match the info/date from the time
> I received the email (and therefore always get back the right
> sha1sums).
>
> is this possible ?
"am" being a tool to accept patches written in some past to faithfully
record both author timestamp and committer timestamp, what you seem to
want is outside of the current scope of the tool.
A patch to butcher "git-am" to copy GIT_COMMITTER_DATE from
GIT_AUTHOR_DATE and export it should be trivial to implement, though.
Perhaps something like this totally untested patch.
git-am.sh | 13 ++++++++++++-
t/t4150-am.sh | 20 ++++++++++++++++++++
2 files changed, 32 insertions(+), 1 deletions(-)
diff --git c/git-am.sh w/git-am.sh
index e20dd88..e96071d 100755
--- c/git-am.sh
+++ w/git-am.sh
@@ -23,6 +23,7 @@ resolvemsg= override error message when patch failure occurs
r,resolved to be used after a patch failure
skip skip the current patch
abort restore the original branch and abort the patching operation.
+committer-date-is-author-date lie about committer date
rebasing (internal use for git-rebase)"
. git-sh-setup
@@ -133,6 +134,7 @@ dotest="$GIT_DIR/rebase-apply"
sign= utf8=t keep= skip= interactive= resolved= rebasing= abort=
resolvemsg= resume=
git_apply_opt=
+committer_date_is_author_date=
while test $# != 0
do
@@ -168,6 +170,8 @@ do
git_apply_opt="$git_apply_opt $(sq "$1=$2")"; shift ;;
-C|-p)
git_apply_opt="$git_apply_opt $(sq "$1$2")"; shift ;;
+ --committer-date-is-author-date)
+ committer_date_is_author_date=t ;;
--)
shift; break ;;
*)
@@ -521,7 +525,14 @@ do
tree=$(git write-tree) &&
parent=$(git rev-parse --verify HEAD) &&
- commit=$(git commit-tree $tree -p $parent <"$dotest/final-commit") &&
+ commit=$(
+ if test -n "$committer_date_is_author_date"
+ then
+ GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
+ export GIT_COMMITTER_DATE
+ fi &&
+ git commit-tree $tree -p $parent <"$dotest/final-commit"
+ ) &&
git update-ref -m "$GIT_REFLOG_ACTION: $FIRSTLINE" HEAD $commit $parent ||
stop_here $this
diff --git c/t/t4150-am.sh w/t/t4150-am.sh
index 796f795..8d3fb00 100755
--- c/t/t4150-am.sh
+++ w/t/t4150-am.sh
@@ -257,4 +257,24 @@ test_expect_success 'am works from file (absolute path given) in subdirectory' '
test -z "$(git diff second)"
'
+test_expect_success 'am --committer-date-is-author-date' '
+ git checkout first &&
+ test_tick &&
+ git am --committer-date-is-author-date patch1 &&
+ git cat-file commit HEAD | sed -e "/^$/q" >head1 &&
+ at=$(sed -ne "/^author /s/.*> //p" head1) &&
+ ct=$(sed -ne "/^committer /s/.*> //p" head1) &&
+ test "$at" = "$ct"
+'
+
+test_expect_success 'am without --committer-date-is-author-date' '
+ git checkout first &&
+ test_tick &&
+ git am patch1 &&
+ git cat-file commit HEAD | sed -e "/^$/q" >head1 &&
+ at=$(sed -ne "/^author /s/.*> //p" head1) &&
+ ct=$(sed -ne "/^committer /s/.*> //p" head1) &&
+ test "$at" != "$ct"
+'
+
test_done
^ permalink raw reply related
* RFC: git diff colorization idea
From: Wincent Colaiuta @ 2009-01-23 0:00 UTC (permalink / raw)
To: git@vger.kernel.org List
Hi,
Lately I've been wishing that Git's diff output were colorized in a
way that combines the standard line-by-line colorizing with the word-
by-word colorizing you get with --color-words.
Pictures speak louder than words, so here are some to show what I mean:
http://www.flickr.com/photos/wincent-colaiuta/sets/72157612877491482/
There you'll find:
1. A couple of sample hunks colorized in the current, standard way
2. The same hunks colorized with "--color-words"
3. The same hunks as they would be colorized if you could take the
standard colorization (1) and augment it with per-word highlighting
from (2)
(that last hunk would probably look better with a different regex
defining what a "word" is; in reality all that happened was that
"rename|" got added to the line, so there's no need to highlight more
than that).
This is not a new idea; it's something that I find myself wanting due
to experience with colorization available in a number of different
diff viewers. Here are some more sample shots showing how different
viewers do it, with varying degrees of prettiness/ugliness:
- Meld: http://meld.sourceforge.net/meld_file1.png
- kdiff: http://kdiff3.sourceforge.net/doc/letter_by_letter.png
- Apple FileMerge: http://homepage.mac.com/kelleherk/iblog/C711669388/E464913847/Media/compare_db_filemerge.jpg
No doubt there are others, but you get the idea.
Would people be interested in seeing this feature go in? I've already
started snooping around diff.c seeing what would need to be done. From
what I can tell it would require a new command-line switch (seeing as
"--color" plus "--color-words" already means something), and probably
two new customizable color slots (such as color.diff.new.word,
color.diff.old.word).
The approach I was thinking of taking was just grabbing the diff_words
info produced when --color-words is passed and using it to augment
specialized versions of emit_line() and emit_add_line().
I'm also thinking that perhaps a per-character approach might be
useful here instead of a per-word one (it would make that last hunk
look better in the mock-up screenshot that I posted); if I go the per-
character route then that suggests that "--color-chars" might be the
right option name, and the color slots would then be
color.diff.new.char and color.diff.old.char.
Any feedback or suggestions before I get in too deep?
Cheers,
Wincent
^ permalink raw reply
* Re: [RFC/PATCH v3 3/3] archive.c: add basic support for submodules
From: Johannes Schindelin @ 2009-01-22 23:44 UTC (permalink / raw)
To: Lars Hjemli; +Cc: git, Junio C Hamano, René Scharfe
In-Reply-To: <1232659071-14401-4-git-send-email-hjemli@gmail.com>
Hi,
On Thu, 22 Jan 2009, Lars Hjemli wrote:
> The new --submodules option is used to trigger inclusion of checked out
> submodules in the archive.
>
> The implementation currently does not verify that the submodule has been
> registered as 'interesting' in .git/config, neither does it resolve the
> currently checked out submodule HEAD but instead uses the commit SHA1
> recorded in the gitlink entry to identify the submodule root tree.
Please understand that I skipped the rest of the patch.
Ciao,
Dscho
^ permalink raw reply
* Re: [RFC/PATCH v3 2/3] sha1_file: prepare for adding alternates on demand
From: Johannes Schindelin @ 2009-01-22 23:43 UTC (permalink / raw)
To: Lars Hjemli; +Cc: git, Junio C Hamano, René Scharfe
In-Reply-To: <1232659071-14401-3-git-send-email-hjemli@gmail.com>
Hi,
On Thu, 22 Jan 2009, Lars Hjemli wrote:
> @@ -285,9 +286,10 @@ static int link_alt_odb_entry(const char * entry, int len, const char * relative
>
> /* Detect cases where alternate disappeared */
> if (!is_directory(ent->base)) {
> - error("object directory %s does not exist; "
> - "check .git/objects/info/alternates.",
> - ent->base);
> + if (!quiet)
> + error("object directory %s does not exist; "
> + "check .git/objects/info/alternates.",
> + ent->base);
> free(ent);
> return -1;
> }
> [...]
> @@ -2573,3 +2579,11 @@ int read_pack_header(int fd, struct pack_header *header)
> return PH_ERROR_PROTOCOL;
> return 0;
> }
> +
> +int add_alt_odb(char *path, int quiet)
> +{
> + int err = link_alt_odb_entry(path, strlen(path), NULL, 0, quiet);
> + if (!err)
> + prepare_packed_git_one(path, 0);
> + return err;
> +}
FWIW my concern is not at all addressed. A future user of add_alt_odb()
(and possibly your users in rare cases, too) can trigger the error that
suggests looking into the alternates. Leaving the human user puzzled.
Ciao,
Dscho
^ permalink raw reply
* kha/{stable,safe,experimental} updated
From: Karl Hasselström @ 2009-01-22 23:29 UTC (permalink / raw)
To: Catalin Marinas; +Cc: ted, git
In-Reply-To: <1232412373-10836-2-git-send-email-ted@tedpavlic.com>
Ted, Both of your patches look good, and work when I try them.
(Excellent commit messages, by the way.) I've applied them and pushed
them out.
Catalin, I have stuff for you in both kha/stable and kha/safe.
-+-
The following changes since commit 7cb253c05b509510177a1df4d5813861641968f6:
Karl Hasselström (1):
Fix typo
are available in the git repository at:
git://repo.or.cz/stgit/kha.git stable
Karl Hasselström (1):
Return None instead of crashing on undefined integer config items
Pete Wyckoff (1):
stgit.namelength is an integer
stgit/config.py | 4 +++-
stgit/utils.py | 2 +-
2 files changed, 4 insertions(+), 2 deletions(-)
-+-
The following changes since commit d3b31eeac6c6fba9352188755164f556faf56e59:
Catalin Marinas (1):
Fix the patch argument parsing for the "show" command
are available in the git repository at:
git://repo.or.cz/stgit/kha.git safe
Gustav Hållberg (7):
stgit.el: Consistently use symbols rather than strings for patch names
stgit.el: Make single file diff buffer read-only
stgit.el: Include stat summary in patch diff
stgit.el: Add message when there are no patches in the series
stgit.el: Indicate empty patches
stgit.el: Minor beautification
stgit.el: Add optional count argument to stgit-commit
Karl Hasselström (2):
Return None instead of crashing on undefined integer config items
Merge branch 'stable'
Pete Wyckoff (1):
stgit.namelength is an integer
Ted Pavlic (2):
Modify bash completion to support help, version, and copyright.
Make bash completion fail to bashdefault before default completion.
contrib/stgit.el | 245 ++++++++++++++++++++++++++++-----------------------
stgit/completion.py | 11 ++-
stgit/config.py | 4 +-
stgit/utils.py | 2 +-
4 files changed, 146 insertions(+), 116 deletions(-)
-+-
The following changes since commit e80d43bd9c8baf2bc9913c6c153914403f210872:
Ted Pavlic (1):
Make bash completion fail to bashdefault before default completion.
are available in the git repository at:
git://repo.or.cz/stgit/kha.git experimental
Gustav Hållberg (1):
stgit.el: (EXPERIMENTAL) Show files modified in work tree
Karl Hasselström (2):
Read several objects at once with git cat-file --batch
Diff several trees at once with git diff-tree --stdin
INSTALL | 5 +-
contrib/stgit.el | 272 ++++++++++++++++++++++++++++++++++--------------------
stgit/lib/git.py | 79 +++++++++++++++-
stgit/run.py | 19 ++++
4 files changed, 266 insertions(+), 109 deletions(-)
--
Karl Hasselström, kha@treskal.com
www.treskal.com/kalle
^ permalink raw reply
* [JGIT PATCH 10/10] Add a few simple merge test cases
From: Shawn O. Pearce @ 2009-01-22 23:28 UTC (permalink / raw)
To: Robin Rosenberg; +Cc: git, Robin Rosenberg
In-Reply-To: <1232666890-23488-10-git-send-email-spearce@spearce.org>
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
.../spearce/jgit/test/resources/create-second-pack | 13 +++-
...ck-3280af9c07ee18a87705ef50b0cc4cd20266cf12.idx | Bin 0 -> 1296 bytes
...k-3280af9c07ee18a87705ef50b0cc4cd20266cf12.pack | Bin 0 -> 562 bytes
...ck-9fb5b411fe6dfa89cc2e6b89d2bd8e5de02b5745.idx | Bin 1088 -> 1100 bytes
...ck-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.idx | Bin 2696 -> 2976 bytes
...k-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.pack | Bin 5956 -> 5901 bytes
.../org/spearce/jgit/test/resources/packed-refs | 4 +-
.../org/spearce/jgit/lib/RepositoryTestCase.java | 3 +-
.../org/spearce/jgit/merge/SimpleMergeTest.java | 86 ++++++++++++++++++++
.../org/spearce/jgit/transport/TransportTest.java | 2 +-
10 files changed, 104 insertions(+), 4 deletions(-)
create mode 100644 org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/pack-3280af9c07ee18a87705ef50b0cc4cd20266cf12.idx
create mode 100644 org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/pack-3280af9c07ee18a87705ef50b0cc4cd20266cf12.pack
create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/merge/SimpleMergeTest.java
diff --git a/org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/create-second-pack b/org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/create-second-pack
index 052877d..5501a67 100755
--- a/org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/create-second-pack
+++ b/org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/create-second-pack
@@ -138,7 +138,18 @@ done
git repack -d
+git checkout -b f a
+mkdir f
+echo "an eff" >f/f
+git add f/f
+git commit -m "An eff"
+git checkout -b g a
+mkdir f
+echo "an F" >f/f
+git add f/f
+git commit -m "An F"
+git repack -d
git pack-refs --all
-qgit --all master
+gitk --all master
diff --git a/org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/pack-3280af9c07ee18a87705ef50b0cc4cd20266cf12.idx b/org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/pack-3280af9c07ee18a87705ef50b0cc4cd20266cf12.idx
new file mode 100644
index 0000000000000000000000000000000000000000..300c0cea48c6c4eda2b870b3631355c2137cebb0
GIT binary patch
literal 1296
zcmexg;-AdGz`z8=xBw$if)Wfen|Y98R-n6x!E8Wvw8HE_v#E_afM$;3(J&x74Y2LV
z)Q$1iT(-xv{o%d?ezP~d30WlO{o~}bSuv7YXEk0%y}!Bi+NY5F;<3>Ud#7h~`1YT>
zpf~%nNr$-eG+Xt8#O{s4dXa}k?k(2XVRih3k&*4s=J(gu+%LX=d`sY>$NY6y^vccL
zFK5=6yT6d|<2_P&W-sI8NG8+rIE_yi-_5-HB{Hf?{<GXKDS;Zn=f$-%{*{*K-dyoz
z&(nux&wt#UJNGfeC6_5O>cO{}3Ii^?mL8a&y=G5Sv+Zu7cmBCoC&;S-%NRy4AT9!?
z`vpMy1+YjH0J3?2>?R=nM4az|fajV^sv(TevSnRfJoL#bbLi`ut*5^~(=3sT{r8l`
LdIkBjci#j6ga?3q
literal 0
HcmV?d00001
diff --git a/org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/pack-3280af9c07ee18a87705ef50b0cc4cd20266cf12.pack b/org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/pack-3280af9c07ee18a87705ef50b0cc4cd20266cf12.pack
new file mode 100644
index 0000000000000000000000000000000000000000..fca3460ed2d263db153ef11a3e559aa47be9efa1
GIT binary patch
literal 562
zcmWG=boORoU|<4bj+wj_bLMu(avd@dV7p)3wYNd_w#iMsjvLl57%x5H=K9t?sp<Ik
zy-ohcJU(|Bgw!K{Gkv_Y)iV2yx4Bxy1{RN(o3pO*q+i>SxK8BLij_wrj#O`T2rS%|
zUidH}#Dz~P_m$6`*V#8S7O30$?L3y2f3D=Xx!-Gc->7BMhQ+Jj+_2mgvGJNrY1Q>E
z`!M4(EkS4a)5PtqUNAR^RLt3ZvSM!F_9Ysop$AQ_o=`fgan!){>Lnvp)w4&gTr#<6
zbJ0Ne><t4`-HQenFC4JBdBNan&7yZ)YUX+jzt0Q2UdLK7$Jmg8snw;eQ&#wAvg(}L
zl3h94ac_R_Q2Cq@G><bvueUMReOX@5{%4zP=e_0sF8g8j-j}{7l$@EFjfI6<?;LqF
z>59_cNnJv1%X-D5F2%7O*}gP)y~fA+sX;sDEEi;$xJmWcT1KEPCI$w^hJhZ*0-ygC
ze!96v!gK9rDgDLw?#EQU4L(uJFlPtvbn}Wi-e-b6e7zqtF>ux~X%pkRgJF9WHdZg*
z5cec;Vs*D^S%j>8VoFLzLPA>7q6xDjVkSi`2@eW9bYaU!C+}OQ8-8rt@>W#!-)0}K
z>7PxQ7@WVWFrc_@!{3{K{@t4O`{?)ne9o9JGxophirXp4u;mKxJX5gi3V?27nZf8F
Z&i6pTbIm2y5XNWOvMw(k`ec<k001O50^|Sy
literal 0
HcmV?d00001
diff --git a/org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/pack-9fb5b411fe6dfa89cc2e6b89d2bd8e5de02b5745.idx b/org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/pack-9fb5b411fe6dfa89cc2e6b89d2bd8e5de02b5745.idx
index cf58d5baa11824217bb0c5eab7444fb406219885..58b712f6c58e3b99abd536c17c306ef2c37c5238 100644
GIT binary patch
delta 89
zcmV-f0H*)I2+Rlw|8!4d00002kpW(@UZMj;7j}SvqA`rvo4QPkhl4}`;t5v+%)Fm1
v0000CGYgnnQ2?6FEimT$X76fU(jBSR$3y!oeS1unZtru#oQ%-R@OV6B4p%0y
literal 1088
zcmZQzpebMknm&q0!(cQG4Bj-rBVN|fu*k6I#_U}_-R;dTjE^|OnT@$;L<KU;I;(5&
j?04Gxtk_GkE3duSzFw<E`CW}`!gtH2lI+N+ZF^b)CtDqp
diff --git a/org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.idx b/org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.idx
index 2579301b8447e4d55480f65ae6c27fe1eb99bf4d..3ff542377406158d8155129ae66fc0b51cba76b8 100644
GIT binary patch
delta 1975
zcmWNSc{~(o9L8VczD?s85wmDmCU<REE7_%?a(yIa3Nhujj!cFI!x(prt4tc2lCznL
z1~tkN*3sk&Z76pK<xDp1`^WqFywCG~f6x28f4y`imWssBXy*$600c{ff@n4!@-K4*
zh&E+cMsP%Ib<EEyNg~_)<6Z=z@v&lR&4t^o{5zON$(63T8`MI*TJpp#7UthPAzfOc
zlyz+6vCLqF@J2mU$LOeTUUpuRf{5UCEp}(q*rmd}hnHb5?x{MYFmbx@5(WhVT^1(X
zog&=aI9Bs}ggMsT%6*iUi?KF(51%v80Z!80O5c~}T}7;?f9zY{pjX?po{6)4p}hSG
zlzCk0IJh3wY`JgCbeOr=uK9Z8%1+SCZoz?POdQGFPH=ox19Pu#;j#r@gY}e1-X<*8
ztg+3zu`%e}u|U$ulM|81z|3FJ^;VmwapsJJkGG1&aa+H3thG=i6+bmj_TbvrmCoc$
zc-yFT6Q)bDggm<Y)Qu}Sk;Arc{@X<mxt;$l9oOn`m^eDS&^agm4)w8xB*YDNdr2e5
zzr&jva1$*1^6a;>iUlNBQ@xh8XZX%<u1CTWMR>|Q75Q-VjND>ulSg@_&y*95g(;{K
znYx3VYzXiYJx$@;d$o8X3qJqlCvZA=6Z=cJTbNfw5c28!rt}-S^usHds;jwag@fn!
zS8qfuunGdNq*dwi%%<rm`)D7`ZQjV}p*eitQyKU7m+ezpO!oV6y>Cu*yRWo>jXdr3
z6wX<(v4{SC3u6eoBJPRHuJ1n~-?w~;6YU70RtZ?l`BxOJe3O$y<L@@*EOt2|nJBV)
zfUb#Gd^$1LmP{*L&3+x))b?@9<J$6el!VHmD5<jYKvqYXVhkqC6DdEi-lUDO3(+Wv
zysbq^*0ZSCE%sTX^|tid<ah2SO>QO4`c1`0C!9^A-bc4mTX$Bn+nyvFuTzbuMG0ln
zofVa_Xv*eWh7K>8D@Y+OxtymFACsb;Z<zmGDU+1EV@QgMDUI$>z_6s6KQMpGh*P2x
z%27#^OUM6a+4}cayIYGz&CXG&j&VP#_wMmIm3ncr?ixZkebb*h_{C1Gzo+d7PKBqZ
zXf?m=%uh@WYm=xCsjJ<8_qDSs*Wf{%&aMs(OYt`2mKrRmy(MQgoz`BBwidoe8+g%>
zkobcw40dFRR|4*|w|g382N~&qdC(MYDm!Y_IGz_ih))>Lb!k=_X1FK){^C8N1mI*<
zI91De^gMY2+U__m!<w|n|H=;R^b0F;_eB{RDW%8X8tu~MH^dlwwr3P&IE7SadfZK<
zluYB#KP`)?6rB5BK_Be<V`0qbm|;XcIsEe@mc?7i+m@1Q@!3n6mimLMn)DB}wZhkF
z?CCk#*}&Q`qbb8hw8X0W$m86h+N)Rpd`>^N<Dfs{NHR?zwsw44sTF9+i*3!martnz
z;^>#D&%cs&@7FU#JcGj8ZA-P)4464)EJ}Fs_D)k8g}UC>EMq;kV-$Q|gjM}DwV=5%
z_}I5Yp9^KKqfTxT?ZP>6k}Q7dUuITBA*)ICD8-dd`I_;E%+O~Mby*TAGD*r4w6g~S
zyexy8`t_fa%a#N#nxE>vw>QeLQ@PFre#!G>iugOlHc^LvgCdJg(<9gojkul{_bC+8
z69>F(>mSLu)wQ-0PS<?<onE#j+{Fc_$SwfBx=-c&b+<bLq$97^G`Pli=B_8pB8Jpi
zexE+1dB$g0Y|%t;idVb;@Q9Lv%z@S6Caz{T2wLNKuRiisi2WQ?nk7CKq+eIDvCy~q
z6`k1HRCDBH2Hk%`K4*Myu93VLnPN4C#S*;PS>JH8KcypkB@5ncRZU=}KH96_q#HEM
zxBm3rCok9UqU83-QUf&xGM<>MR`)V4C58qdSe8{266V7V(zoQctO_q`ni7>qgY|c;
zruth3kkWtR1%_Q7n&w~us~__9)|NEra+0;p|EDD5x~h#dgPA>b>D4-#;)Gq>2)Om;
zC2i5-Qs|itym7H^$-c$DtN9JvzN+O$Twg0&`nQv2$@&Auk>uq*xAD!f@qcim;RdFh
zLfeAS+><K!IQJf5?d=N<HM@@Ka>ZdA*u*!ZgK}+DCT0ksb@vC2=f<9yy(gNkYH3K)
zOziCCA8z3FEF;fH4z4*<GzffNE?M|!j(WY9r%R>R)XPK68OCKk!$nlyoMV??=#U*P
zd1l{D@BH-~wiLU_;hu2WOsS4@L5+XRsR#3Vt1mefM%%CO+Doafhws1rdP-CkQ&T<|
zc5i-n?*k?xbdKrk^XwQwPSfH68UVRT0Hn+SP`UzutS(#>4m8E#SF{O5J^%{-P@e-p
zSrhKn0g${7z@AX3O8^k1z&}d{o-4xzJ!!~`F#%9K0_`dQkj?;z%){^@s0{&-2!y$Z
zAR_`96!f3Lxp<iO9J0}n#R5PPAApBh@UjS4;2VT+0HAyUkS9Q04*gLG>%$>fQgIBn
zhYS+>NDat!0U(?M**mb<M_95O&SRkO0WX5(glYf~KM1ufe25Utqd_JFW;MW>$FQ8#
tIo)0Ce0{H4d`WoglAGiPUdBsD(Nnqf$%y01fxIk6k#j3%Ow8X>?tj#hbMOEF
delta 1424
zcmXAodpOg39LK-zhS}CORBqiywTvYvt=owdD#N2mgzBt@5IKe;vS>-U{M=6D3@eXI
zwN+-U$n|h4?YM<bxg?b9L8d%7UpxPPp6C1ezTfZ9=grgQ67$uSEdjtNDOOS2&*wP<
z#X22l#6LK^By6P^01bB(lW#e;PSHzLL5MFsS6EYh-&h0yQGl2$6OI9ZKBloRJmlyt
ze{7J*6yMO*Ws-V3^%|UaVwI)u%1Ddz=JW!~7IC7T8e?rc0NP}1uY1NtV?1EdM|xcy
zgI!z%v|#|0)+4e111pF>z6?7n@9SSOnEb{qIZ)#f`EwHh*c_ej;~>xNV#BVv(5gKK
zGHOTeXgvgSjNWxdEc$&~PT%n|m&~@bksg~d1VHB`B9#NNuB0%%<Zc$b^ZD@*9P8Ew
zy+^cpcK}e;WJ_dMg)B>rEZf>JD?t&)MIT!LSi>jR&k;TD^m-mx-|W?&ouuH_{8}FZ
z-y+5;tCm&xhlWNPKdTMk$0Te8p}))9gs9&J003I{)a}CPJ+D*kz9(f#+0Il`$?Qw0
zkY?Yw;CwJJR#~hg*2M(rebOEcuY~h7Bv=mAtZ=WkJ0)S@(kBj|l{)UaN7@kN5(t25
z?Wtft+>61=n|DpPyQhqcuO{EfXaj%{?!BetTj&TcofUDT*hIXupNqG<0{?GCUdn;E
zgtJ1=d%exBQxfnkb<^B+!D-d*r%<`(`LiS4iZ+?T<G(r&j^hR;(~&9-(3(a7r&!9%
z9sYY`n#GCso`HF7>tz81x*}NBRm<vkE>+fz$=p&VzlW;pT7_!l<+FJ3q2lR4LYQ$N
z1BYpytK4L46JVGfQn(Q+-x?EVYF)6L<ujY`O7iMJTI2Gyk20v-0r8OoiLyBJIgWY1
zidUXyV?j~4-uwq-vlwQQA19PvXMUl3Con76SDfxzUM|vt=d@-aZqbY#8kTdV0c*_D
zsQQ}wQ(`0$09+{|kOP$+IUI+`rIK}Pd``w+n17g}sC0AwJOFC5oVID3^>140mdLtd
zQvz*x(y2NYDyfeTtW$p!@UU#lgLh7Ah1;J*ZeHFD&#Wj-ZPl^1K|*U&d35X&UkNOt
znGwI-udioN;NhRU?MK-*{iHI8iteI_dQyYh?4x@Cz-K4ZtB4(l>$Sa2gNoUJjMfzt
zPr_owA#^zq-IVF-i#MYXZ~pd2*PkZU<zeQG`b6jeotfwuP;$%dL2P!vz4wc}up;T1
zA8_tlz-@cIf25mo)GYW>RM5mTp7jS5OkzL6lLLtue*b6m5UVVZ(q}fRr#|D_S&<AI
zrfE=i^{Q<x_srsvZJiEmYBaN^VSEY#yUU~-F{-km_w=u)3l2^9O>B)ac?{=n$g~`Y
zU#`3n!<nnA(%RR(Nb&bp=9T;#pAM_}v`XZEbiryOL+f|^iFu|?kRTGpgVz44&N;l3
z##Eqv)DI<0HDXG8p5|VHJs3j{s;_3Kvr-$C_eDxK8h`ksUZlm37dm-WXTuB`wQ(_O
z1B5!2Bmek?WV&;M`Q;)q%rL2?>2VDE`4M|`&Hgy@%xv9p#}r?<iwYz~4pb<W;vB?f
zRR2=*PY)P8>o9g>{$nm&vPZj-hfjy<sD<>TxNOVrP9j!o#|#A8c2o+Dnt|V}z;ouA
zFE)I_FDFS2R-c6Q%Yo?9Ud)}Ib;%TrY80)HMDp_FCoMoFI)y_knjx=H>F;I5y(En>
zJN<jy?d351@!^^kPXmnh8#>YD*&aiDH%NSL0i&2i%u$4cun_t(TE+z<DpRM+f7>Fh
z?~SAtr)g`O&$8&1U0h1vT~cU;GC=Re9<sOUyT0Rzlyn)1V7VEdU<8k4y$JXZTkul8
diff --git a/org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.pack b/org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.pack
index bb47c90d93b0b2276fc36b96bc8734085bde6007..ef56d7e941828561e9f6e2cbc46e2d6c9c8d76bf 100644
GIT binary patch
delta 55
zcmV-70LcHuE{!g*s{sV$1%N=4!2w$X;R0W?G6I+l180Cov)>O<2NYiZCg!fo8+@2=
Nzv)s5^+^m_Both>71IC!
delta 110
zcmV-!0FnQVF2pXds{t1D1;B8vj0l7bffm|^TP<Z-I%~PjDwD4PTNd#G&=E?wtTJn>
zFyp3IpgDDT#i6f=vkd~64Hb6+x-!#bo>2e-!WL1JYjAg}b^oces1H#G6hxtEG1~WN
Q{ggPWqc#a04LlG+NkNq^UjP6A
diff --git a/org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/packed-refs b/org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/packed-refs
index 746bd6b..38a70ec 100644
--- a/org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/packed-refs
+++ b/org.spearce.jgit.test/tst-rsrc/org/spearce/jgit/test/resources/packed-refs
@@ -4,8 +4,10 @@
6e1475206e57110fcef4b92320436c1e9872a322 refs/heads/c
f73b95671f326616d66b2afb3bdfcdbbce110b44 refs/heads/d
d0114ab8ac326bab30e3a657a0397578c5a1af88 refs/heads/e
-d86a2aada2f5e7ccf6f11880bfb9ab404e8a8864 refs/heads/pa
+47d3697c3747e8184e0dc479ccbd01e359023577 refs/heads/f
+175d5b80bd9768884d8fced02e9bd33488174396 refs/heads/g
49322bb17d3acc9146f98c97d078513228bbf3c0 refs/heads/master
+d86a2aada2f5e7ccf6f11880bfb9ab404e8a8864 refs/heads/pa
6db9c2ebf75590eef973081736730a9ea169a0c4 refs/tags/A
17768080a2318cd89bba4c8b87834401e2095703 refs/tags/B
^d86a2aada2f5e7ccf6f11880bfb9ab404e8a8864
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryTestCase.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryTestCase.java
index 9e48fde..20348f1 100644
--- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryTestCase.java
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryTestCase.java
@@ -236,7 +236,8 @@ public void run() {
"pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371",
"pack-9fb5b411fe6dfa89cc2e6b89d2bd8e5de02b5745",
"pack-546ff360fe3488adb20860ce3436a2d6373d2796",
- "pack-e6d07037cbcf13376308a0a995d1fa48f8f76aaa"
+ "pack-e6d07037cbcf13376308a0a995d1fa48f8f76aaa",
+ "pack-3280af9c07ee18a87705ef50b0cc4cd20266cf12"
};
final File packDir = new File(db.getObjectsDirectory(), "pack");
for (int k = 0; k < packs.length; k++) {
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/merge/SimpleMergeTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/merge/SimpleMergeTest.java
new file mode 100644
index 0000000..96064f5
--- /dev/null
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/merge/SimpleMergeTest.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2008, Robin Rosenberg
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Git Development Community nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.spearce.jgit.merge;
+
+import java.io.IOException;
+
+import org.spearce.jgit.lib.ObjectId;
+import org.spearce.jgit.lib.RepositoryTestCase;
+
+public class SimpleMergeTest extends RepositoryTestCase {
+
+ public void testOurs() throws IOException {
+ Merger ourMerger = MergeStrategy.OURS.newMerger(db);
+ boolean merge = ourMerger.merge(new ObjectId[] { db.resolve("a"), db.resolve("c") });
+ assertTrue(merge);
+ assertEquals(db.mapTree("a").getId(), ourMerger.getResultTreeId());
+ }
+
+ public void testTheirs() throws IOException {
+ Merger ourMerger = MergeStrategy.THEIRS.newMerger(db);
+ boolean merge = ourMerger.merge(new ObjectId[] { db.resolve("a"), db.resolve("c") });
+ assertTrue(merge);
+ assertEquals(db.mapTree("c").getId(), ourMerger.getResultTreeId());
+ }
+
+ public void testTrivialTwoWay() throws IOException {
+ Merger ourMerger = MergeStrategy.SIMPLE_TWO_WAY_IN_CORE.newMerger(db);
+ boolean merge = ourMerger.merge(new ObjectId[] { db.resolve("a"), db.resolve("c") });
+ assertTrue(merge);
+ assertEquals("02ba32d3649e510002c21651936b7077aa75ffa9",ourMerger.getResultTreeId().name());
+ }
+
+ public void testTrivialTwoWay_disjointhistories() throws IOException {
+ Merger ourMerger = MergeStrategy.SIMPLE_TWO_WAY_IN_CORE.newMerger(db);
+ boolean merge = ourMerger.merge(new ObjectId[] { db.resolve("a"), db.resolve("c~4") });
+ assertTrue(merge);
+ assertEquals("86265c33b19b2be71bdd7b8cb95823f2743d03a8",ourMerger.getResultTreeId().name());
+ }
+
+ public void testTrivialTwoWay_ok() throws IOException {
+ Merger ourMerger = MergeStrategy.SIMPLE_TWO_WAY_IN_CORE.newMerger(db);
+ boolean merge = ourMerger.merge(new ObjectId[] { db.resolve("a^0^0^0"), db.resolve("a^0^0^1") });
+ assertTrue(merge);
+ assertEquals(db.mapTree("a^0^0").getId(), ourMerger.getResultTreeId());
+ }
+
+ public void testTrivialTwoWay_conflict() throws IOException {
+ Merger ourMerger = MergeStrategy.SIMPLE_TWO_WAY_IN_CORE.newMerger(db);
+ boolean merge = ourMerger.merge(new ObjectId[] { db.resolve("f"), db.resolve("g") });
+ assertFalse(merge);
+ }
+}
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/transport/TransportTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/transport/TransportTest.java
index dc1cb21..c6e3335 100644
--- a/org.spearce.jgit.test/tst/org/spearce/jgit/transport/TransportTest.java
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/transport/TransportTest.java
@@ -123,7 +123,7 @@ public void testFindRemoteRefUpdatesWildcardNoTracking() throws IOException {
.findRemoteRefUpdatesFor(Collections.nCopies(1, new RefSpec(
"+refs/heads/*:refs/heads/test/*")));
- assertEquals(7, result.size());
+ assertEquals(9, result.size());
boolean foundA = false;
boolean foundB = false;
for (final RemoteRefUpdate rru : result) {
--
1.6.1.399.g0d272
^ permalink raw reply related
* [JGIT PATCH 09/10] Define a basic merge API, and a two-way tree merge strategy
From: Shawn O. Pearce @ 2009-01-22 23:28 UTC (permalink / raw)
To: Robin Rosenberg; +Cc: git
In-Reply-To: <1232666890-23488-9-git-send-email-spearce@spearce.org>
This basic merge implementation is sufficient to merge two commits in
memory and write the result out as a new commit, without having a work
tree on the local filesystem. It is therefore suitable for use within
a batch server process where human intervention is not available to
resolve conflicts.
This API should permit extending it with the working tree and a copy
of the work tree's DirCache, so edits in the tree can be merged in
parallel with edits from commits. But the functionality is not yet
implemented, so it is still a pie-in-the-sky concept.
The main strategy "simple-two-way-in-core" provides a basic 3 way
merge on the path level only. File contents are never patched by
this strategy, making it somewhat safe for automatic merges.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
.../src/org/spearce/jgit/merge/MergeStrategy.java | 134 ++++++++++++
.../src/org/spearce/jgit/merge/Merger.java | 213 ++++++++++++++++++++
.../org/spearce/jgit/merge/StrategyOneSided.java | 98 +++++++++
.../jgit/merge/StrategySimpleTwoWayInCore.java | 179 ++++++++++++++++
4 files changed, 624 insertions(+), 0 deletions(-)
create mode 100644 org.spearce.jgit/src/org/spearce/jgit/merge/MergeStrategy.java
create mode 100644 org.spearce.jgit/src/org/spearce/jgit/merge/Merger.java
create mode 100644 org.spearce.jgit/src/org/spearce/jgit/merge/StrategyOneSided.java
create mode 100644 org.spearce.jgit/src/org/spearce/jgit/merge/StrategySimpleTwoWayInCore.java
diff --git a/org.spearce.jgit/src/org/spearce/jgit/merge/MergeStrategy.java b/org.spearce.jgit/src/org/spearce/jgit/merge/MergeStrategy.java
new file mode 100644
index 0000000..d28dcc1
--- /dev/null
+++ b/org.spearce.jgit/src/org/spearce/jgit/merge/MergeStrategy.java
@@ -0,0 +1,134 @@
+/*
+ * Copyright (C) 2008, Google Inc.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Git Development Community nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.spearce.jgit.merge;
+
+import java.util.HashMap;
+
+import org.spearce.jgit.lib.Repository;
+
+/**
+ * A method of combining two or more trees together to form an output tree.
+ * <p>
+ * Different strategies may employ different techniques for deciding which paths
+ * (and ObjectIds) to carry from the input trees into the final output tree.
+ */
+public abstract class MergeStrategy {
+ /** Simple strategy that sets the output tree to the first input tree. */
+ public static final MergeStrategy OURS = new StrategyOneSided("ours", 0);
+
+ /** Simple strategy that sets the output tree to the second input tree. */
+ public static final MergeStrategy THEIRS = new StrategyOneSided("theirs", 1);
+
+ /** Simple strategy to merge paths, without simultaneous edits. */
+ public static final MergeStrategy SIMPLE_TWO_WAY_IN_CORE = StrategySimpleTwoWayInCore.INSTANCE;
+
+ private static final HashMap<String, MergeStrategy> STRATEGIES = new HashMap<String, MergeStrategy>();
+
+ static {
+ register(OURS);
+ register(THEIRS);
+ register(SIMPLE_TWO_WAY_IN_CORE);
+ }
+
+ /**
+ * Register a merge strategy so it can later be obtained by name.
+ *
+ * @param imp
+ * the strategy to register.
+ * @throws IllegalArgumentException
+ * a strategy by the same name has already been registered.
+ */
+ public static void register(final MergeStrategy imp) {
+ register(imp.getName(), imp);
+ }
+
+ /**
+ * Register a merge strategy so it can later be obtained by name.
+ *
+ * @param name
+ * name the strategy can be looked up under.
+ * @param imp
+ * the strategy to register.
+ * @throws IllegalArgumentException
+ * a strategy by the same name has already been registered.
+ */
+ public static synchronized void register(final String name,
+ final MergeStrategy imp) {
+ if (STRATEGIES.containsKey(name))
+ throw new IllegalArgumentException("Merge strategy \"" + name
+ + "\" already exists as a default strategy");
+ STRATEGIES.put(name, imp);
+ }
+
+ /**
+ * Locate a strategy by name.
+ *
+ * @param name
+ * name of the strategy to locate.
+ * @return the strategy instance; null if no strategy matches the name.
+ */
+ public static synchronized MergeStrategy get(final String name) {
+ return STRATEGIES.get(name);
+ }
+
+ /**
+ * Get all registered strategies.
+ *
+ * @return the registered strategy instances. No inherit order is returned;
+ * the caller may modify (and/or sort) the returned array if
+ * necessary to obtain a reasonable ordering.
+ */
+ public static synchronized MergeStrategy[] get() {
+ final MergeStrategy[] r = new MergeStrategy[STRATEGIES.size()];
+ STRATEGIES.values().toArray(r);
+ return r;
+ }
+
+ /** @return default name of this strategy implementation. */
+ public abstract String getName();
+
+ /**
+ * Create a new merge instance.
+ *
+ * @param db
+ * repository database the merger will read from, and eventually
+ * write results back to.
+ * @return the new merge instance which implements this strategy.
+ */
+ public abstract Merger newMerger(Repository db);
+}
diff --git a/org.spearce.jgit/src/org/spearce/jgit/merge/Merger.java b/org.spearce.jgit/src/org/spearce/jgit/merge/Merger.java
new file mode 100644
index 0000000..04990a1
--- /dev/null
+++ b/org.spearce.jgit/src/org/spearce/jgit/merge/Merger.java
@@ -0,0 +1,213 @@
+/*
+ * Copyright (C) 2008, Google Inc.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Git Development Community nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.spearce.jgit.merge;
+
+import java.io.IOException;
+
+import org.spearce.jgit.errors.IncorrectObjectTypeException;
+import org.spearce.jgit.lib.AnyObjectId;
+import org.spearce.jgit.lib.Constants;
+import org.spearce.jgit.lib.ObjectId;
+import org.spearce.jgit.lib.ObjectWriter;
+import org.spearce.jgit.lib.Repository;
+import org.spearce.jgit.lib.WindowCursor;
+import org.spearce.jgit.revwalk.RevCommit;
+import org.spearce.jgit.revwalk.RevObject;
+import org.spearce.jgit.revwalk.RevTree;
+import org.spearce.jgit.revwalk.RevWalk;
+import org.spearce.jgit.revwalk.filter.RevFilter;
+import org.spearce.jgit.treewalk.AbstractTreeIterator;
+import org.spearce.jgit.treewalk.CanonicalTreeParser;
+import org.spearce.jgit.treewalk.EmptyTreeIterator;
+
+/**
+ * Instance of a specific {@link MergeStrategy} for a single {@link Repository}.
+ */
+public abstract class Merger {
+ /** The repository this merger operates on. */
+ protected final Repository db;
+
+ /** A RevWalk for computing merge bases, or listing incoming commits. */
+ protected final RevWalk walk;
+
+ private ObjectWriter writer;
+
+ /** The original objects supplied in the merge; this can be any tree-ish. */
+ protected RevObject[] sourceObjects;
+
+ /** If {@link #sourceObjects}[i] is a commit, this is the commit. */
+ protected RevCommit[] sourceCommits;
+
+ /** The trees matching every entry in {@link #sourceObjects}. */
+ protected RevTree[] sourceTrees;
+
+ /**
+ * Create a new merge instance for a repository.
+ *
+ * @param local
+ * the repository this merger will read and write data on.
+ */
+ protected Merger(final Repository local) {
+ db = local;
+ walk = new RevWalk(db);
+ }
+
+ /**
+ * @return the repository this merger operates on.
+ */
+ public Repository getRepository() {
+ return db;
+ }
+
+ /**
+ * @return an object writer to create objects in {@link #getRepository()}.
+ */
+ public ObjectWriter getObjectWriter() {
+ if (writer == null)
+ writer = new ObjectWriter(getRepository());
+ return writer;
+ }
+
+ /**
+ * Merge together two or more tree-ish objects.
+ * <p>
+ * Any tree-ish may be supplied as inputs. Commits and/or tags pointing at
+ * trees or commits may be passed as input objects.
+ *
+ * @param tips
+ * source trees to be combined together. The merge base is not
+ * included in this set.
+ * @return true if the merge was completed without conflicts; false if the
+ * merge strategy cannot handle this merge or there were conflicts
+ * preventing it from automatically resolving all paths.
+ * @throws IncorrectObjectTypeException
+ * one of the input objects is not a commit, but the strategy
+ * requires it to be a commit.
+ * @throws IOException
+ * one or more sources could not be read, or outputs could not
+ * be written to the Repository.
+ */
+ public final boolean merge(final AnyObjectId[] tips) throws IOException {
+ sourceObjects = new RevObject[tips.length];
+ for (int i = 0; i < tips.length; i++)
+ sourceObjects[i] = walk.parseAny(tips[i]);
+
+ sourceCommits = new RevCommit[sourceObjects.length];
+ for (int i = 0; i < sourceObjects.length; i++) {
+ try {
+ sourceCommits[i] = walk.parseCommit(sourceObjects[i]);
+ } catch (IncorrectObjectTypeException err) {
+ sourceCommits[i] = null;
+ }
+ }
+
+ sourceTrees = new RevTree[sourceObjects.length];
+ for (int i = 0; i < sourceObjects.length; i++)
+ sourceTrees[i] = walk.parseTree(sourceObjects[i]);
+
+ return mergeImpl();
+ }
+
+ /**
+ * Create an iterator to walk the merge base of two commits.
+ *
+ * @param aIdx
+ * index of the first commit in {@link #sourceObjects}.
+ * @param bIdx
+ * index of the second commit in {@link #sourceObjects}.
+ * @return the new iterator
+ * @throws IncorrectObjectTypeException
+ * one of the input objects is not a commit.
+ * @throws IOException
+ * objects are missing or multiple merge bases were found.
+ */
+ protected AbstractTreeIterator mergeBase(final int aIdx, final int bIdx)
+ throws IOException {
+ if (sourceCommits[aIdx] == null)
+ throw new IncorrectObjectTypeException(sourceObjects[aIdx],
+ Constants.TYPE_COMMIT);
+ if (sourceCommits[bIdx] == null)
+ throw new IncorrectObjectTypeException(sourceObjects[bIdx],
+ Constants.TYPE_COMMIT);
+
+ walk.reset();
+ walk.setRevFilter(RevFilter.MERGE_BASE);
+ walk.markStart(sourceCommits[aIdx]);
+ walk.markStart(sourceCommits[bIdx]);
+ final RevCommit base = walk.next();
+ if (base == null)
+ return new EmptyTreeIterator();
+ final RevCommit base2 = walk.next();
+ if (base2 != null) {
+ throw new IOException("Multiple merge bases for:" + "\n "
+ + sourceCommits[aIdx].name() + "\n "
+ + sourceCommits[bIdx].name() + "found:" + "\n "
+ + base.name() + "\n " + base2.name());
+ }
+ final WindowCursor curs = new WindowCursor();
+ try {
+ return new CanonicalTreeParser(null, db, base.getTree(), curs);
+ } finally {
+ curs.release();
+ }
+ }
+
+ /**
+ * Execute the merge.
+ * <p>
+ * This method is called from {@link #merge(AnyObjectId[])} after the
+ * {@link #sourceObjects}, {@link #sourceCommits} and {@link #sourceTrees}
+ * have been populated.
+ *
+ * @return true if the merge was completed without conflicts; false if the
+ * merge strategy cannot handle this merge or there were conflicts
+ * preventing it from automatically resolving all paths.
+ * @throws IncorrectObjectTypeException
+ * one of the input objects is not a commit, but the strategy
+ * requires it to be a commit.
+ * @throws IOException
+ * one or more sources could not be read, or outputs could not
+ * be written to the Repository.
+ */
+ protected abstract boolean mergeImpl() throws IOException;
+
+ /**
+ * @return resulting tree, if {@link #merge(AnyObjectId[])} returned true.
+ */
+ public abstract ObjectId getResultTreeId();
+}
diff --git a/org.spearce.jgit/src/org/spearce/jgit/merge/StrategyOneSided.java b/org.spearce.jgit/src/org/spearce/jgit/merge/StrategyOneSided.java
new file mode 100644
index 0000000..0c3dcc2
--- /dev/null
+++ b/org.spearce.jgit/src/org/spearce/jgit/merge/StrategyOneSided.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2008, Google Inc.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Git Development Community nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.spearce.jgit.merge;
+
+import java.io.IOException;
+
+import org.spearce.jgit.lib.ObjectId;
+import org.spearce.jgit.lib.Repository;
+
+/**
+ * Trivial merge strategy to make the resulting tree exactly match an input.
+ * <p>
+ * This strategy can be used to cauterize an entire side branch of history, by
+ * setting the output tree to one of the inputs, and ignoring any of the paths
+ * of the other inputs.
+ */
+public class StrategyOneSided extends MergeStrategy {
+ private final String strategyName;
+
+ private final int treeIndex;
+
+ /**
+ * Create a new merge strategy to select a specific input tree.
+ *
+ * @param name
+ * name of this strategy.
+ * @param index
+ * the position of the input tree to accept as the result.
+ */
+ protected StrategyOneSided(final String name, final int index) {
+ strategyName = name;
+ treeIndex = index;
+ }
+
+ @Override
+ public String getName() {
+ return strategyName;
+ }
+
+ @Override
+ public Merger newMerger(final Repository db) {
+ return new OneSide(db, treeIndex);
+ }
+
+ protected static class OneSide extends Merger {
+ private final int treeIndex;
+
+ protected OneSide(final Repository local, final int index) {
+ super(local);
+ treeIndex = index;
+ }
+
+ @Override
+ protected boolean mergeImpl() throws IOException {
+ return treeIndex < sourceTrees.length;
+ }
+
+ @Override
+ public ObjectId getResultTreeId() {
+ return sourceTrees[treeIndex];
+ }
+ }
+}
diff --git a/org.spearce.jgit/src/org/spearce/jgit/merge/StrategySimpleTwoWayInCore.java b/org.spearce.jgit/src/org/spearce/jgit/merge/StrategySimpleTwoWayInCore.java
new file mode 100644
index 0000000..893add9
--- /dev/null
+++ b/org.spearce.jgit/src/org/spearce/jgit/merge/StrategySimpleTwoWayInCore.java
@@ -0,0 +1,179 @@
+/*
+ * Copyright (C) 2008, Google Inc.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Git Development Community nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.spearce.jgit.merge;
+
+import java.io.IOException;
+
+import org.spearce.jgit.dircache.DirCache;
+import org.spearce.jgit.dircache.DirCacheBuilder;
+import org.spearce.jgit.dircache.DirCacheEntry;
+import org.spearce.jgit.errors.UnmergedPathException;
+import org.spearce.jgit.lib.ObjectId;
+import org.spearce.jgit.lib.Repository;
+import org.spearce.jgit.treewalk.AbstractTreeIterator;
+import org.spearce.jgit.treewalk.NameConflictTreeWalk;
+
+/**
+ * Merges two commits together in-memory, ignoring any working directory.
+ * <p>
+ * The strategy chooses a path from one of the two input trees if the path is
+ * unchanged in the other relative to their common merge base tree. This is a
+ * trivial 3-way merge (at the file path level only).
+ * <p>
+ * Modifications of the same file path (content and/or file mode) by both input
+ * trees will cause a merge conflict, as this strategy does not attempt to merge
+ * file contents.
+ */
+public class StrategySimpleTwoWayInCore extends MergeStrategy {
+ static final MergeStrategy INSTANCE = new StrategySimpleTwoWayInCore();
+
+ /** Create a new instance of the strategy. */
+ protected StrategySimpleTwoWayInCore() {
+ //
+ }
+
+ @Override
+ public String getName() {
+ return "simple-two-way-in-core";
+ }
+
+ @Override
+ public Merger newMerger(final Repository db) {
+ return new InCoreMerger(db);
+ }
+
+ private static class InCoreMerger extends Merger {
+ private static final int T_BASE = 0;
+
+ private static final int T_OURS = 1;
+
+ private static final int T_THEIRS = 2;
+
+ private final NameConflictTreeWalk tw;
+
+ private final DirCache cache;
+
+ private DirCacheBuilder builder;
+
+ private ObjectId resultTree;
+
+ InCoreMerger(final Repository local) {
+ super(local);
+ tw = new NameConflictTreeWalk(db);
+ cache = DirCache.newInCore();
+ }
+
+ @Override
+ protected boolean mergeImpl() throws IOException {
+ if (sourceTrees.length != 2)
+ return false;
+
+ tw.reset();
+ tw.addTree(mergeBase(0, 1));
+ tw.addTree(sourceTrees[0]);
+ tw.addTree(sourceTrees[1]);
+
+ boolean hasConflict = false;
+ builder = cache.builder();
+ while (tw.next()) {
+ final int modeO = tw.getRawMode(T_OURS);
+ final int modeT = tw.getRawMode(T_THEIRS);
+ if (modeO == modeT && tw.idEqual(T_OURS, T_THEIRS)) {
+ same();
+ continue;
+ }
+
+ final int modeB = tw.getRawMode(T_BASE);
+ if (modeB == modeO && tw.idEqual(T_BASE, T_OURS))
+ add(T_THEIRS, DirCacheEntry.STAGE_0);
+ else if (modeB == modeT && tw.idEqual(T_BASE, T_THEIRS))
+ add(T_OURS, DirCacheEntry.STAGE_0);
+ else {
+ conflict();
+ hasConflict = true;
+ }
+ }
+ builder.finish();
+ builder = null;
+
+ if (hasConflict)
+ return false;
+ try {
+ resultTree = cache.writeTree(getObjectWriter());
+ return true;
+ } catch (UnmergedPathException upe) {
+ resultTree = null;
+ return false;
+ }
+ }
+
+ private void same() throws IOException {
+ if (tw.isSubtree())
+ builder.addTree(tw.getRawPath(), db, tw.getObjectId(1));
+ else
+ add(T_OURS, DirCacheEntry.STAGE_0);
+ }
+
+ private void conflict() {
+ add(T_BASE, DirCacheEntry.STAGE_1);
+ add(T_OURS, DirCacheEntry.STAGE_2);
+ add(T_THEIRS, DirCacheEntry.STAGE_3);
+ }
+
+ private void add(final int tree, final int stage) {
+ final AbstractTreeIterator i = getTree(tree);
+ if (i != null) {
+ final DirCacheEntry e;
+
+ e = new DirCacheEntry(tw.getRawPath(), stage);
+ e.setObjectIdFromRaw(i.idBuffer(), i.idOffset());
+ e.setFileMode(tw.getFileMode(tree));
+ builder.add(e);
+ }
+ }
+
+ private AbstractTreeIterator getTree(final int tree) {
+ return tw.getTree(tree, AbstractTreeIterator.class);
+ }
+
+ @Override
+ public ObjectId getResultTreeId() {
+ return resultTree;
+ }
+ }
+}
--
1.6.1.399.g0d272
^ permalink raw reply related
* [JGIT PATCH 08/10] Allow DirCacheEntry instances to be created with stage > 0
From: Shawn O. Pearce @ 2009-01-22 23:28 UTC (permalink / raw)
To: Robin Rosenberg; +Cc: git
In-Reply-To: <1232666890-23488-8-git-send-email-spearce@spearce.org>
As the stage is part of the sorting criteria for DirCacheEntry
objects we don't allow the stage to be modified on the fly in
an existing instance. Instead the stage must be set by reading
it from the on-disk format or by creating a new entry with the
proper path and stage components.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
.../org/spearce/jgit/dircache/DirCacheEntry.java | 52 +++++++++++++++++---
1 files changed, 45 insertions(+), 7 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCacheEntry.java b/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCacheEntry.java
index 355cd3e..9304501 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCacheEntry.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCacheEntry.java
@@ -60,6 +60,18 @@
public class DirCacheEntry {
private static final byte[] nullpad = new byte[8];
+ /** The standard (fully merged) stage for an entry. */
+ public static final int STAGE_0 = 0;
+
+ /** The base tree revision for an entry. */
+ public static final int STAGE_1 = 1;
+
+ /** The first tree revision (usually called "ours"). */
+ public static final int STAGE_2 = 2;
+
+ /** The second tree revision (usually called "theirs"). */
+ public static final int STAGE_3 = 3;
+
// private static final int P_CTIME = 0;
// private static final int P_CTIME_NSEC = 4;
@@ -141,8 +153,8 @@ DirCacheEntry(final byte[] sharedInfo, final int infoAt,
}
/**
- * Create an empty entry.
- *
+ * Create an empty entry at stage 0.
+ *
* @param newPath
* name of the cache entry.
*/
@@ -151,20 +163,46 @@ public DirCacheEntry(final String newPath) {
}
/**
- * Create an empty entry.
- *
+ * Create an empty entry at the specified stage.
+ *
+ * @param newPath
+ * name of the cache entry.
+ * @param stage
+ * the stage index of the new entry.
+ */
+ public DirCacheEntry(final String newPath, final int stage) {
+ this(Constants.encode(newPath), stage);
+ }
+
+ /**
+ * Create an empty entry at stage 0.
+ *
* @param newPath
* name of the cache entry, in the standard encoding.
*/
public DirCacheEntry(final byte[] newPath) {
+ this(newPath, STAGE_0);
+ }
+
+ /**
+ * Create an empty entry at the specified stage.
+ *
+ * @param newPath
+ * name of the cache entry, in the standard encoding.
+ * @param stage
+ * the stage index of the new entry.
+ */
+ public DirCacheEntry(final byte[] newPath, final int stage) {
info = new byte[INFO_LEN];
infoOffset = 0;
-
path = newPath;
+
+ int flags = ((stage & 0x3) << 12);
if (path.length < NAME_MASK)
- NB.encodeInt16(info, infoOffset + P_FLAGS, path.length);
+ flags |= path.length;
else
- NB.encodeInt16(info, infoOffset + P_FLAGS, NAME_MASK);
+ flags |= NAME_MASK;
+ NB.encodeInt16(info, infoOffset + P_FLAGS, flags);
}
void write(final OutputStream os) throws IOException {
--
1.6.1.399.g0d272
^ permalink raw reply related
* [JGIT PATCH 05/10] Allow a DirCache to be created with no backing store file
From: Shawn O. Pearce @ 2009-01-22 23:28 UTC (permalink / raw)
To: Robin Rosenberg; +Cc: git
In-Reply-To: <1232666890-23488-5-git-send-email-spearce@spearce.org>
This permits using a DirCache as a temporary storage area in memory
only, with no chance of it being written out to disk.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
.../src/org/spearce/jgit/dircache/DirCache.java | 17 +++++++++++++++++
1 files changed, 17 insertions(+), 0 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCache.java b/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCache.java
index b3c57ad..c5a4f91 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCache.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCache.java
@@ -111,6 +111,17 @@ static int cmp(final byte[] aPath, final int aLen, final byte[] bPath,
}
/**
+ * Create a new empty index which is never stored on disk.
+ *
+ * @return an empty cache which has no backing store file. The cache may not
+ * be read or written, but it may be queried and updated (in
+ * memory).
+ */
+ public static DirCache newInCore() {
+ return new DirCache(null);
+ }
+
+ /**
* Create a new in-core index representation and read an index from disk.
* <p>
* The new index will be read before it is returned to the caller. Read
@@ -297,6 +308,8 @@ void replace(final DirCacheEntry[] e, final int cnt) {
* library does not support.
*/
public void read() throws IOException, CorruptObjectException {
+ if (liveFile == null)
+ throw new IOException("DirCache does not have a backing file");
if (!liveFile.exists())
clear();
else if (liveFile.lastModified() != lastModified) {
@@ -407,6 +420,8 @@ private static boolean is_DIRC(final byte[] hdr) {
* hold the lock.
*/
public boolean lock() throws IOException {
+ if (liveFile == null)
+ throw new IOException("DirCache does not have a backing file");
final LockFile tmp = new LockFile(liveFile);
if (tmp.lock()) {
tmp.setNeedStatInformation(true);
@@ -515,6 +530,8 @@ public boolean commit() {
}
private void requireLocked(final LockFile tmp) {
+ if (liveFile == null)
+ throw new IllegalStateException("DirCache is not locked");
if (tmp == null)
throw new IllegalStateException("DirCache "
+ liveFile.getAbsolutePath() + " not locked.");
--
1.6.1.399.g0d272
^ permalink raw reply related
* [JGIT PATCH 07/10] Recursively load an entire tree into a DirCacheBuilder
From: Shawn O. Pearce @ 2009-01-22 23:28 UTC (permalink / raw)
To: Robin Rosenberg; +Cc: git
In-Reply-To: <1232666890-23488-7-git-send-email-spearce@spearce.org>
This implements the DirCache portion of "git read-tree", where a
tree can be recursively read into a DirCache instance without an
impact on the working directory.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
.../org/spearce/jgit/dircache/DirCacheBuilder.java | 65 ++++++++++++++++++++
1 files changed, 65 insertions(+), 0 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCacheBuilder.java b/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCacheBuilder.java
index 3a37054..10161fa 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCacheBuilder.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCacheBuilder.java
@@ -37,8 +37,16 @@
package org.spearce.jgit.dircache;
+import java.io.IOException;
import java.util.Arrays;
+import org.spearce.jgit.lib.AnyObjectId;
+import org.spearce.jgit.lib.Repository;
+import org.spearce.jgit.lib.WindowCursor;
+import org.spearce.jgit.treewalk.AbstractTreeIterator;
+import org.spearce.jgit.treewalk.CanonicalTreeParser;
+import org.spearce.jgit.treewalk.TreeWalk;
+
/**
* Updates a {@link DirCache} by adding individual {@link DirCacheEntry}s.
* <p>
@@ -112,6 +120,63 @@ public void keep(final int pos, int cnt) {
fastKeep(pos, cnt);
}
+ /**
+ * Recursively add an entire tree into this builder.
+ * <p>
+ * If pathPrefix is "a/b" and the tree contains file "c" then the resulting
+ * DirCacheEntry will have the path "a/b/c".
+ * <p>
+ * All entries are inserted at stage 0, therefore assuming that the
+ * application will not insert any other paths with the same pathPrefix.
+ *
+ * @param pathPrefix
+ * UTF-8 encoded prefix to mount the tree's entries at. If the
+ * path does not end with '/' one will be automatically inserted
+ * as necessary.
+ * @param db
+ * repository the tree(s) will be read from during recursive
+ * traversal. This must be the same repository that the resulting
+ * DirCache would be written out to (or used in) otherwise the
+ * caller is simply asking for deferred MissingObjectExceptions.
+ * @param tree
+ * the tree to recursively add. This tree's contents will appear
+ * under <code>pathPrefix</code>. The ObjectId must be that of a
+ * tree; the caller is responsible for dereferencing a tag or
+ * commit (if necessary).
+ * @throws IOException
+ * a tree cannot be read to iterate through its entries.
+ */
+ public void addTree(final byte[] pathPrefix, final Repository db,
+ final AnyObjectId tree) throws IOException {
+ final TreeWalk tw = new TreeWalk(db);
+ tw.reset();
+ final WindowCursor curs = new WindowCursor();
+ try {
+ tw.addTree(new CanonicalTreeParser(pathPrefix, db, tree
+ .toObjectId(), curs));
+ } finally {
+ curs.release();
+ }
+ tw.setRecursive(true);
+ if (tw.next()) {
+ final DirCacheEntry newEntry = toEntry(tw);
+ beforeAdd(newEntry);
+ fastAdd(newEntry);
+ while (tw.next())
+ fastAdd(toEntry(tw));
+ }
+ }
+
+ private DirCacheEntry toEntry(final TreeWalk tw) {
+ final DirCacheEntry e = new DirCacheEntry(tw.getRawPath());
+ final AbstractTreeIterator i;
+
+ i = tw.getTree(0, AbstractTreeIterator.class);
+ e.setFileMode(tw.getFileMode(0));
+ e.setObjectIdFromRaw(i.idBuffer(), i.idOffset());
+ return e;
+ }
+
public void finish() {
if (!sorted)
resort();
--
1.6.1.399.g0d272
^ permalink raw reply related
* [JGIT PATCH 04/10] Add writeTree support to DirCache
From: Shawn O. Pearce @ 2009-01-22 23:28 UTC (permalink / raw)
To: Robin Rosenberg; +Cc: git
In-Reply-To: <1232666890-23488-4-git-send-email-spearce@spearce.org>
This way we can write a full tree from the DirCache, including reusing
any valid tree entries stored within the 'TREE' cache extension. By
reusing those entries we can avoid generating the tree objects that
are already stored in the Git repository.
The algorithm may cause up to 3 passes over the DirCache entries:
* Pass 1: Compute the tree structure
* Pass 2: Compute the sizes of each tree
* Pass 3: Write the tree object to the object store
These extra passes cause more CPU time to be expended in exchange
for a lower memory requirement during the tree writing. The code
is only formatting the lowest level leaf tree which has not yet
been written to the object store, so higher level trees do not
occupy memory while they are waiting for the leaves to write out.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
.../src/org/spearce/jgit/dircache/DirCache.java | 20 ++++
.../org/spearce/jgit/dircache/DirCacheTree.java | 115 ++++++++++++++++++++
.../spearce/jgit/errors/UnmergedPathException.java | 67 ++++++++++++
.../src/org/spearce/jgit/lib/FileMode.java | 7 ++
.../src/org/spearce/jgit/lib/ObjectWriter.java | 12 ++-
5 files changed, 219 insertions(+), 2 deletions(-)
create mode 100644 org.spearce.jgit/src/org/spearce/jgit/errors/UnmergedPathException.java
diff --git a/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCache.java b/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCache.java
index 76657c4..b3c57ad 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCache.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCache.java
@@ -51,8 +51,11 @@
import java.util.Comparator;
import org.spearce.jgit.errors.CorruptObjectException;
+import org.spearce.jgit.errors.UnmergedPathException;
import org.spearce.jgit.lib.Constants;
import org.spearce.jgit.lib.LockFile;
+import org.spearce.jgit.lib.ObjectId;
+import org.spearce.jgit.lib.ObjectWriter;
import org.spearce.jgit.lib.Repository;
import org.spearce.jgit.util.MutableInteger;
import org.spearce.jgit.util.NB;
@@ -692,4 +695,21 @@ public DirCacheTree getCacheTree(final boolean build) {
}
return tree;
}
+
+ /**
+ * Write all index trees to the object store, returning the root tree.
+ *
+ * @param ow
+ * the writer to use when serializing to the store.
+ * @return identity for the root tree.
+ * @throws UnmergedPathException
+ * one or more paths contain higher-order stages (stage > 0),
+ * which cannot be stored in a tree object.
+ * @throws IOException
+ * an unexpected error occurred writing to the object store.
+ */
+ public ObjectId writeTree(final ObjectWriter ow)
+ throws UnmergedPathException, IOException {
+ return getCacheTree(true).writeTree(sortedEntries, 0, 0, ow);
+ }
}
diff --git a/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCacheTree.java b/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCacheTree.java
index 26b6348..cf96ded 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCacheTree.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/dircache/DirCacheTree.java
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
+ * Copyright (C) 2008, Google Inc.
*
* All rights reserved.
*
@@ -37,14 +38,20 @@
package org.spearce.jgit.dircache;
+import static org.spearce.jgit.lib.Constants.OBJECT_ID_LENGTH;
+
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Comparator;
+import org.spearce.jgit.errors.UnmergedPathException;
import org.spearce.jgit.lib.Constants;
+import org.spearce.jgit.lib.FileMode;
import org.spearce.jgit.lib.ObjectId;
+import org.spearce.jgit.lib.ObjectWriter;
import org.spearce.jgit.util.MutableInteger;
import org.spearce.jgit.util.RawParseUtils;
@@ -273,6 +280,114 @@ public String getPathString() {
return r.toString();
}
+ /**
+ * Write (if necessary) this tree to the object store.
+ *
+ * @param cache
+ * the complete cache from DirCache.
+ * @param cIdx
+ * first position of <code>cache</code> that is a member of this
+ * tree. The path of <code>cache[cacheIdx].path</code> for the
+ * range <code>[0,pathOff-1)</code> matches the complete path of
+ * this tree, from the root of the repository.
+ * @param pathOffset
+ * number of bytes of <code>cache[cacheIdx].path</code> that
+ * matches this tree's path. The value at array position
+ * <code>cache[cacheIdx].path[pathOff-1]</code> is always '/' if
+ * <code>pathOff</code> is > 0.
+ * @param ow
+ * the writer to use when serializing to the store.
+ * @return identity of this tree.
+ * @throws UnmergedPathException
+ * one or more paths contain higher-order stages (stage > 0),
+ * which cannot be stored in a tree object.
+ * @throws IOException
+ * an unexpected error occurred writing to the object store.
+ */
+ ObjectId writeTree(final DirCacheEntry[] cache, int cIdx,
+ final int pathOffset, final ObjectWriter ow)
+ throws UnmergedPathException, IOException {
+ if (id == null) {
+ final int endIdx = cIdx + entrySpan;
+ final int size = computeSize(cache, cIdx, pathOffset, ow);
+ final ByteArrayOutputStream out = new ByteArrayOutputStream(size);
+ int childIdx = 0;
+ int entryIdx = cIdx;
+
+ while (entryIdx < endIdx) {
+ final DirCacheEntry e = cache[entryIdx];
+ final byte[] ep = e.path;
+ if (childIdx < childCnt) {
+ final DirCacheTree st = children[childIdx];
+ if (st.contains(ep, pathOffset, ep.length)) {
+ FileMode.TREE.copyTo(out);
+ out.write(' ');
+ out.write(st.encodedName);
+ out.write(0);
+ st.id.copyRawTo(out);
+
+ entryIdx += st.entrySpan;
+ childIdx++;
+ continue;
+ }
+ }
+
+ e.getFileMode().copyTo(out);
+ out.write(' ');
+ out.write(ep, pathOffset, ep.length - pathOffset);
+ out.write(0);
+ out.write(e.idBuffer(), e.idOffset(), OBJECT_ID_LENGTH);
+ entryIdx++;
+ }
+
+ id = ow.writeCanonicalTree(out.toByteArray());
+ }
+ return id;
+ }
+
+ private int computeSize(final DirCacheEntry[] cache, int cIdx,
+ final int pathOffset, final ObjectWriter ow)
+ throws UnmergedPathException, IOException {
+ final int endIdx = cIdx + entrySpan;
+ int childIdx = 0;
+ int entryIdx = cIdx;
+ int size = 0;
+
+ while (entryIdx < endIdx) {
+ final DirCacheEntry e = cache[entryIdx];
+ if (e.getStage() != 0)
+ throw new UnmergedPathException(e);
+
+ final byte[] ep = e.path;
+ if (childIdx < childCnt) {
+ final DirCacheTree st = children[childIdx];
+ if (st.contains(ep, pathOffset, ep.length)) {
+ final int stOffset = pathOffset + st.nameLength() + 1;
+ st.writeTree(cache, entryIdx, stOffset, ow);
+
+ size += FileMode.TREE.copyToLength();
+ size += st.nameLength();
+ size += OBJECT_ID_LENGTH + 2;
+
+ entryIdx += st.entrySpan;
+ childIdx++;
+ continue;
+ }
+ }
+
+ final FileMode mode = e.getFileMode();
+ if (mode.getObjectType() == Constants.OBJ_BAD)
+ throw new UnmergedPathException(e);
+
+ size += mode.copyToLength();
+ size += ep.length - pathOffset;
+ size += OBJECT_ID_LENGTH + 2;
+ entryIdx++;
+ }
+
+ return size;
+ }
+
private void appendName(final StringBuilder r) {
if (parent != null) {
parent.appendName(r);
diff --git a/org.spearce.jgit/src/org/spearce/jgit/errors/UnmergedPathException.java b/org.spearce.jgit/src/org/spearce/jgit/errors/UnmergedPathException.java
new file mode 100644
index 0000000..17a3965
--- /dev/null
+++ b/org.spearce.jgit/src/org/spearce/jgit/errors/UnmergedPathException.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2008, Google Inc.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Git Development Community nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.spearce.jgit.errors;
+
+import java.io.IOException;
+
+import org.spearce.jgit.dircache.DirCacheEntry;
+
+/**
+ * Indicates one or more paths in a DirCache have non-zero stages present.
+ */
+public class UnmergedPathException extends IOException {
+ private static final long serialVersionUID = 1L;
+
+ private final DirCacheEntry entry;
+
+ /**
+ * Create a new unmerged path exception.
+ *
+ * @param dce
+ * the first non-zero stage of the unmerged path.
+ */
+ public UnmergedPathException(final DirCacheEntry dce) {
+ super("Unmerged path: " + dce.getPathString());
+ entry = dce;
+ }
+
+ /** @return the first non-zero stage of the unmerged path */
+ public DirCacheEntry getDirCacheEntry() {
+ return entry;
+ }
+}
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/FileMode.java b/org.spearce.jgit/src/org/spearce/jgit/lib/FileMode.java
index fe5f2f6..cf42f37 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/FileMode.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/FileMode.java
@@ -191,6 +191,13 @@ public void copyTo(final OutputStream os) throws IOException {
}
/**
+ * @return the number of bytes written by {@link #copyTo(OutputStream)}.
+ */
+ public int copyToLength() {
+ return octalBytes.length;
+ }
+
+ /**
* Get the object type that should appear for this type of mode.
* <p>
* See the object type constants in {@link Constants}.
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectWriter.java b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectWriter.java
index e84798a..546cc68 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectWriter.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectWriter.java
@@ -155,10 +155,18 @@ public ObjectId writeTree(final Tree t) throws IOException {
o.write(0);
id.copyRawTo(o);
}
- return writeTree(o.toByteArray());
+ return writeCanonicalTree(o.toByteArray());
}
- private ObjectId writeTree(final byte[] b) throws IOException {
+ /**
+ * Write a canonical tree to the object database.
+ *
+ * @param b
+ * the canonical encoding of the tree object.
+ * @return SHA-1 of the tree
+ * @throws IOException
+ */
+ public ObjectId writeCanonicalTree(final byte[] b) throws IOException {
return writeTree(b.length, new ByteArrayInputStream(b));
}
--
1.6.1.399.g0d272
^ permalink raw reply related
* [JGIT PATCH 06/10] Allow CanonicalTreeParsers to be created with a UTF-8 path prefix
From: Shawn O. Pearce @ 2009-01-22 23:28 UTC (permalink / raw)
To: Robin Rosenberg; +Cc: git
In-Reply-To: <1232666890-23488-6-git-send-email-spearce@spearce.org>
Creating an iterator with a path prefix permits a tree to be
"mounted" at a different part of a repository, permitting more
sophisticated merge strategies beyond just 1:1 path matching.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
.../jgit/treewalk/AbstractTreeIterator.java | 31 ++++++++++++++++++++
.../spearce/jgit/treewalk/CanonicalTreeParser.java | 30 +++++++++++++++++++
.../src/org/spearce/jgit/treewalk/TreeWalk.java | 2 +-
3 files changed, 62 insertions(+), 1 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java
index 791056c..62ca69c 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/AbstractTreeIterator.java
@@ -172,6 +172,37 @@ protected AbstractTreeIterator(final String prefix) {
}
/**
+ * Create a new iterator with no parent and a prefix.
+ * <p>
+ * The prefix path supplied is inserted in front of all paths generated by
+ * this iterator. It is intended to be used when an iterator is being
+ * created for a subsection of an overall repository and needs to be
+ * combined with other iterators that are created to run over the entire
+ * repository namespace.
+ *
+ * @param prefix
+ * position of this iterator in the repository tree. The value
+ * may be null or the empty array to indicate the prefix is the
+ * root of the repository. A trailing slash ('/') is
+ * automatically appended if the prefix does not end in '/'.
+ */
+ protected AbstractTreeIterator(final byte[] prefix) {
+ parent = null;
+
+ if (prefix != null && prefix.length > 0) {
+ pathLen = prefix.length;
+ path = new byte[Math.max(DEFAULT_PATH_SIZE, pathLen + 1)];
+ System.arraycopy(prefix, 0, path, 0, pathLen);
+ if (path[pathLen - 1] != '/')
+ path[pathLen++] = '/';
+ pathOffset = pathLen;
+ } else {
+ path = new byte[DEFAULT_PATH_SIZE];
+ pathOffset = 0;
+ }
+ }
+
+ /**
* Create an iterator for a subtree of an existing iterator.
*
* @param p
diff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/CanonicalTreeParser.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/CanonicalTreeParser.java
index 2bcf792..ed883bd 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/treewalk/CanonicalTreeParser.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/CanonicalTreeParser.java
@@ -67,6 +67,36 @@ public CanonicalTreeParser() {
raw = EMPTY;
}
+ /**
+ * Create a new parser for a tree appearing in a subset of a repository.
+ *
+ * @param prefix
+ * position of this iterator in the repository tree. The value
+ * may be null or the empty array to indicate the prefix is the
+ * root of the repository. A trailing slash ('/') is
+ * automatically appended if the prefix does not end in '/'.
+ * @param repo
+ * repository to load the tree data from.
+ * @param treeId
+ * identity of the tree being parsed; used only in exception
+ * messages if data corruption is found.
+ * @param curs
+ * a window cursor to use during data access from the repository.
+ * @throws MissingObjectException
+ * the object supplied is not available from the repository.
+ * @throws IncorrectObjectTypeException
+ * the object supplied as an argument is not actually a tree and
+ * cannot be parsed as though it were a tree.
+ * @throws IOException
+ * a loose object or pack file could not be read.
+ */
+ public CanonicalTreeParser(final byte[] prefix, final Repository repo,
+ final ObjectId treeId, final WindowCursor curs)
+ throws IncorrectObjectTypeException, IOException {
+ super(prefix);
+ reset(repo, treeId, curs);
+ }
+
private CanonicalTreeParser(final CanonicalTreeParser p) {
super(p);
}
diff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java
index 22040e3..416e027 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/TreeWalk.java
@@ -354,7 +354,7 @@ public void reset(final AnyObjectId[] ids) throws MissingObjectException,
o = trees[i];
while (o.parent != null)
o = o.parent;
- if (o instanceof CanonicalTreeParser) {
+ if (o instanceof CanonicalTreeParser && o.pathOffset == 0) {
o.matches = null;
o.matchShift = 0;
((CanonicalTreeParser) o).reset(db, ids[i], curs);
--
1.6.1.399.g0d272
^ permalink raw reply related
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox