summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2012-03-22 15:07:54 -0700
committerJunio C Hamano <gitster@pobox.com>2012-03-22 15:08:35 -0700
commitd5b592cf6799e3e9d80150c62af6033ba2c32a5a (patch)
treefa4d66df71d618a223f526fe2c85835e4c2cb8ab
parent498a04af143f55a7bbbba484d48a7f123d43be04 (diff)
parent536caca5ce0d88e4c54e9e7376ed182807702c58 (diff)
downloadgit-jk/merge-recursive-no-rename-empty.tar.gz
Adjust 'jk/maint-1.7.7-merge-recursive-no-rename-empty' for the 1.7.10 codebasejk/merge-recursive-no-rename-empty
A new offender that casts EMPTY_TREE_SHA1_BIN was added to sequencer.c after 1.7.9.x maintenance track; adjust the "merge-recursive" series applied for older maintenance track to the current codebase. * jk/maint-1.7.7-merge-recursive-no-rename-empty: merge-recursive: don't detect renames from empty files make is_empty_blob_sha1 available everywhere drop casts from users EMPTY_TREE_SHA1_BIN
-rw-r--r--builtin/diff.c2
-rw-r--r--cache.h13
-rw-r--r--merge-recursive.c4
-rw-r--r--read-cache.c10
-rw-r--r--sequencer.c2
-rwxr-xr-xt/t6022-merge-rename.sh16
6 files changed, 33 insertions, 14 deletions
diff --git a/builtin/diff.c b/builtin/diff.c
index 424c815f9b..9069dc41be 100644
--- a/builtin/diff.c
+++ b/builtin/diff.c
@@ -327,7 +327,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
add_head_to_pending(&rev);
if (!rev.pending.nr) {
struct tree *tree;
- tree = lookup_tree((const unsigned char*)EMPTY_TREE_SHA1_BIN);
+ tree = lookup_tree(EMPTY_TREE_SHA1_BIN);
add_pending_object(&rev, &tree->object, "HEAD");
}
break;
diff --git a/cache.h b/cache.h
index e5e1aa4e15..5280574801 100644
--- a/cache.h
+++ b/cache.h
@@ -708,6 +708,19 @@ static inline void hashclr(unsigned char *hash)
#define EMPTY_TREE_SHA1_BIN \
((const unsigned char *) EMPTY_TREE_SHA1_BIN_LITERAL)
+#define EMPTY_BLOB_SHA1_HEX \
+ "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"
+#define EMPTY_BLOB_SHA1_BIN_LITERAL \
+ "\xe6\x9d\xe2\x9b\xb2\xd1\xd6\x43\x4b\x8b" \
+ "\x29\xae\x77\x5a\xd8\xc2\xe4\x8c\x53\x91"
+#define EMPTY_BLOB_SHA1_BIN \
+ ((const unsigned char *) EMPTY_BLOB_SHA1_BIN_LITERAL)
+
+static inline int is_empty_blob_sha1(const unsigned char *sha1)
+{
+ return !hashcmp(sha1, EMPTY_BLOB_SHA1_BIN);
+}
+
int git_mkstemp(char *path, size_t n, const char *template);
int git_mkstemps(char *path, size_t n, const char *template, int suffix_len);
diff --git a/merge-recursive.c b/merge-recursive.c
index 6479a60cd1..0255f5061b 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -502,7 +502,7 @@ static struct string_list *get_renames(struct merge_options *o,
struct string_list_item *item;
struct rename *re;
struct diff_filepair *pair = diff_queued_diff.queue[i];
- if (pair->status != 'R') {
+ if (pair->status != 'R' || is_empty_blob_sha1(pair->one->sha1)) {
diff_free_filepair(pair);
continue;
}
@@ -1914,7 +1914,7 @@ int merge_recursive(struct merge_options *o,
/* if there is no common ancestor, use an empty tree */
struct tree *tree;
- tree = lookup_tree((const unsigned char *)EMPTY_TREE_SHA1_BIN);
+ tree = lookup_tree(EMPTY_TREE_SHA1_BIN);
merged_common_ancestors = make_virtual_commit(tree, "ancestor");
}
diff --git a/read-cache.c b/read-cache.c
index 274e54b4f3..6c8f395836 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -157,16 +157,6 @@ static int ce_modified_check_fs(struct cache_entry *ce, struct stat *st)
return 0;
}
-static int is_empty_blob_sha1(const unsigned char *sha1)
-{
- static const unsigned char empty_blob_sha1[20] = {
- 0xe6,0x9d,0xe2,0x9b,0xb2,0xd1,0xd6,0x43,0x4b,0x8b,
- 0x29,0xae,0x77,0x5a,0xd8,0xc2,0xe4,0x8c,0x53,0x91
- };
-
- return !hashcmp(sha1, empty_blob_sha1);
-}
-
static int ce_match_stat_basic(struct cache_entry *ce, struct stat *st)
{
unsigned int changed = 0;
diff --git a/sequencer.c b/sequencer.c
index a37846a594..4307364b26 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -164,7 +164,7 @@ static void write_message(struct strbuf *msgbuf, const char *filename)
static struct tree *empty_tree(void)
{
- return lookup_tree((const unsigned char *)EMPTY_TREE_SHA1_BIN);
+ return lookup_tree(EMPTY_TREE_SHA1_BIN);
}
static int error_dirty_index(struct replay_opts *opts)
diff --git a/t/t6022-merge-rename.sh b/t/t6022-merge-rename.sh
index 9d8584e957..1104249182 100755
--- a/t/t6022-merge-rename.sh
+++ b/t/t6022-merge-rename.sh
@@ -884,4 +884,20 @@ test_expect_success 'no spurious "refusing to lose untracked" message' '
! grep "refusing to lose untracked file" errors.txt
'
+test_expect_success 'do not follow renames for empty files' '
+ git checkout -f -b empty-base &&
+ >empty1 &&
+ git add empty1 &&
+ git commit -m base &&
+ echo content >empty1 &&
+ git add empty1 &&
+ git commit -m fill &&
+ git checkout -b empty-topic HEAD^ &&
+ git mv empty1 empty2 &&
+ git commit -m rename &&
+ test_must_fail git merge empty-base &&
+ >expect &&
+ test_cmp expect empty2
+'
+
test_done