@@ -29,6 +29,7 @@ static unsigned long oldest_have;
29
29
static int multi_ack , nr_our_refs ;
30
30
static int use_thin_pack , use_ofs_delta , use_include_tag ;
31
31
static int no_progress ;
32
+ static int shallow_nr ;
32
33
static struct object_array have_obj ;
33
34
static struct object_array want_obj ;
34
35
static unsigned int timeout ;
@@ -107,8 +108,6 @@ static int do_rev_list(int fd, void *create_full_pack)
107
108
struct rev_info revs ;
108
109
109
110
pack_pipe = fdopen (fd , "w" );
110
- if (create_full_pack )
111
- use_thin_pack = 0 ; /* no point doing it */
112
111
init_revisions (& revs , NULL );
113
112
revs .tag_objects = 1 ;
114
113
revs .tree_objects = 1 ;
@@ -155,13 +154,21 @@ static void create_pack_file(void)
155
154
const char * argv [10 ];
156
155
int arg = 0 ;
157
156
158
- rev_list .proc = do_rev_list ;
159
- /* .data is just a boolean: any non-NULL value will do */
160
- rev_list .data = create_full_pack ? & rev_list : NULL ;
161
- if (start_async (& rev_list ))
162
- die ("git upload-pack: unable to fork git-rev-list" );
157
+ if (shallow_nr ) {
158
+ rev_list .proc = do_rev_list ;
159
+ rev_list .data = 0 ;
160
+ if (start_async (& rev_list ))
161
+ die ("git upload-pack: unable to fork git-rev-list" );
162
+ argv [arg ++ ] = "pack-objects" ;
163
+ } else {
164
+ argv [arg ++ ] = "pack-objects" ;
165
+ argv [arg ++ ] = "--revs" ;
166
+ if (create_full_pack )
167
+ argv [arg ++ ] = "--all" ;
168
+ else if (use_thin_pack )
169
+ argv [arg ++ ] = "--thin" ;
170
+ }
163
171
164
- argv [arg ++ ] = "pack-objects" ;
165
172
argv [arg ++ ] = "--stdout" ;
166
173
if (!no_progress )
167
174
argv [arg ++ ] = "--progress" ;
@@ -172,7 +179,7 @@ static void create_pack_file(void)
172
179
argv [arg ++ ] = NULL ;
173
180
174
181
memset (& pack_objects , 0 , sizeof (pack_objects ));
175
- pack_objects .in = rev_list .out ; /* start_command closes it */
182
+ pack_objects .in = shallow_nr ? rev_list .out : -1 ;
176
183
pack_objects .out = -1 ;
177
184
pack_objects .err = -1 ;
178
185
pack_objects .git_cmd = 1 ;
@@ -181,6 +188,24 @@ static void create_pack_file(void)
181
188
if (start_command (& pack_objects ))
182
189
die ("git upload-pack: unable to fork git-pack-objects" );
183
190
191
+ /* pass on revisions we (don't) want */
192
+ if (!shallow_nr ) {
193
+ FILE * pipe_fd = fdopen (pack_objects .in , "w" );
194
+ if (!create_full_pack ) {
195
+ int i ;
196
+ for (i = 0 ; i < want_obj .nr ; i ++ )
197
+ fprintf (pipe_fd , "%s\n" , sha1_to_hex (want_obj .objects [i ].item -> sha1 ));
198
+ fprintf (pipe_fd , "--not\n" );
199
+ for (i = 0 ; i < have_obj .nr ; i ++ )
200
+ fprintf (pipe_fd , "%s\n" , sha1_to_hex (have_obj .objects [i ].item -> sha1 ));
201
+ }
202
+
203
+ fprintf (pipe_fd , "\n" );
204
+ fflush (pipe_fd );
205
+ fclose (pipe_fd );
206
+ }
207
+
208
+
184
209
/* We read from pack_objects.err to capture stderr output for
185
210
* progress bar, and pack_objects.out to capture the pack data.
186
211
*/
@@ -276,7 +301,7 @@ static void create_pack_file(void)
276
301
error ("git upload-pack: git-pack-objects died with error." );
277
302
goto fail ;
278
303
}
279
- if (finish_async (& rev_list ))
304
+ if (shallow_nr && finish_async (& rev_list ))
280
305
goto fail ; /* error was already reported */
281
306
282
307
/* flush the data */
@@ -451,6 +476,7 @@ static void receive_needs(void)
451
476
static char line [1000 ];
452
477
int len , depth = 0 ;
453
478
479
+ shallow_nr = 0 ;
454
480
if (debug_fd )
455
481
write_in_full (debug_fd , "#S\n" , 3 );
456
482
for (;;) {
@@ -534,6 +560,7 @@ static void receive_needs(void)
534
560
packet_write (1 , "shallow %s" ,
535
561
sha1_to_hex (object -> sha1 ));
536
562
register_shallow (object -> sha1 );
563
+ shallow_nr ++ ;
537
564
}
538
565
result = result -> next ;
539
566
}
@@ -567,6 +594,8 @@ static void receive_needs(void)
567
594
for (i = 0 ; i < shallows .nr ; i ++ )
568
595
register_shallow (shallows .objects [i ].item -> sha1 );
569
596
}
597
+
598
+ shallow_nr += shallows .nr ;
570
599
free (shallows .objects );
571
600
}
572
601
0 commit comments