Merge branch 'maint'

* maint:
  merge-file: handle empty files gracefully
  merge-recursive: handle file mode changes
  Minor wording changes in the keyboard descriptions in git-add --interactive.
  git fetch: Take '-n' to mean '--no-tags'
  quiltimport: fix misquoting of parsed -p<num> parameter
  git-quiltimport: better parser to grok "enhanced" series files.
This commit is contained in:
Junio C Hamano 2008-03-14 00:16:42 -07:00
commit 16007f3916
7 changed files with 95 additions and 18 deletions

View File

@ -207,16 +207,14 @@ patch::
and the working tree file and asks you if you want to stage and the working tree file and asks you if you want to stage
the change of each hunk. You can say: the change of each hunk. You can say:
y - add the change from that hunk to index y - stage this hunk
n - do not add the change from that hunk to index n - do not stage this hunk
a - add the change from that hunk and all the rest to index a - stage this and all the remaining hunks in the file
d - do not the change from that hunk nor any of the rest to index d - do not stage this hunk nor any of the remaining hunks in the file
j - do not decide on this hunk now, and view the next j - leave this hunk undecided, see next undecided hunk
undecided hunk J - leave this hunk undecided, see next hunk
J - do not decide on this hunk now, and view the next hunk k - leave this hunk undecided, see previous undecided hunk
k - do not decide on this hunk now, and view the previous K - leave this hunk undecided, see previous hunk
undecided hunk
K - do not decide on this hunk now, and view the previous hunk
s - split the current hunk into smaller hunks s - split the current hunk into smaller hunks
? - print help ? - print help
+ +

View File

@ -40,6 +40,8 @@ static struct option builtin_fetch_options[] = {
"force overwrite of local branch"), "force overwrite of local branch"),
OPT_SET_INT('t', "tags", &tags, OPT_SET_INT('t', "tags", &tags,
"fetch all tags and associated objects", TAGS_SET), "fetch all tags and associated objects", TAGS_SET),
OPT_SET_INT('n', NULL, &tags,
"do not fetch all tags (--no-tags)", TAGS_UNSET),
OPT_BOOLEAN('k', "keep", &keep, "keep downloaded pack"), OPT_BOOLEAN('k', "keep", &keep, "keep downloaded pack"),
OPT_BOOLEAN('u', "update-head-ok", &update_head_ok, OPT_BOOLEAN('u', "update-head-ok", &update_head_ok,
"allow updating of HEAD ref"), "allow updating of HEAD ref"),

View File

@ -57,7 +57,8 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)
if (!f) if (!f)
ret = error("Could not open %s for writing", filename); ret = error("Could not open %s for writing", filename);
else if (fwrite(result.ptr, result.size, 1, f) != 1) else if (result.size &&
fwrite(result.ptr, result.size, 1, f) != 1)
ret = error("Could not write to %s", filename); ret = error("Could not write to %s", filename);
else if (fclose(f)) else if (fclose(f))
ret = error("Could not close %s", filename); ret = error("Could not close %s", filename);

View File

@ -668,9 +668,20 @@ static struct merge_file_info merge_file(struct diff_filespec *o,
if (!sha_eq(a->sha1, o->sha1) && !sha_eq(b->sha1, o->sha1)) if (!sha_eq(a->sha1, o->sha1) && !sha_eq(b->sha1, o->sha1))
result.merge = 1; result.merge = 1;
result.mode = a->mode == o->mode ? b->mode: a->mode; /*
* Merge modes
*/
if (a->mode == b->mode || a->mode == o->mode)
result.mode = b->mode;
else {
result.mode = a->mode;
if (b->mode != o->mode) {
result.clean = 0;
result.merge = 1;
}
}
if (sha_eq(a->sha1, o->sha1)) if (sha_eq(a->sha1, b->sha1) || sha_eq(a->sha1, o->sha1))
hashcpy(result.sha, b->sha1); hashcpy(result.sha, b->sha1);
else if (sha_eq(b->sha1, o->sha1)) else if (sha_eq(b->sha1, o->sha1))
hashcpy(result.sha, a->sha1); hashcpy(result.sha, a->sha1);

View File

@ -63,7 +63,23 @@ tmp_info="$tmp_dir/info"
commit=$(git rev-parse HEAD) commit=$(git rev-parse HEAD)
mkdir $tmp_dir || exit 2 mkdir $tmp_dir || exit 2
for patch_name in $(grep -v '^#' < "$QUILT_PATCHES/series" ); do while read patch_name level garbage
do
case "$patch_name" in ''|'#'*) continue;; esac
case "$level" in
-p*) ;;
''|'#'*)
level=;;
*)
echo "unable to parse patch level, ignoring it."
level=;;
esac
case "$garbage" in
''|'#'*);;
*)
echo "trailing garbage found in series file: $garbage"
exit 1;;
esac
if ! [ -f "$QUILT_PATCHES/$patch_name" ] ; then if ! [ -f "$QUILT_PATCHES/$patch_name" ] ; then
echo "$patch_name doesn't exist. Skipping." echo "$patch_name doesn't exist. Skipping."
continue continue
@ -113,10 +129,10 @@ for patch_name in $(grep -v '^#' < "$QUILT_PATCHES/series" ); do
fi fi
if [ -z "$dry_run" ] ; then if [ -z "$dry_run" ] ; then
git apply --index -C1 "$tmp_patch" && git apply --index -C1 ${level:+"$level"} "$tmp_patch" &&
tree=$(git write-tree) && tree=$(git write-tree) &&
commit=$( (echo "$SUBJECT"; echo; cat "$tmp_msg") | git commit-tree $tree -p $commit) && commit=$( (echo "$SUBJECT"; echo; cat "$tmp_msg") | git commit-tree $tree -p $commit) &&
git update-ref -m "quiltimport: $patch_name" HEAD $commit || exit 4 git update-ref -m "quiltimport: $patch_name" HEAD $commit || exit 4
fi fi
done done <"$QUILT_PATCHES/series"
rm -rf $tmp_dir || exit 5 rm -rf $tmp_dir || exit 5

49
t/t6031-merge-recursive.sh Executable file
View File

@ -0,0 +1,49 @@
#!/bin/sh
test_description='merge-recursive: handle file mode'
. ./test-lib.sh
test_expect_success 'mode change in one branch: keep changed version' '
: >file1 &&
git add file1 &&
git commit -m initial &&
git checkout -b a1 master &&
: >dummy &&
git add dummy &&
git commit -m a &&
git checkout -b b1 master &&
chmod +x file1 &&
git add file1 &&
git commit -m b1 &&
git checkout a1 &&
git merge-recursive master -- a1 b1 &&
test -x file1
'
test_expect_success 'mode change in both branches: expect conflict' '
git reset --hard HEAD &&
git checkout -b a2 master &&
: >file2 &&
H=$(git hash-object file2) &&
chmod +x file2 &&
git add file2 &&
git commit -m a2 &&
git checkout -b b2 master &&
: >file2 &&
git add file2 &&
git commit -m b2 &&
git checkout a2 &&
(
git merge-recursive master -- a2 b2
test $? = 1
) &&
git ls-files -u >actual &&
(
echo "100755 $H 2 file2"
echo "100644 $H 3 file2"
) >expect &&
diff -u actual expect &&
test -x file2
'
test_done

View File

@ -152,8 +152,8 @@ int read_mmfile(mmfile_t *ptr, const char *filename)
if ((f = fopen(filename, "rb")) == NULL) if ((f = fopen(filename, "rb")) == NULL)
return error("Could not open %s", filename); return error("Could not open %s", filename);
sz = xsize_t(st.st_size); sz = xsize_t(st.st_size);
ptr->ptr = xmalloc(sz); ptr->ptr = xmalloc(sz ? sz : 1);
if (fread(ptr->ptr, sz, 1, f) != 1) if (sz && fread(ptr->ptr, sz, 1, f) != 1)
return error("Could not read %s", filename); return error("Could not read %s", filename);
fclose(f); fclose(f);
ptr->size = sz; ptr->size = sz;