@@ -5990,6 +5990,22 @@ static int remove_space(char *line, int len)
59905990 return dst - line ;
59915991}
59925992
5993+ void flush_one_hunk (struct object_id * result , git_SHA_CTX * ctx )
5994+ {
5995+ unsigned char hash [GIT_MAX_RAWSZ ];
5996+ unsigned short carry = 0 ;
5997+ int i ;
5998+
5999+ git_SHA1_Final (hash , ctx );
6000+ git_SHA1_Init (ctx );
6001+ /* 20-byte sum, with carry */
6002+ for (i = 0 ; i < GIT_SHA1_RAWSZ ; ++ i ) {
6003+ carry += result -> hash [i ] + hash [i ];
6004+ result -> hash [i ] = carry ;
6005+ carry >>= 8 ;
6006+ }
6007+ }
6008+
59936009static void patch_id_consume (void * priv , char * line , unsigned long len )
59946010{
59956011 struct patch_id_t * data = priv ;
@@ -6014,8 +6030,8 @@ static void patch_id_add_mode(git_SHA_CTX *ctx, unsigned mode)
60146030 git_SHA1_Update (ctx , buf , len );
60156031}
60166032
6017- /* returns 0 upon success, and writes result into sha1 */
6018- static int diff_get_patch_id (struct diff_options * options , struct object_id * oid , int diff_header_only )
6033+ /* returns 0 upon success, and writes result into oid */
6034+ static int diff_get_patch_id (struct diff_options * options , struct object_id * oid , int diff_header_only , int stable )
60196035{
60206036 struct diff_queue_struct * q = & diff_queued_diff ;
60216037 int i ;
@@ -6025,6 +6041,7 @@ static int diff_get_patch_id(struct diff_options *options, struct object_id *oid
60256041 git_SHA1_Init (& ctx );
60266042 memset (& data , 0 , sizeof (struct patch_id_t ));
60276043 data .ctx = & ctx ;
6044+ oidclr (oid );
60286045
60296046 for (i = 0 ; i < q -> nr ; i ++ ) {
60306047 xpparam_t xpp ;
@@ -6100,17 +6117,22 @@ static int diff_get_patch_id(struct diff_options *options, struct object_id *oid
61006117 patch_id_consume , & data , & xpp , & xecfg ))
61016118 return error ("unable to generate patch-id diff for %s" ,
61026119 p -> one -> path );
6120+
6121+ if (stable )
6122+ flush_one_hunk (oid , & ctx );
61036123 }
61046124
6105- git_SHA1_Final (oid -> hash , & ctx );
6125+ if (!stable )
6126+ git_SHA1_Final (oid -> hash , & ctx );
6127+
61066128 return 0 ;
61076129}
61086130
6109- int diff_flush_patch_id (struct diff_options * options , struct object_id * oid , int diff_header_only )
6131+ int diff_flush_patch_id (struct diff_options * options , struct object_id * oid , int diff_header_only , int stable )
61106132{
61116133 struct diff_queue_struct * q = & diff_queued_diff ;
61126134 int i ;
6113- int result = diff_get_patch_id (options , oid , diff_header_only );
6135+ int result = diff_get_patch_id (options , oid , diff_header_only , stable );
61146136
61156137 for (i = 0 ; i < q -> nr ; i ++ )
61166138 diff_free_filepair (q -> queue [i ]);
0 commit comments