diff --git a/commit.c b/commit.c index 0737915d20..754d1b8a0b 100644 --- a/commit.c +++ b/commit.c @@ -1263,10 +1263,25 @@ static struct commit *interesting(struct commit_list *list) return NULL; } -static struct commit_list *base_traverse(struct commit_list *list, struct commit *stop) +static struct commit_list *merge_bases(struct commit *one, struct commit *two) { + struct commit_list *list = NULL; struct commit_list *result = NULL; + if (one == two) + /* We do not mark this even with RESULT so we do not + * have to clean it up. + */ + return commit_list_insert(one, &result); + + parse_commit(one); + parse_commit(two); + + one->object.flags |= PARENT1; + two->object.flags |= PARENT2; + insert_by_date(one, &list); + insert_by_date(two, &list); + while (interesting(list)) { struct commit *commit; struct commit_list *parents; @@ -1297,20 +1312,10 @@ static struct commit_list *base_traverse(struct commit_list *list, struct commit p->object.flags |= flags; insert_by_date(p, &list); } - if (stop && (stop->object.flags & PARENT2)) { - free_commit_list(list); - list = NULL; - insert_by_date(stop, &list); - return list; - } } /* Clean up the result to remove stale ones */ free_commit_list(list); - - if (stop) - return NULL; - list = result; result = NULL; while (list) { struct commit_list *n = list->next; @@ -1322,27 +1327,6 @@ static struct commit_list *base_traverse(struct commit_list *list, struct commit return result; } -static struct commit_list *merge_bases(struct commit *one, struct commit *two) -{ - struct commit_list *list = NULL; - - if (one == two) - /* We do not mark this even with RESULT so we do not - * have to clean it up. - */ - return commit_list_insert(one, &list); - - parse_commit(one); - parse_commit(two); - - one->object.flags |= PARENT1; - two->object.flags |= PARENT2; - insert_by_date(one, &list); - insert_by_date(two, &list); - - return base_traverse(list, NULL); -} - struct commit_list *get_merge_bases(struct commit *one, struct commit *two, int cleanup) @@ -1405,30 +1389,20 @@ struct commit_list *get_merge_bases(struct commit *one, int in_merge_bases(struct commit *commit, struct commit **reference, int num) { - struct commit_list *result, *list; - int i, ret; + struct commit_list *bases, *b; + int ret = 0; - list = NULL; - parse_commit(commit); - commit->object.flags |= PARENT1; - insert_by_date(commit, &list); - - for (i = 0; i < num; i++) { - struct commit *two = reference[i]; - parse_commit(two); - if (!(two->object.flags & PARENT2)) { - two->object.flags |= PARENT2; - insert_by_date(two, &list); + if (num == 1) + bases = get_merge_bases(commit, *reference, 1); + else + die("not yet"); + for (b = bases; b; b = b->next) { + if (!hashcmp(commit->object.sha1, b->item->object.sha1)) { + ret = 1; + break; } } - result = base_traverse(list, commit); - ret = !!result; - free_commit_list(result); - clear_commit_marks(commit, all_flags); - for (i = 0; i < num; i++) { - struct commit *two = reference[i]; - clear_commit_marks(two, all_flags); - } + free_commit_list(bases); return ret; } diff --git a/git-checkout.sh b/git-checkout.sh index 9cdeaa445a..a7390e808c 100755 --- a/git-checkout.sh +++ b/git-checkout.sh @@ -207,9 +207,6 @@ else exit 1 ;; esac - # First stash away the local changes - git diff-index --binary -p HEAD >"$GIT_DIR"/LOCAL_DIFF - # Match the index to the working tree, and do a three-way. git diff-files --name-only | git update-index --remove --stdin && work=`git write-tree` && @@ -234,10 +231,6 @@ else sed -e 's/^[0-7]* [0-9a-f]* /'"0 $z40 /" echo "$unmerged" ) | git update-index --index-info - - echo >&2 "Conflicts in locally modified files:" - git diff --name-only --diff-filter=U >&2 - echo >&2 "Your local changes are found in $GIT_DIR/LOCAL_DIFF" ;; esac exit 0 diff --git a/git-merge.sh b/git-merge.sh index 5c62a06a50..fa4589173f 100755 --- a/git-merge.sh +++ b/git-merge.sh @@ -97,51 +97,6 @@ finish () { esac } -merge_local_changes () { - merge_error=$(git-read-tree -m -u --exclude-per-directory=.gitignore $1 $2 2>&1) || ( - - # First stash away the local changes - git diff-index --binary -p HEAD >"$GIT_DIR"/LOCAL_DIFF - - # Match the index to the working tree, and do a three-way. - git diff-files --name-only | - git update-index --remove --stdin && - work=`git write-tree` && - git read-tree --reset -u $2 && - git read-tree -m -u --aggressive --exclude-per-directory=.gitignore $1 $2 $work || exit - - echo >&2 "Carrying local changes forward." - if result=`git write-tree 2>/dev/null` - then - echo >&2 "Trivially automerged." - else - git merge-index -o git-merge-one-file -a - fi - - # Do not register the cleanly merged paths in the index - # yet; this is not a real merge before committing, but - # just carrying the working tree changes along. - unmerged=`git ls-files -u` - git read-tree --reset $2 - case "$unmerged" in - '') ;; - *) - ( - z40=0000000000000000000000000000000000000000 - echo "$unmerged" | - sed -e 's/^[0-7]* [0-9a-f]* /'"0 $z40 /" - echo "$unmerged" - ) | git update-index --index-info - - echo >&2 "Conflicts in locally modified files:" - git diff --name-only --diff-filter=U >&2 - echo >&2 "Your local changes are found in $GIT_DIR/LOCAL_DIFF" - ;; - esac - exit 0 - ) -} - merge_name () { remote="$1" rh=$(git-rev-parse --verify "$remote^0" 2>/dev/null) || return @@ -347,7 +302,7 @@ f,*) msg="$msg (no commit created; -m option ignored)" fi new_head=$(git-rev-parse --verify "$1^0") && - merge_local_changes $head $new_head && + git-read-tree -v -m -u --exclude-per-directory=.gitignore $head "$new_head" && finish "$new_head" "$msg" || exit dropsave exit 0