@@ -376,7 +376,8 @@ struct ref **get_remote_heads(struct packet_reader *reader,
376376}
377377
378378/* Returns 1 when a valid ref has been added to `list`, 0 otherwise */
379- static int process_ref_v2 (struct packet_reader * reader , struct ref * * * list )
379+ static int process_ref_v2 (struct packet_reader * reader , struct ref * * * list ,
380+ char * * unborn_head_target )
380381{
381382 int ret = 1 ;
382383 int i = 0 ;
@@ -397,6 +398,25 @@ static int process_ref_v2(struct packet_reader *reader, struct ref ***list)
397398 goto out ;
398399 }
399400
401+ if (!strcmp ("unborn" , line_sections .items [i ].string )) {
402+ i ++ ;
403+ if (unborn_head_target &&
404+ !strcmp ("HEAD" , line_sections .items [i ++ ].string )) {
405+ /*
406+ * Look for the symref target (if any). If found,
407+ * return it to the caller.
408+ */
409+ for (; i < line_sections .nr ; i ++ ) {
410+ const char * arg = line_sections .items [i ].string ;
411+
412+ if (skip_prefix (arg , "symref-target:" , & arg )) {
413+ * unborn_head_target = xstrdup (arg );
414+ break ;
415+ }
416+ }
417+ }
418+ goto out ;
419+ }
400420 if (parse_oid_hex_algop (line_sections .items [i ++ ].string , & old_oid , & end , reader -> hash_algo ) ||
401421 * end ) {
402422 ret = 0 ;
@@ -453,12 +473,16 @@ void check_stateless_delimiter(int stateless_rpc,
453473
454474struct ref * * get_remote_refs (int fd_out , struct packet_reader * reader ,
455475 struct ref * * list , int for_push ,
456- const struct strvec * ref_prefixes ,
476+ struct transport_ls_refs_options * transport_options ,
457477 const struct string_list * server_options ,
458478 int stateless_rpc )
459479{
460480 int i ;
461481 const char * hash_name ;
482+ struct strvec * ref_prefixes = transport_options ?
483+ & transport_options -> ref_prefixes : NULL ;
484+ char * * unborn_head_target = transport_options ?
485+ & transport_options -> unborn_head_target : NULL ;
462486 * list = NULL ;
463487
464488 if (server_supports_v2 ("ls-refs" , 1 ))
@@ -488,6 +512,8 @@ struct ref **get_remote_refs(int fd_out, struct packet_reader *reader,
488512 if (!for_push )
489513 packet_write_fmt (fd_out , "peel\n" );
490514 packet_write_fmt (fd_out , "symrefs\n" );
515+ if (server_supports_feature ("ls-refs" , "unborn" , 0 ))
516+ packet_write_fmt (fd_out , "unborn\n" );
491517 for (i = 0 ; ref_prefixes && i < ref_prefixes -> nr ; i ++ ) {
492518 packet_write_fmt (fd_out , "ref-prefix %s\n" ,
493519 ref_prefixes -> v [i ]);
@@ -496,7 +522,7 @@ struct ref **get_remote_refs(int fd_out, struct packet_reader *reader,
496522
497523 /* Process response from server */
498524 while (packet_reader_read (reader ) == PACKET_READ_NORMAL ) {
499- if (!process_ref_v2 (reader , & list ))
525+ if (!process_ref_v2 (reader , & list , unborn_head_target ))
500526 die (_ ("invalid ls-refs response: %s" ), reader -> line );
501527 }
502528
0 commit comments