@@ -756,8 +756,33 @@ static int sideband_demux(int in, int out, void *data)
756
756
return ret ;
757
757
}
758
758
759
+ static void write_promisor_file (const char * keep_name ,
760
+ struct ref * * sought , int nr_sought )
761
+ {
762
+ struct strbuf promisor_name = STRBUF_INIT ;
763
+ int suffix_stripped ;
764
+ FILE * output ;
765
+ int i ;
766
+
767
+ strbuf_addstr (& promisor_name , keep_name );
768
+ suffix_stripped = strbuf_strip_suffix (& promisor_name , ".keep" );
769
+ if (!suffix_stripped )
770
+ BUG ("name of pack lockfile should end with .keep (was '%s')" ,
771
+ keep_name );
772
+ strbuf_addstr (& promisor_name , ".promisor" );
773
+
774
+ output = xfopen (promisor_name .buf , "w" );
775
+ for (i = 0 ; i < nr_sought ; i ++ )
776
+ fprintf (output , "%s %s\n" , oid_to_hex (& sought [i ]-> old_oid ),
777
+ sought [i ]-> name );
778
+ fclose (output );
779
+
780
+ strbuf_release (& promisor_name );
781
+ }
782
+
759
783
static int get_pack (struct fetch_pack_args * args ,
760
- int xd [2 ], char * * pack_lockfile )
784
+ int xd [2 ], char * * pack_lockfile ,
785
+ struct ref * * sought , int nr_sought )
761
786
{
762
787
struct async demux ;
763
788
int do_keep = args -> keep_pack ;
@@ -819,7 +844,13 @@ static int get_pack(struct fetch_pack_args *args,
819
844
}
820
845
if (args -> check_self_contained_and_connected )
821
846
argv_array_push (& cmd .args , "--check-self-contained-and-connected" );
822
- if (args -> from_promisor )
847
+ /*
848
+ * If we're obtaining the filename of a lockfile, we'll use
849
+ * that filename to write a .promisor file with more
850
+ * information below. If not, we need index-pack to do it for
851
+ * us.
852
+ */
853
+ if (!(do_keep && pack_lockfile ) && args -> from_promisor )
823
854
argv_array_push (& cmd .args , "--promisor" );
824
855
}
825
856
else {
@@ -873,6 +904,14 @@ static int get_pack(struct fetch_pack_args *args,
873
904
die (_ ("%s failed" ), cmd_name );
874
905
if (use_sideband && finish_async (& demux ))
875
906
die (_ ("error in sideband demultiplexer" ));
907
+
908
+ /*
909
+ * Now that index-pack has succeeded, write the promisor file using the
910
+ * obtained .keep filename if necessary
911
+ */
912
+ if (do_keep && pack_lockfile && args -> from_promisor )
913
+ write_promisor_file (* pack_lockfile , sought , nr_sought );
914
+
876
915
return 0 ;
877
916
}
878
917
@@ -1008,7 +1047,7 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
1008
1047
alternate_shallow_file = setup_temporary_shallow (si -> shallow );
1009
1048
else
1010
1049
alternate_shallow_file = NULL ;
1011
- if (get_pack (args , fd , pack_lockfile ))
1050
+ if (get_pack (args , fd , pack_lockfile , sought , nr_sought ))
1012
1051
die (_ ("git fetch-pack: fetch failed." ));
1013
1052
1014
1053
all_done :
@@ -1464,7 +1503,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
1464
1503
1465
1504
/* get the pack */
1466
1505
process_section_header (& reader , "packfile" , 0 );
1467
- if (get_pack (args , fd , pack_lockfile ))
1506
+ if (get_pack (args , fd , pack_lockfile , sought , nr_sought ))
1468
1507
die (_ ("git fetch-pack: fetch failed." ));
1469
1508
1470
1509
state = FETCH_DONE ;
0 commit comments