5
5
#include "walker.h"
6
6
7
7
static const char http_fetch_usage [] = "git http-fetch "
8
- "[-c] [-t] [-a] [-v] [--recover] [-w ref] [--stdin] commit-id url" ;
8
+ "[-c] [-t] [-a] [-v] [--recover] [-w ref] [--stdin | --packfile | commit-id] url" ;
9
9
10
10
int cmd_main (int argc , const char * * argv )
11
11
{
@@ -19,6 +19,7 @@ int cmd_main(int argc, const char **argv)
19
19
int rc = 0 ;
20
20
int get_verbosely = 0 ;
21
21
int get_recover = 0 ;
22
+ int packfile = 0 ;
22
23
23
24
while (arg < argc && argv [arg ][0 ] == '-' ) {
24
25
if (argv [arg ][1 ] == 't' ) {
@@ -35,43 +36,80 @@ int cmd_main(int argc, const char **argv)
35
36
get_recover = 1 ;
36
37
} else if (!strcmp (argv [arg ], "--stdin" )) {
37
38
commits_on_stdin = 1 ;
39
+ } else if (!strcmp (argv [arg ], "--packfile" )) {
40
+ packfile = 1 ;
38
41
}
39
42
arg ++ ;
40
43
}
41
- if (argc != arg + 2 - commits_on_stdin )
44
+ if (argc != arg + 2 - ( commits_on_stdin || packfile ) )
42
45
usage (http_fetch_usage );
43
46
if (commits_on_stdin ) {
44
47
commits = walker_targets_stdin (& commit_id , & write_ref );
48
+ } else if (packfile ) {
49
+ /* URL will be set later */
45
50
} else {
46
51
commit_id = (char * * ) & argv [arg ++ ];
47
52
commits = 1 ;
48
53
}
49
54
50
- if (argv [arg ])
51
- str_end_url_with_slash (argv [arg ], & url );
55
+ if (packfile ) {
56
+ url = xstrdup (argv [arg ]);
57
+ } else {
58
+ if (argv [arg ])
59
+ str_end_url_with_slash (argv [arg ], & url );
60
+ }
52
61
53
62
setup_git_directory ();
54
63
55
64
git_config (git_default_config , NULL );
56
65
57
66
http_init (NULL , url , 0 );
58
- walker = get_http_walker (url );
59
- walker -> get_verbosely = get_verbosely ;
60
- walker -> get_recover = get_recover ;
61
67
62
- rc = walker_fetch (walker , commits , commit_id , write_ref , url );
68
+ if (packfile ) {
69
+ struct http_pack_request * preq ;
70
+ struct slot_results results ;
71
+ int ret ;
72
+
73
+ preq = new_http_pack_request (NULL , url );
74
+ if (preq == NULL )
75
+ die ("couldn't create http pack request" );
76
+ preq -> slot -> results = & results ;
77
+ preq -> generate_keep = 1 ;
78
+
79
+ if (start_active_slot (preq -> slot )) {
80
+ run_active_slot (preq -> slot );
81
+ if (results .curl_result != CURLE_OK ) {
82
+ die ("Unable to get pack file %s\n%s" , preq -> url ,
83
+ curl_errorstr );
84
+ }
85
+ } else {
86
+ die ("Unable to start request" );
87
+ }
88
+
89
+ if ((ret = finish_http_pack_request (preq )))
90
+ die ("finish_http_pack_request gave result %d" , ret );
91
+ release_http_pack_request (preq );
92
+ rc = 0 ;
93
+ } else {
94
+ walker = get_http_walker (url );
95
+ walker -> get_verbosely = get_verbosely ;
96
+ walker -> get_recover = get_recover ;
97
+
98
+ rc = walker_fetch (walker , commits , commit_id , write_ref , url );
63
99
64
- if (commits_on_stdin )
65
- walker_targets_free (commits , commit_id , write_ref );
100
+ if (commits_on_stdin )
101
+ walker_targets_free (commits , commit_id , write_ref );
66
102
67
- if (walker -> corrupt_object_found ) {
68
- fprintf (stderr ,
103
+ if (walker -> corrupt_object_found ) {
104
+ fprintf (stderr ,
69
105
"Some loose object were found to be corrupt, but they might be just\n"
70
106
"a false '404 Not Found' error message sent with incorrect HTTP\n"
71
107
"status code. Suggest running 'git fsck'.\n" );
108
+ }
109
+
110
+ walker_free (walker );
72
111
}
73
112
74
- walker_free (walker );
75
113
http_cleanup ();
76
114
77
115
free (url );
0 commit comments