@@ -516,103 +516,6 @@ static int handle_file(const char *path, unsigned char *sha1, const char *output
516
516
return hunk_no ;
517
517
}
518
518
519
- /*
520
- * Subclass of rerere_io that reads from an in-core buffer that is a
521
- * strbuf
522
- */
523
- struct rerere_io_mem {
524
- struct rerere_io io ;
525
- struct strbuf input ;
526
- };
527
-
528
- /*
529
- * ... and its getline() method implementation
530
- */
531
- static int rerere_mem_getline (struct strbuf * sb , struct rerere_io * io_ )
532
- {
533
- struct rerere_io_mem * io = (struct rerere_io_mem * )io_ ;
534
- char * ep ;
535
- size_t len ;
536
-
537
- strbuf_release (sb );
538
- if (!io -> input .len )
539
- return -1 ;
540
- ep = memchr (io -> input .buf , '\n' , io -> input .len );
541
- if (!ep )
542
- ep = io -> input .buf + io -> input .len ;
543
- else if (* ep == '\n' )
544
- ep ++ ;
545
- len = ep - io -> input .buf ;
546
- strbuf_add (sb , io -> input .buf , len );
547
- strbuf_remove (& io -> input , 0 , len );
548
- return 0 ;
549
- }
550
-
551
- static int handle_cache (const char * path , unsigned char * sha1 , const char * output )
552
- {
553
- mmfile_t mmfile [3 ] = {{NULL }};
554
- mmbuffer_t result = {NULL , 0 };
555
- const struct cache_entry * ce ;
556
- int pos , len , i , hunk_no ;
557
- struct rerere_io_mem io ;
558
- int marker_size = ll_merge_marker_size (path );
559
-
560
- /*
561
- * Reproduce the conflicted merge in-core
562
- */
563
- len = strlen (path );
564
- pos = cache_name_pos (path , len );
565
- if (0 <= pos )
566
- return -1 ;
567
- pos = - pos - 1 ;
568
-
569
- while (pos < active_nr ) {
570
- enum object_type type ;
571
- unsigned long size ;
572
-
573
- ce = active_cache [pos ++ ];
574
- if (ce_namelen (ce ) != len || memcmp (ce -> name , path , len ))
575
- break ;
576
- i = ce_stage (ce ) - 1 ;
577
- if (!mmfile [i ].ptr ) {
578
- mmfile [i ].ptr = read_sha1_file (ce -> sha1 , & type , & size );
579
- mmfile [i ].size = size ;
580
- }
581
- }
582
- for (i = 0 ; i < 3 ; i ++ )
583
- if (!mmfile [i ].ptr && !mmfile [i ].size )
584
- mmfile [i ].ptr = xstrdup ("" );
585
-
586
- /*
587
- * NEEDSWORK: handle conflicts from merges with
588
- * merge.renormalize set, too
589
- */
590
- ll_merge (& result , path , & mmfile [0 ], NULL ,
591
- & mmfile [1 ], "ours" ,
592
- & mmfile [2 ], "theirs" , NULL );
593
- for (i = 0 ; i < 3 ; i ++ )
594
- free (mmfile [i ].ptr );
595
-
596
- memset (& io , 0 , sizeof (io ));
597
- io .io .getline = rerere_mem_getline ;
598
- if (output )
599
- io .io .output = fopen (output , "w" );
600
- else
601
- io .io .output = NULL ;
602
- strbuf_init (& io .input , 0 );
603
- strbuf_attach (& io .input , result .ptr , result .size , result .size );
604
-
605
- /*
606
- * Grab the conflict ID and optionally write the original
607
- * contents with conflict markers out.
608
- */
609
- hunk_no = handle_path (sha1 , (struct rerere_io * )& io , marker_size );
610
- strbuf_release (& io .input );
611
- if (io .io .output )
612
- fclose (io .io .output );
613
- return hunk_no ;
614
- }
615
-
616
519
/*
617
520
* Look at a cache entry at "i" and see if it is not conflicting,
618
521
* conflicting and we are willing to handle, or conflicting and
@@ -1005,6 +908,103 @@ int rerere(int flags)
1005
908
return status ;
1006
909
}
1007
910
911
+ /*
912
+ * Subclass of rerere_io that reads from an in-core buffer that is a
913
+ * strbuf
914
+ */
915
+ struct rerere_io_mem {
916
+ struct rerere_io io ;
917
+ struct strbuf input ;
918
+ };
919
+
920
+ /*
921
+ * ... and its getline() method implementation
922
+ */
923
+ static int rerere_mem_getline (struct strbuf * sb , struct rerere_io * io_ )
924
+ {
925
+ struct rerere_io_mem * io = (struct rerere_io_mem * )io_ ;
926
+ char * ep ;
927
+ size_t len ;
928
+
929
+ strbuf_release (sb );
930
+ if (!io -> input .len )
931
+ return -1 ;
932
+ ep = memchr (io -> input .buf , '\n' , io -> input .len );
933
+ if (!ep )
934
+ ep = io -> input .buf + io -> input .len ;
935
+ else if (* ep == '\n' )
936
+ ep ++ ;
937
+ len = ep - io -> input .buf ;
938
+ strbuf_add (sb , io -> input .buf , len );
939
+ strbuf_remove (& io -> input , 0 , len );
940
+ return 0 ;
941
+ }
942
+
943
+ static int handle_cache (const char * path , unsigned char * sha1 , const char * output )
944
+ {
945
+ mmfile_t mmfile [3 ] = {{NULL }};
946
+ mmbuffer_t result = {NULL , 0 };
947
+ const struct cache_entry * ce ;
948
+ int pos , len , i , hunk_no ;
949
+ struct rerere_io_mem io ;
950
+ int marker_size = ll_merge_marker_size (path );
951
+
952
+ /*
953
+ * Reproduce the conflicted merge in-core
954
+ */
955
+ len = strlen (path );
956
+ pos = cache_name_pos (path , len );
957
+ if (0 <= pos )
958
+ return -1 ;
959
+ pos = - pos - 1 ;
960
+
961
+ while (pos < active_nr ) {
962
+ enum object_type type ;
963
+ unsigned long size ;
964
+
965
+ ce = active_cache [pos ++ ];
966
+ if (ce_namelen (ce ) != len || memcmp (ce -> name , path , len ))
967
+ break ;
968
+ i = ce_stage (ce ) - 1 ;
969
+ if (!mmfile [i ].ptr ) {
970
+ mmfile [i ].ptr = read_sha1_file (ce -> sha1 , & type , & size );
971
+ mmfile [i ].size = size ;
972
+ }
973
+ }
974
+ for (i = 0 ; i < 3 ; i ++ )
975
+ if (!mmfile [i ].ptr && !mmfile [i ].size )
976
+ mmfile [i ].ptr = xstrdup ("" );
977
+
978
+ /*
979
+ * NEEDSWORK: handle conflicts from merges with
980
+ * merge.renormalize set, too?
981
+ */
982
+ ll_merge (& result , path , & mmfile [0 ], NULL ,
983
+ & mmfile [1 ], "ours" ,
984
+ & mmfile [2 ], "theirs" , NULL );
985
+ for (i = 0 ; i < 3 ; i ++ )
986
+ free (mmfile [i ].ptr );
987
+
988
+ memset (& io , 0 , sizeof (io ));
989
+ io .io .getline = rerere_mem_getline ;
990
+ if (output )
991
+ io .io .output = fopen (output , "w" );
992
+ else
993
+ io .io .output = NULL ;
994
+ strbuf_init (& io .input , 0 );
995
+ strbuf_attach (& io .input , result .ptr , result .size , result .size );
996
+
997
+ /*
998
+ * Grab the conflict ID and optionally write the original
999
+ * contents with conflict markers out.
1000
+ */
1001
+ hunk_no = handle_path (sha1 , (struct rerere_io * )& io , marker_size );
1002
+ strbuf_release (& io .input );
1003
+ if (io .io .output )
1004
+ fclose (io .io .output );
1005
+ return hunk_no ;
1006
+ }
1007
+
1008
1008
static int rerere_forget_one_path (const char * path , struct string_list * rr )
1009
1009
{
1010
1010
const char * filename ;
0 commit comments