1+ #include <ctype.h>
12#include "cache.h"
23#include "object.h"
34#include "delta.h"
@@ -17,7 +18,7 @@ struct object_entry {
1718 unsigned long size ;
1819 unsigned long offset ;
1920 unsigned int depth ;
20- unsigned int flags ;
21+ unsigned int hash ;
2122 enum object_type type ;
2223 unsigned long delta_size ;
2324 struct object_entry * delta ;
@@ -182,7 +183,7 @@ static void write_index_file(void)
182183 fclose (f );
183184}
184185
185- static void add_object_entry (unsigned char * sha1 )
186+ static void add_object_entry (unsigned char * sha1 , unsigned int hash )
186187{
187188 unsigned int idx = nr_objects ;
188189 struct object_entry * entry ;
@@ -195,6 +196,7 @@ static void add_object_entry(unsigned char *sha1)
195196 entry = objects + idx ;
196197 memset (entry , 0 , sizeof (* entry ));
197198 memcpy (entry -> sha1 , sha1 , 20 );
199+ entry -> hash = hash ;
198200 nr_objects = idx + 1 ;
199201}
200202
@@ -267,6 +269,10 @@ static int type_size_sort(const struct object_entry *a, const struct object_entr
267269 return -1 ;
268270 if (a -> type > b -> type )
269271 return 1 ;
272+ if (a -> hash < b -> hash )
273+ return -1 ;
274+ if (a -> hash > b -> hash )
275+ return 1 ;
270276 if (a -> size < b -> size )
271277 return -1 ;
272278 if (a -> size > b -> size )
@@ -319,6 +325,8 @@ static int try_delta(struct unpacked *cur, struct unpacked *old, unsigned max_de
319325 max_size = size / 2 - 20 ;
320326 if (cur_entry -> delta )
321327 max_size = cur_entry -> delta_size - 1 ;
328+ if (sizediff >= max_size )
329+ return -1 ;
322330 delta_buf = diff_delta (old -> data , oldsize ,
323331 cur -> data , size , & delta_size , max_size );
324332 if (!delta_buf )
@@ -371,7 +379,7 @@ static void find_deltas(struct object_entry **list, int window, int depth)
371379
372380int main (int argc , char * * argv )
373381{
374- char line [128 ];
382+ char line [PATH_MAX + 20 ];
375383 int window = 10 , depth = 10 ;
376384 int i ;
377385
@@ -404,10 +412,21 @@ int main(int argc, char **argv)
404412 usage (pack_usage );
405413
406414 while (fgets (line , sizeof (line ), stdin ) != NULL ) {
415+ unsigned int hash ;
416+ char * p ;
407417 unsigned char sha1 [20 ];
418+
408419 if (get_sha1_hex (line , sha1 ))
409420 die ("expected sha1, got garbage" );
410- add_object_entry (sha1 );
421+ hash = 0 ;
422+ p = line + 40 ;
423+ while (* p ) {
424+ unsigned char c = * p ++ ;
425+ if (isspace (c ))
426+ continue ;
427+ hash = hash * 11 + c ;
428+ }
429+ add_object_entry (sha1 , hash );
411430 }
412431 get_object_details ();
413432
0 commit comments