Skip to content

Commit 6541675

Browse files
author
Junio C Hamano
committed
diffcore-rename: split out the delta counting code.
This is to rework diffcore break/rename/copy detection code so that it does not affected when deltifier code gets improved. Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent aeecd23 commit 6541675

File tree

5 files changed

+61
-40
lines changed

5 files changed

+61
-40
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ LIB_H = \
196196

197197
DIFF_OBJS = \
198198
diff.o diffcore-break.o diffcore-order.o diffcore-pathspec.o \
199-
diffcore-pickaxe.o diffcore-rename.o tree-diff.o combine-diff.o
199+
diffcore-pickaxe.o diffcore-rename.o tree-diff.o combine-diff.o \
200+
diffcore-delta.o
200201

201202
LIB_OBJS = \
202203
blob.o commit.o connect.o count-delta.o csum-file.o \

diffcore-break.c

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
#include "cache.h"
55
#include "diff.h"
66
#include "diffcore.h"
7-
#include "delta.h"
8-
#include "count-delta.h"
97

108
static int should_break(struct diff_filespec *src,
119
struct diff_filespec *dst,
@@ -47,7 +45,6 @@ static int should_break(struct diff_filespec *src,
4745
* The value we return is 1 if we want the pair to be broken,
4846
* or 0 if we do not.
4947
*/
50-
void *delta;
5148
unsigned long delta_size, base_size, src_copied, literal_added;
5249
int to_break = 0;
5350

@@ -69,19 +66,11 @@ static int should_break(struct diff_filespec *src,
6966
if (base_size < MINIMUM_BREAK_SIZE)
7067
return 0; /* we do not break too small filepair */
7168

72-
delta = diff_delta(src->data, src->size,
73-
dst->data, dst->size,
74-
&delta_size, 0);
75-
if (!delta)
76-
return 0; /* error but caught downstream */
77-
78-
/* Estimate the edit size by interpreting delta. */
79-
if (count_delta(delta, delta_size,
80-
&src_copied, &literal_added)) {
81-
free(delta);
82-
return 0; /* we cannot tell */
83-
}
84-
free(delta);
69+
if (diffcore_count_changes(src->data, src->size,
70+
dst->data, dst->size,
71+
0,
72+
&src_copied, &literal_added))
73+
return 0;
8574

8675
/* Compute merge-score, which is "how much is removed
8776
* from the source material". The clean-up stage will

diffcore-delta.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include "cache.h"
2+
#include "diff.h"
3+
#include "diffcore.h"
4+
#include "delta.h"
5+
#include "count-delta.h"
6+
7+
static int diffcore_count_changes_1(void *src, unsigned long src_size,
8+
void *dst, unsigned long dst_size,
9+
unsigned long delta_limit,
10+
unsigned long *src_copied,
11+
unsigned long *literal_added)
12+
{
13+
void *delta;
14+
unsigned long delta_size;
15+
16+
delta = diff_delta(src, src_size,
17+
dst, dst_size,
18+
&delta_size, delta_limit);
19+
if (!delta)
20+
/* If delta_limit is exceeded, we have too much differences */
21+
return -1;
22+
23+
/* Estimate the edit size by interpreting delta. */
24+
if (count_delta(delta, delta_size, src_copied, literal_added)) {
25+
free(delta);
26+
return -1;
27+
}
28+
free(delta);
29+
return 0;
30+
}
31+
32+
int diffcore_count_changes(void *src, unsigned long src_size,
33+
void *dst, unsigned long dst_size,
34+
unsigned long delta_limit,
35+
unsigned long *src_copied,
36+
unsigned long *literal_added)
37+
{
38+
return diffcore_count_changes_1(src, src_size,
39+
dst, dst_size,
40+
delta_limit,
41+
src_copied,
42+
literal_added);
43+
}

diffcore-rename.c

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
#include "cache.h"
55
#include "diff.h"
66
#include "diffcore.h"
7-
#include "delta.h"
8-
#include "count-delta.h"
97

108
/* Table of rename/copy destinations */
119

@@ -135,7 +133,6 @@ static int estimate_similarity(struct diff_filespec *src,
135133
* match than anything else; the destination does not even
136134
* call into this function in that case.
137135
*/
138-
void *delta;
139136
unsigned long delta_size, base_size, src_copied, literal_added;
140137
unsigned long delta_limit;
141138
int score;
@@ -165,28 +162,13 @@ static int estimate_similarity(struct diff_filespec *src,
165162
if (diff_populate_filespec(src, 0) || diff_populate_filespec(dst, 0))
166163
return 0; /* error but caught downstream */
167164

168-
delta_limit = base_size * (MAX_SCORE-minimum_score) / MAX_SCORE;
169-
delta = diff_delta(src->data, src->size,
170-
dst->data, dst->size,
171-
&delta_size, delta_limit);
172-
if (!delta)
173-
/* If delta_limit is exceeded, we have too much differences */
174-
return 0;
175-
176-
/* A delta that has a lot of literal additions would have
177-
* big delta_size no matter what else it does.
178-
*/
179-
if (base_size * (MAX_SCORE-minimum_score) < delta_size * MAX_SCORE) {
180-
free(delta);
181-
return 0;
182-
}
183165

184-
/* Estimate the edit size by interpreting delta. */
185-
if (count_delta(delta, delta_size, &src_copied, &literal_added)) {
186-
free(delta);
166+
delta_limit = base_size * (MAX_SCORE-minimum_score) / MAX_SCORE;
167+
if (diffcore_count_changes(src->data, src->size,
168+
dst->data, dst->size,
169+
delta_limit,
170+
&src_copied, &literal_added))
187171
return 0;
188-
}
189-
free(delta);
190172

191173
/* Extent of damage */
192174
if (src->size + literal_added < src_copied)

diffcore.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,10 @@ void diff_debug_queue(const char *, struct diff_queue_struct *);
101101
#define diff_debug_queue(a,b) do {} while(0)
102102
#endif
103103

104+
extern int diffcore_count_changes(void *src, unsigned long src_size,
105+
void *dst, unsigned long dst_size,
106+
unsigned long delta_limit,
107+
unsigned long *src_copied,
108+
unsigned long *literal_added);
109+
104110
#endif

0 commit comments

Comments
 (0)