1212#include "run-command.h"
1313#include "sigchain.h"
1414#include "version.h"
15+ #include "string-list.h"
1516
1617static const char upload_pack_usage [] = "git upload-pack [--strict] [--timeout=<n>] <dir>" ;
1718
@@ -28,7 +29,7 @@ static const char upload_pack_usage[] = "git upload-pack [--strict] [--timeout=<
2829
2930static unsigned long oldest_have ;
3031
31- static int multi_ack , nr_our_refs ;
32+ static int multi_ack ;
3233static int no_done ;
3334static int use_thin_pack , use_ofs_delta , use_include_tag ;
3435static int no_progress , daemon_mode ;
@@ -139,7 +140,6 @@ static void create_pack_file(void)
139140{
140141 struct async rev_list ;
141142 struct child_process pack_objects ;
142- int create_full_pack = (nr_our_refs == want_obj .nr && !have_obj .nr );
143143 char data [8193 ], progress [128 ];
144144 char abort_msg [] = "aborting due to possible repository "
145145 "corruption on the remote side." ;
@@ -151,9 +151,7 @@ static void create_pack_file(void)
151151 argv [arg ++ ] = "pack-objects" ;
152152 if (!shallow_nr ) {
153153 argv [arg ++ ] = "--revs" ;
154- if (create_full_pack )
155- argv [arg ++ ] = "--all" ;
156- else if (use_thin_pack )
154+ if (use_thin_pack )
157155 argv [arg ++ ] = "--thin" ;
158156 }
159157
@@ -185,15 +183,15 @@ static void create_pack_file(void)
185183 }
186184 else {
187185 FILE * pipe_fd = xfdopen (pack_objects .in , "w" );
188- if (!create_full_pack ) {
189- int i ;
190- for (i = 0 ; i < want_obj .nr ; i ++ )
191- fprintf (pipe_fd , "%s\n" , sha1_to_hex (want_obj .objects [i ].item -> sha1 ));
192- fprintf (pipe_fd , "--not\n" );
193- for (i = 0 ; i < have_obj .nr ; i ++ )
194- fprintf (pipe_fd , "%s\n" , sha1_to_hex (have_obj .objects [i ].item -> sha1 ));
195- }
186+ int i ;
196187
188+ for (i = 0 ; i < want_obj .nr ; i ++ )
189+ fprintf (pipe_fd , "%s\n" ,
190+ sha1_to_hex (want_obj .objects [i ].item -> sha1 ));
191+ fprintf (pipe_fd , "--not\n" );
192+ for (i = 0 ; i < have_obj .nr ; i ++ )
193+ fprintf (pipe_fd , "%s\n" ,
194+ sha1_to_hex (have_obj .objects [i ].item -> sha1 ));
197195 fprintf (pipe_fd , "\n" );
198196 fflush (pipe_fd );
199197 fclose (pipe_fd );
@@ -729,15 +727,30 @@ static void receive_needs(void)
729727 free (shallows .objects );
730728}
731729
730+ /* return non-zero if the ref is hidden, otherwise 0 */
731+ static int mark_our_ref (const char * refname , const unsigned char * sha1 , int flag , void * cb_data )
732+ {
733+ struct object * o = lookup_unknown_object (sha1 );
734+
735+ if (ref_is_hidden (refname ))
736+ return 1 ;
737+ if (!o )
738+ die ("git upload-pack: cannot find object %s:" , sha1_to_hex (sha1 ));
739+ o -> flags |= OUR_REF ;
740+ return 0 ;
741+ }
742+
732743static int send_ref (const char * refname , const unsigned char * sha1 , int flag , void * cb_data )
733744{
734745 static const char * capabilities = "multi_ack thin-pack side-band"
735746 " side-band-64k ofs-delta shallow no-progress"
736747 " include-tag multi_ack_detailed" ;
737- struct object * o = lookup_unknown_object (sha1 );
738748 const char * refname_nons = strip_namespace (refname );
739749 unsigned char peeled [20 ];
740750
751+ if (mark_our_ref (refname , sha1 , flag , cb_data ))
752+ return 0 ;
753+
741754 if (capabilities )
742755 packet_write (1 , "%s %s%c%s%s agent=%s\n" ,
743756 sha1_to_hex (sha1 ), refname_nons ,
@@ -747,27 +760,11 @@ static int send_ref(const char *refname, const unsigned char *sha1, int flag, vo
747760 else
748761 packet_write (1 , "%s %s\n" , sha1_to_hex (sha1 ), refname_nons );
749762 capabilities = NULL ;
750- if (!(o -> flags & OUR_REF )) {
751- o -> flags |= OUR_REF ;
752- nr_our_refs ++ ;
753- }
754763 if (!peel_ref (refname , peeled ))
755764 packet_write (1 , "%s %s^{}\n" , sha1_to_hex (peeled ), refname_nons );
756765 return 0 ;
757766}
758767
759- static int mark_our_ref (const char * refname , const unsigned char * sha1 , int flag , void * cb_data )
760- {
761- struct object * o = parse_object (sha1 );
762- if (!o )
763- die ("git upload-pack: cannot find object %s:" , sha1_to_hex (sha1 ));
764- if (!(o -> flags & OUR_REF )) {
765- o -> flags |= OUR_REF ;
766- nr_our_refs ++ ;
767- }
768- return 0 ;
769- }
770-
771768static void upload_pack (void )
772769{
773770 if (advertise_refs || !stateless_rpc ) {
@@ -789,6 +786,11 @@ static void upload_pack(void)
789786 }
790787}
791788
789+ static int upload_pack_config (const char * var , const char * value , void * unused )
790+ {
791+ return parse_hide_refs_config (var , value , "uploadpack" );
792+ }
793+
792794int main (int argc , char * * argv )
793795{
794796 char * dir ;
@@ -840,6 +842,7 @@ int main(int argc, char **argv)
840842 die ("'%s' does not appear to be a git repository" , dir );
841843 if (is_repository_shallow ())
842844 die ("attempt to fetch/clone from a shallow repository" );
845+ git_config (upload_pack_config , NULL );
843846 if (getenv ("GIT_DEBUG_SEND_PACK" ))
844847 debug_fd = atoi (getenv ("GIT_DEBUG_SEND_PACK" ));
845848 upload_pack ();
0 commit comments