tree-diff: move all action-taking code out of compare_tree_entry()
- let it do only comparison. This way the code is cleaner and more structured - cmp function only compares, and the driver takes action based on comparison result. There should be no change in performance, as effectively, we just move if series from on place into another, and merge it to was-already-there same switch/if, so the result is maybe a little bit faster. Signed-off-by: Kirill Smelkov <kirr@mns.spb.ru> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
5dfb2bbd8d
commit
903bba68ab
28
tree-diff.c
28
tree-diff.c
@ -9,8 +9,7 @@
|
|||||||
static void show_path(struct strbuf *base, struct diff_options *opt,
|
static void show_path(struct strbuf *base, struct diff_options *opt,
|
||||||
struct tree_desc *t1, struct tree_desc *t2);
|
struct tree_desc *t1, struct tree_desc *t2);
|
||||||
|
|
||||||
static int compare_tree_entry(struct tree_desc *t1, struct tree_desc *t2,
|
static int compare_tree_entry(struct tree_desc *t1, struct tree_desc *t2)
|
||||||
struct strbuf *base, struct diff_options *opt)
|
|
||||||
{
|
{
|
||||||
unsigned mode1, mode2;
|
unsigned mode1, mode2;
|
||||||
const char *path1, *path2;
|
const char *path1, *path2;
|
||||||
@ -28,19 +27,7 @@ static int compare_tree_entry(struct tree_desc *t1, struct tree_desc *t2,
|
|||||||
* even when having the same name.
|
* even when having the same name.
|
||||||
*/
|
*/
|
||||||
cmp = base_name_compare(path1, pathlen1, mode1, path2, pathlen2, mode2);
|
cmp = base_name_compare(path1, pathlen1, mode1, path2, pathlen2, mode2);
|
||||||
if (cmp < 0) {
|
return cmp;
|
||||||
show_path(base, opt, t1, /*t2=*/NULL);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (cmp > 0) {
|
|
||||||
show_path(base, opt, /*t1=*/NULL, t2);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (!DIFF_OPT_TST(opt, FIND_COPIES_HARDER) && !hashcmp(sha1, sha2) && mode1 == mode2)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
show_path(base, opt, t1, t2);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -160,6 +147,8 @@ int diff_tree(struct tree_desc *t1, struct tree_desc *t2,
|
|||||||
strbuf_add(&base, base_str, baselen);
|
strbuf_add(&base, base_str, baselen);
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
int cmp;
|
||||||
|
|
||||||
if (diff_can_quit_early(opt))
|
if (diff_can_quit_early(opt))
|
||||||
break;
|
break;
|
||||||
if (opt->pathspec.nr) {
|
if (opt->pathspec.nr) {
|
||||||
@ -179,21 +168,28 @@ int diff_tree(struct tree_desc *t1, struct tree_desc *t2,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmp = compare_tree_entry(t1, t2, &base, opt);
|
cmp = compare_tree_entry(t1, t2);
|
||||||
|
|
||||||
/* t1 = t2 */
|
/* t1 = t2 */
|
||||||
if (cmp == 0) {
|
if (cmp == 0) {
|
||||||
|
if (DIFF_OPT_TST(opt, FIND_COPIES_HARDER) ||
|
||||||
|
hashcmp(t1->entry.sha1, t2->entry.sha1) ||
|
||||||
|
(t1->entry.mode != t2->entry.mode))
|
||||||
|
show_path(&base, opt, t1, t2);
|
||||||
|
|
||||||
update_tree_entry(t1);
|
update_tree_entry(t1);
|
||||||
update_tree_entry(t2);
|
update_tree_entry(t2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* t1 < t2 */
|
/* t1 < t2 */
|
||||||
else if (cmp < 0) {
|
else if (cmp < 0) {
|
||||||
|
show_path(&base, opt, t1, /*t2=*/NULL);
|
||||||
update_tree_entry(t1);
|
update_tree_entry(t1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* t1 > t2 */
|
/* t1 > t2 */
|
||||||
else {
|
else {
|
||||||
|
show_path(&base, opt, /*t1=*/NULL, t2);
|
||||||
update_tree_entry(t2);
|
update_tree_entry(t2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user