From 9dd5bded1bdc4f518aeed6a32ad70ccdd182dde5 Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Sat, 8 Mar 2008 19:27:09 +0100 Subject: [PATCH 1/6] git-quiltimport: better parser to grok "enhanced" series files. The previous parser wasn't able to grok: * empty lines; * annotated patch levels (trailing -pNNN annotations); * trailing comments. Now it understands them and uses the patch level hints as a git apply argument. Signed-off-by: Pierre Habouzit Signed-off-by: Junio C Hamano --- git-quiltimport.sh | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/git-quiltimport.sh b/git-quiltimport.sh index 233e5eae1d..84c8b8ef4f 100755 --- a/git-quiltimport.sh +++ b/git-quiltimport.sh @@ -63,7 +63,23 @@ tmp_info="$tmp_dir/info" commit=$(git rev-parse HEAD) 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 echo "$patch_name doesn't exist. Skipping." continue @@ -113,10 +129,10 @@ for patch_name in $(grep -v '^#' < "$QUILT_PATCHES/series" ); do fi if [ -z "$dry_run" ] ; then - git apply --index -C1 "$tmp_patch" && + git apply --index -C1 $level "$tmp_patch" && tree=$(git write-tree) && commit=$( (echo "$SUBJECT"; echo; cat "$tmp_msg") | git commit-tree $tree -p $commit) && git update-ref -m "quiltimport: $patch_name" HEAD $commit || exit 4 fi -done +done <"$QUILT_PATCHES/series" rm -rf $tmp_dir || exit 5 From 18d077c1bf576d51e2ad09e41b22042b8cb5c9f4 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 12 Mar 2008 21:07:19 -0700 Subject: [PATCH 2/6] quiltimport: fix misquoting of parsed -p parameter Signed-off-by: Junio C Hamano --- git-quiltimport.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/git-quiltimport.sh b/git-quiltimport.sh index 84c8b8ef4f..7cd8f7134e 100755 --- a/git-quiltimport.sh +++ b/git-quiltimport.sh @@ -67,7 +67,7 @@ while read patch_name level garbage do case "$patch_name" in ''|'#'*) continue;; esac case "$level" in - -p*);; + -p*) ;; ''|'#'*) level=;; *) @@ -129,7 +129,7 @@ do fi if [ -z "$dry_run" ] ; then - git apply --index -C1 $level "$tmp_patch" && + git apply --index -C1 ${level:+"$level"} "$tmp_patch" && tree=$(git write-tree) && commit=$( (echo "$SUBJECT"; echo; cat "$tmp_msg") | git commit-tree $tree -p $commit) && git update-ref -m "quiltimport: $patch_name" HEAD $commit || exit 4 From e7951290f6f87ac413a3f1e3a870619275453efe Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Thu, 13 Mar 2008 08:13:15 +0100 Subject: [PATCH 3/6] git fetch: Take '-n' to mean '--no-tags' Prior to commit 8320199 (Rewrite builtin-fetch option parsing to use parse_options().), we understood '-n' as a short option to mean "don't fetch tags from the remote". This patch reinstates behaviour similar, but not identical to the pre commit 8320199 times. Back then, -n always overrode --tags, so if both --tags and -n was given on command-line, no tags were fetched regardless of argument ordering. Now we use a "last entry wins" strategy, so '-n --tags' means "fetch tags". Since it's patently absurd to say both --tags and --no-tags, this shouldn't matter in practice. Spotted-by: Artem Zolochevskiy Reported-by: Dmitry V. Levin Signed-off-by: Johannes Schindelin Tested-by: Andreas Ericsson Signed-off-by: Junio C Hamano --- builtin-fetch.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/builtin-fetch.c b/builtin-fetch.c index 320e235682..9a6ddcec92 100644 --- a/builtin-fetch.c +++ b/builtin-fetch.c @@ -40,6 +40,8 @@ static struct option builtin_fetch_options[] = { "force overwrite of local branch"), OPT_SET_INT('t', "tags", &tags, "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('u', "update-head-ok", &update_head_ok, "allow updating of HEAD ref"), From bb12ac5120b657691b71108cef3e586ba0b76af6 Mon Sep 17 00:00:00 2001 From: Vineet Kumar Date: Thu, 13 Mar 2008 11:32:16 -0700 Subject: [PATCH 4/6] Minor wording changes in the keyboard descriptions in git-add --interactive. The wording of the interactive help text from git-add--interactive.perl is clearer. Just duplicate that text here. Signed-off-by: Vineet Kumar Signed-off-by: Junio C Hamano --- Documentation/git-add.txt | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/Documentation/git-add.txt b/Documentation/git-add.txt index 47799097ce..c751a17d07 100644 --- a/Documentation/git-add.txt +++ b/Documentation/git-add.txt @@ -207,16 +207,14 @@ patch:: and the working tree file and asks you if you want to stage the change of each hunk. You can say: - y - add the change from that hunk to index - n - do not add the change from that hunk to index - a - add the change from that hunk and all the rest to index - d - do not the change from that hunk nor any of the rest to index - j - do not decide on this hunk now, and view the next - undecided hunk - J - do not decide on this hunk now, and view the next hunk - k - do not decide on this hunk now, and view the previous - undecided hunk - K - do not decide on this hunk now, and view the previous hunk + y - stage this hunk + n - do not stage this hunk + a - stage this and all the remaining hunks in the file + d - do not stage this hunk nor any of the remaining hunks in the file + j - leave this hunk undecided, see next undecided hunk + J - leave this hunk undecided, see next hunk + k - leave this hunk undecided, see previous undecided hunk + K - leave this hunk undecided, see previous hunk s - split the current hunk into smaller hunks ? - print help + From 1affea4f629537fd48e3bd66de89a6f45d0fcd82 Mon Sep 17 00:00:00 2001 From: Clemens Buchacher Date: Thu, 13 Mar 2008 23:47:41 +0100 Subject: [PATCH 5/6] merge-recursive: handle file mode changes File mode changes should be handled similarly to changes of content. That is, if the file mode changed in only one branch, keep the changed version, and if both branch changed to different mode, mark it as a conflict. Signed-off-by: Clemens Buchacher Signed-off-by: Junio C Hamano --- merge-recursive.c | 15 ++++++++++-- t/t6031-merge-recursive.sh | 49 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 2 deletions(-) create mode 100755 t/t6031-merge-recursive.sh diff --git a/merge-recursive.c b/merge-recursive.c index 34e3167caf..d97cbf7d16 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -1028,9 +1028,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)) 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); else if (sha_eq(b->sha1, o->sha1)) hashcpy(result.sha, a->sha1); diff --git a/t/t6031-merge-recursive.sh b/t/t6031-merge-recursive.sh new file mode 100755 index 0000000000..5bb6b93780 --- /dev/null +++ b/t/t6031-merge-recursive.sh @@ -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 From 381b851c9b010147bb1fa83a013b7c8f60419026 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Thu, 13 Mar 2008 16:19:35 +0100 Subject: [PATCH 6/6] merge-file: handle empty files gracefully Earlier, it would error out while trying to read and/or writing them. Now, calling merge-file with empty files is neither interesting nor useful, but it is a bug that needed fixing. Noticed by Clemens Buchacher. Signed-off-by: Johannes Schindelin --- builtin-merge-file.c | 3 ++- xdiff-interface.c | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/builtin-merge-file.c b/builtin-merge-file.c index 58deb62ac0..baff4495f0 100644 --- a/builtin-merge-file.c +++ b/builtin-merge-file.c @@ -57,7 +57,8 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix) if (!f) 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); else if (fclose(f)) ret = error("Could not close %s", filename); diff --git a/xdiff-interface.c b/xdiff-interface.c index 4b8e5cca80..d8ba7e725f 100644 --- a/xdiff-interface.c +++ b/xdiff-interface.c @@ -152,8 +152,8 @@ int read_mmfile(mmfile_t *ptr, const char *filename) if ((f = fopen(filename, "rb")) == NULL) return error("Could not open %s", filename); sz = xsize_t(st.st_size); - ptr->ptr = xmalloc(sz); - if (fread(ptr->ptr, sz, 1, f) != 1) + ptr->ptr = xmalloc(sz ? sz : 1); + if (sz && fread(ptr->ptr, sz, 1, f) != 1) return error("Could not read %s", filename); fclose(f); ptr->size = sz;