Skip to content

Commit 11f944d

Browse files
torvaldsgitster
authored andcommitted
for_each_hash: allow passing a 'void *data' pointer to callback
For the find_exact_renames() function, this allows us to pass the diff_options structure pointer to the low-level routines. We will use that to distinguish between the "rename" and "copy" cases. Signed-off-by: Linus Torvalds <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7ed863a commit 11f944d

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

builtin/describe.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ static inline struct commit_name *find_commit_name(const unsigned char *peeled)
6363
return n;
6464
}
6565

66-
static int set_util(void *chain)
66+
static int set_util(void *chain, void *data)
6767
{
6868
struct commit_name *n;
6969
for (n = chain; n; n = n->next) {
@@ -289,7 +289,7 @@ static void describe(const char *arg, int last_one)
289289
fprintf(stderr, "searching to describe %s\n", arg);
290290

291291
if (!have_util) {
292-
for_each_hash(&names, set_util);
292+
for_each_hash(&names, set_util, NULL);
293293
have_util = 1;
294294
}
295295

diffcore-rename.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,8 @@ struct file_similarity {
247247
};
248248

249249
static int find_identical_files(struct file_similarity *src,
250-
struct file_similarity *dst)
250+
struct file_similarity *dst,
251+
struct diff_options *options)
251252
{
252253
int renames = 0;
253254

@@ -306,11 +307,12 @@ static void free_similarity_list(struct file_similarity *p)
306307
}
307308
}
308309

309-
static int find_same_files(void *ptr)
310+
static int find_same_files(void *ptr, void *data)
310311
{
311312
int ret;
312313
struct file_similarity *p = ptr;
313314
struct file_similarity *src = NULL, *dst = NULL;
315+
struct diff_options *options = data;
314316

315317
/* Split the hash list up into sources and destinations */
316318
do {
@@ -329,7 +331,7 @@ static int find_same_files(void *ptr)
329331
* If we have both sources *and* destinations, see if
330332
* we can match them up
331333
*/
332-
ret = (src && dst) ? find_identical_files(src, dst) : 0;
334+
ret = (src && dst) ? find_identical_files(src, dst, options) : 0;
333335

334336
/* Free the hashes and return the number of renames found */
335337
free_similarity_list(src);
@@ -377,7 +379,7 @@ static void insert_file_table(struct hash_table *table, int src_dst, int index,
377379
* and then during the second round we try to match
378380
* cache-dirty entries as well.
379381
*/
380-
static int find_exact_renames(void)
382+
static int find_exact_renames(struct diff_options *options)
381383
{
382384
int i;
383385
struct hash_table file_table;
@@ -390,7 +392,7 @@ static int find_exact_renames(void)
390392
insert_file_table(&file_table, 1, i, rename_dst[i].two);
391393

392394
/* Find the renames */
393-
i = for_each_hash(&file_table, find_same_files);
395+
i = for_each_hash(&file_table, find_same_files, options);
394396

395397
/* .. and free the hash data structure */
396398
free_hash(&file_table);
@@ -467,7 +469,7 @@ void diffcore_rename(struct diff_options *options)
467469
* We really want to cull the candidates list early
468470
* with cheap tests in order to avoid doing deltas.
469471
*/
470-
rename_count = find_exact_renames();
472+
rename_count = find_exact_renames(options);
471473

472474
/* Did we only want exact renames? */
473475
if (minimum_score == MAX_SCORE)

hash.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void **insert_hash(unsigned int hash, void *ptr, struct hash_table *table)
8181
return insert_hash_entry(hash, ptr, table);
8282
}
8383

84-
int for_each_hash(const struct hash_table *table, int (*fn)(void *))
84+
int for_each_hash(const struct hash_table *table, int (*fn)(void *, void *), void *data)
8585
{
8686
int sum = 0;
8787
unsigned int i;
@@ -92,7 +92,7 @@ int for_each_hash(const struct hash_table *table, int (*fn)(void *))
9292
void *ptr = array->ptr;
9393
array++;
9494
if (ptr) {
95-
int val = fn(ptr);
95+
int val = fn(ptr, data);
9696
if (val < 0)
9797
return val;
9898
sum += val;

hash.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct hash_table {
3030

3131
extern void *lookup_hash(unsigned int hash, const struct hash_table *table);
3232
extern void **insert_hash(unsigned int hash, void *ptr, struct hash_table *table);
33-
extern int for_each_hash(const struct hash_table *table, int (*fn)(void *));
33+
extern int for_each_hash(const struct hash_table *table, int (*fn)(void *, void *), void *data);
3434
extern void free_hash(struct hash_table *table);
3535

3636
static inline void init_hash(struct hash_table *table)

0 commit comments

Comments
 (0)