@@ -72,7 +72,8 @@ static int print_tool_help(void)
72
72
return run_command (& cmd );
73
73
}
74
74
75
- static int parse_index_info (char * p , int * mode1 , int * mode2 ,
75
+ static int parse_index_info (struct repository * repo ,
76
+ char * p , int * mode1 , int * mode2 ,
76
77
struct object_id * oid1 , struct object_id * oid2 ,
77
78
char * status )
78
79
{
@@ -84,11 +85,11 @@ static int parse_index_info(char *p, int *mode1, int *mode2,
84
85
* mode2 = (int )strtol (p + 1 , & p , 8 );
85
86
if (* p != ' ' )
86
87
return error ("expected ' ', got '%c'" , * p );
87
- if (parse_oid_hex (++ p , oid1 , (const char * * )& p ))
88
+ if (parse_oid_hex_algop (++ p , oid1 , (const char * * )& p , repo -> hash_algo ))
88
89
return error ("expected object ID, got '%s'" , p );
89
90
if (* p != ' ' )
90
91
return error ("expected ' ', got '%c'" , * p );
91
- if (parse_oid_hex (++ p , oid2 , (const char * * )& p ))
92
+ if (parse_oid_hex_algop (++ p , oid2 , (const char * * )& p , repo -> hash_algo ))
92
93
return error ("expected object ID, got '%s'" , p );
93
94
if (* p != ' ' )
94
95
return error ("expected ' ', got '%c'" , * p );
@@ -115,7 +116,8 @@ static void add_path(struct strbuf *buf, size_t base_len, const char *path)
115
116
/*
116
117
* Determine whether we can simply reuse the file in the worktree.
117
118
*/
118
- static int use_wt_file (const char * workdir , const char * name ,
119
+ static int use_wt_file (struct repository * repo ,
120
+ const char * workdir , const char * name ,
119
121
struct object_id * oid )
120
122
{
121
123
struct strbuf buf = STRBUF_INIT ;
@@ -130,7 +132,7 @@ static int use_wt_file(const char *workdir, const char *name,
130
132
int fd = open (buf .buf , O_RDONLY );
131
133
132
134
if (fd >= 0 &&
133
- !index_fd (the_repository -> index , & wt_oid , fd , & st , OBJ_BLOB , name , 0 )) {
135
+ !index_fd (repo -> index , & wt_oid , fd , & st , OBJ_BLOB , name , 0 )) {
134
136
if (is_null_oid (oid )) {
135
137
oidcpy (oid , & wt_oid );
136
138
use = 1 ;
@@ -221,13 +223,14 @@ static int path_entry_cmp(const void *cmp_data UNUSED,
221
223
return strcmp (a -> path , key ? key : b -> path );
222
224
}
223
225
224
- static void changed_files (struct hashmap * result , const char * index_path ,
226
+ static void changed_files (struct repository * repo ,
227
+ struct hashmap * result , const char * index_path ,
225
228
const char * workdir )
226
229
{
227
230
struct child_process update_index = CHILD_PROCESS_INIT ;
228
231
struct child_process diff_files = CHILD_PROCESS_INIT ;
229
232
struct strbuf buf = STRBUF_INIT ;
230
- const char * git_dir = absolute_path (repo_get_git_dir (the_repository ));
233
+ const char * git_dir = absolute_path (repo_get_git_dir (repo ));
231
234
FILE * fp ;
232
235
233
236
strvec_pushl (& update_index .args ,
@@ -300,7 +303,8 @@ static int ensure_leading_directories(char *path)
300
303
* to compare the readlink(2) result as text, even on a filesystem that is
301
304
* capable of doing a symbolic link.
302
305
*/
303
- static char * get_symlink (struct difftool_options * dt_options ,
306
+ static char * get_symlink (struct repository * repo ,
307
+ struct difftool_options * dt_options ,
304
308
const struct object_id * oid , const char * path )
305
309
{
306
310
char * data ;
@@ -317,8 +321,7 @@ static char *get_symlink(struct difftool_options *dt_options,
317
321
} else {
318
322
enum object_type type ;
319
323
unsigned long size ;
320
- data = repo_read_object_file (the_repository , oid , & type ,
321
- & size );
324
+ data = repo_read_object_file (repo , oid , & type , & size );
322
325
if (!data )
323
326
die (_ ("could not read object %s for symlink %s" ),
324
327
oid_to_hex (oid ), path );
@@ -365,7 +368,8 @@ static void write_standin_files(struct pair_entry *entry,
365
368
write_file_in_directory (rdir , rdir_len , entry -> path , entry -> right );
366
369
}
367
370
368
- static int run_dir_diff (struct difftool_options * dt_options ,
371
+ static int run_dir_diff (struct repository * repo ,
372
+ struct difftool_options * dt_options ,
369
373
const char * extcmd , const char * prefix ,
370
374
struct child_process * child )
371
375
{
@@ -386,15 +390,15 @@ static int run_dir_diff(struct difftool_options *dt_options,
386
390
struct hashmap symlinks2 = HASHMAP_INIT (pair_cmp , NULL );
387
391
struct hashmap_iter iter ;
388
392
struct pair_entry * entry ;
389
- struct index_state wtindex = INDEX_STATE_INIT (the_repository );
393
+ struct index_state wtindex = INDEX_STATE_INIT (repo );
390
394
struct checkout lstate , rstate ;
391
395
int err = 0 ;
392
396
struct child_process cmd = CHILD_PROCESS_INIT ;
393
397
struct hashmap wt_modified = HASHMAP_INIT (path_entry_cmp , NULL );
394
398
struct hashmap tmp_modified = HASHMAP_INIT (path_entry_cmp , NULL );
395
399
int indices_loaded = 0 ;
396
400
397
- workdir = repo_get_work_tree (the_repository );
401
+ workdir = repo_get_work_tree (repo );
398
402
399
403
/* Setup temp directories */
400
404
tmp = getenv ("TMPDIR" );
@@ -449,8 +453,7 @@ static int run_dir_diff(struct difftool_options *dt_options,
449
453
"not supported in\n"
450
454
"directory diff mode ('-d' and '--dir-diff')." ));
451
455
452
- if (parse_index_info (info .buf , & lmode , & rmode , & loid , & roid ,
453
- & status ))
456
+ if (parse_index_info (repo , info .buf , & lmode , & rmode , & loid , & roid , & status ))
454
457
break ;
455
458
if (strbuf_getline_nul (& lpath , fp ))
456
459
break ;
@@ -480,13 +483,13 @@ static int run_dir_diff(struct difftool_options *dt_options,
480
483
}
481
484
482
485
if (S_ISLNK (lmode )) {
483
- char * content = get_symlink (dt_options , & loid , src_path );
486
+ char * content = get_symlink (repo , dt_options , & loid , src_path );
484
487
add_left_or_right (& symlinks2 , src_path , content , 0 );
485
488
free (content );
486
489
}
487
490
488
491
if (S_ISLNK (rmode )) {
489
- char * content = get_symlink (dt_options , & roid , dst_path );
492
+ char * content = get_symlink (repo , dt_options , & roid , dst_path );
490
493
add_left_or_right (& symlinks2 , dst_path , content , 1 );
491
494
free (content );
492
495
}
@@ -511,7 +514,7 @@ static int run_dir_diff(struct difftool_options *dt_options,
511
514
}
512
515
hashmap_add (& working_tree_dups , & entry -> entry );
513
516
514
- if (!use_wt_file (workdir , dst_path , & roid )) {
517
+ if (!use_wt_file (repo , workdir , dst_path , & roid )) {
515
518
if (checkout_path (rmode , & roid , dst_path ,
516
519
& rstate )) {
517
520
ret = error ("could not write '%s'" ,
@@ -637,9 +640,9 @@ static int run_dir_diff(struct difftool_options *dt_options,
637
640
ret = error ("could not write %s" , buf .buf );
638
641
goto finish ;
639
642
}
640
- changed_files (& wt_modified , buf .buf , workdir );
643
+ changed_files (repo , & wt_modified , buf .buf , workdir );
641
644
strbuf_setlen (& rdir , rdir_len );
642
- changed_files (& tmp_modified , buf .buf , rdir .buf );
645
+ changed_files (repo , & tmp_modified , buf .buf , rdir .buf );
643
646
add_path (& rdir , rdir_len , name );
644
647
indices_loaded = 1 ;
645
648
}
@@ -713,7 +716,7 @@ static int run_file_diff(int prompt, const char *prefix,
713
716
int cmd_difftool (int argc ,
714
717
const char * * argv ,
715
718
const char * prefix ,
716
- struct repository * repo UNUSED )
719
+ struct repository * repo )
717
720
{
718
721
int use_gui_tool = -1 , dir_diff = 0 , prompt = -1 , tool_help = 0 , no_index = 0 ;
719
722
static char * difftool_cmd = NULL , * extcmd = NULL ;
@@ -749,7 +752,8 @@ int cmd_difftool(int argc,
749
752
};
750
753
struct child_process child = CHILD_PROCESS_INIT ;
751
754
752
- git_config (difftool_config , & dt_options );
755
+ if (repo )
756
+ repo_config (repo , difftool_config , & dt_options );
753
757
dt_options .symlinks = dt_options .has_symlinks ;
754
758
755
759
argc = parse_options (argc , argv , prefix , builtin_difftool_options ,
@@ -764,8 +768,8 @@ int cmd_difftool(int argc,
764
768
765
769
if (!no_index ){
766
770
setup_work_tree ();
767
- setenv (GIT_DIR_ENVIRONMENT , absolute_path (repo_get_git_dir (the_repository )), 1 );
768
- setenv (GIT_WORK_TREE_ENVIRONMENT , absolute_path (repo_get_work_tree (the_repository )), 1 );
771
+ setenv (GIT_DIR_ENVIRONMENT , absolute_path (repo_get_git_dir (repo )), 1 );
772
+ setenv (GIT_WORK_TREE_ENVIRONMENT , absolute_path (repo_get_work_tree (repo )), 1 );
769
773
} else if (dir_diff )
770
774
die (_ ("options '%s' and '%s' cannot be used together" ), "--dir-diff" , "--no-index" );
771
775
@@ -814,6 +818,6 @@ int cmd_difftool(int argc,
814
818
strvec_pushv (& child .args , argv );
815
819
816
820
if (dir_diff )
817
- return run_dir_diff (& dt_options , extcmd , prefix , & child );
821
+ return run_dir_diff (repo , & dt_options , extcmd , prefix , & child );
818
822
return run_file_diff (prompt , prefix , & child );
819
823
}
0 commit comments