@@ -466,7 +466,8 @@ void add_exclude(const char *string, const char *base,
466
466
x -> el = el ;
467
467
}
468
468
469
- static void * read_skip_worktree_file_from_index (const char * path , size_t * size )
469
+ static void * read_skip_worktree_file_from_index (const char * path , size_t * size ,
470
+ struct sha1_stat * sha1_stat )
470
471
{
471
472
int pos , len ;
472
473
unsigned long sz ;
@@ -485,6 +486,10 @@ static void *read_skip_worktree_file_from_index(const char *path, size_t *size)
485
486
return NULL ;
486
487
}
487
488
* size = xsize_t (sz );
489
+ if (sha1_stat ) {
490
+ memset (& sha1_stat -> stat , 0 , sizeof (sha1_stat -> stat ));
491
+ hashcpy (sha1_stat -> sha1 , active_cache [pos ]-> sha1 );
492
+ }
488
493
return data ;
489
494
}
490
495
@@ -529,11 +534,18 @@ static void trim_trailing_spaces(char *buf)
529
534
* last_space = '\0' ;
530
535
}
531
536
532
- int add_excludes_from_file_to_list (const char * fname ,
533
- const char * base ,
534
- int baselen ,
535
- struct exclude_list * el ,
536
- int check_index )
537
+ /*
538
+ * Given a file with name "fname", read it (either from disk, or from
539
+ * the index if "check_index" is non-zero), parse it and store the
540
+ * exclude rules in "el".
541
+ *
542
+ * If "ss" is not NULL, compute SHA-1 of the exclude file and fill
543
+ * stat data from disk (only valid if add_excludes returns zero). If
544
+ * ss_valid is non-zero, "ss" must contain good value as input.
545
+ */
546
+ static int add_excludes (const char * fname , const char * base , int baselen ,
547
+ struct exclude_list * el , int check_index ,
548
+ struct sha1_stat * sha1_stat )
537
549
{
538
550
struct stat st ;
539
551
int fd , i , lineno = 1 ;
@@ -547,7 +559,7 @@ int add_excludes_from_file_to_list(const char *fname,
547
559
if (0 <= fd )
548
560
close (fd );
549
561
if (!check_index ||
550
- (buf = read_skip_worktree_file_from_index (fname , & size )) == NULL )
562
+ (buf = read_skip_worktree_file_from_index (fname , & size , sha1_stat )) == NULL )
551
563
return -1 ;
552
564
if (size == 0 ) {
553
565
free (buf );
@@ -560,6 +572,11 @@ int add_excludes_from_file_to_list(const char *fname,
560
572
} else {
561
573
size = xsize_t (st .st_size );
562
574
if (size == 0 ) {
575
+ if (sha1_stat ) {
576
+ fill_stat_data (& sha1_stat -> stat , & st );
577
+ hashcpy (sha1_stat -> sha1 , EMPTY_BLOB_SHA1_BIN );
578
+ sha1_stat -> valid = 1 ;
579
+ }
563
580
close (fd );
564
581
return 0 ;
565
582
}
@@ -571,6 +588,22 @@ int add_excludes_from_file_to_list(const char *fname,
571
588
}
572
589
buf [size ++ ] = '\n' ;
573
590
close (fd );
591
+ if (sha1_stat ) {
592
+ int pos ;
593
+ if (sha1_stat -> valid &&
594
+ !match_stat_data (& sha1_stat -> stat , & st ))
595
+ ; /* no content change, ss->sha1 still good */
596
+ else if (check_index &&
597
+ (pos = cache_name_pos (fname , strlen (fname ))) >= 0 &&
598
+ !ce_stage (active_cache [pos ]) &&
599
+ ce_uptodate (active_cache [pos ]) &&
600
+ !would_convert_to_git (fname ))
601
+ hashcpy (sha1_stat -> sha1 , active_cache [pos ]-> sha1 );
602
+ else
603
+ hash_sha1_file (buf , size , "blob" , sha1_stat -> sha1 );
604
+ fill_stat_data (& sha1_stat -> stat , & st );
605
+ sha1_stat -> valid = 1 ;
606
+ }
574
607
}
575
608
576
609
el -> filebuf = buf ;
@@ -589,6 +622,13 @@ int add_excludes_from_file_to_list(const char *fname,
589
622
return 0 ;
590
623
}
591
624
625
+ int add_excludes_from_file_to_list (const char * fname , const char * base ,
626
+ int baselen , struct exclude_list * el ,
627
+ int check_index )
628
+ {
629
+ return add_excludes (fname , base , baselen , el , check_index , NULL );
630
+ }
631
+
592
632
struct exclude_list * add_exclude_list (struct dir_struct * dir ,
593
633
int group_type , const char * src )
594
634
{
0 commit comments