@@ -70,7 +70,7 @@ static const char *format_from_name(const char *filename)
70
70
return NULL ;
71
71
ext ++ ;
72
72
if (!strcasecmp (ext , "zip" ))
73
- return "zip" ;
73
+ return "--format= zip" ;
74
74
return NULL ;
75
75
}
76
76
@@ -84,41 +84,39 @@ int cmd_archive(int argc, const char **argv, const char *prefix)
84
84
const char * exec = "git-upload-archive" ;
85
85
const char * output = NULL ;
86
86
const char * remote = NULL ;
87
- const char * format = NULL ;
87
+ const char * format_option = NULL ;
88
88
struct option local_opts [] = {
89
89
OPT_STRING ('o' , "output" , & output , "file" ,
90
90
"write the archive to this file" ),
91
91
OPT_STRING (0 , "remote" , & remote , "repo" ,
92
92
"retrieve the archive from remote repository <repo>" ),
93
93
OPT_STRING (0 , "exec" , & exec , "cmd" ,
94
94
"path to the remote git-upload-archive command" ),
95
- OPT_STRING (0 , "format" , & format , "fmt" , "archive format" ),
96
95
OPT_END ()
97
96
};
98
- char fmt_opt [32 ];
99
97
100
98
argc = parse_options (argc , argv , prefix , local_opts , NULL ,
101
99
PARSE_OPT_KEEP_ALL );
102
100
103
101
if (output ) {
104
102
create_output_file (output );
105
- if (!format )
106
- format = format_from_name (output );
103
+ format_option = format_from_name (output );
107
104
}
108
105
109
- if (format ) {
110
- sprintf (fmt_opt , "--format=%s" , format );
111
- /*
112
- * We have enough room in argv[] to muck it in place,
113
- * because either --format and/or --output must have
114
- * been given on the original command line if we get
115
- * to this point, and parse_options() must have eaten
116
- * it, i.e. we can add back one element to the array.
117
- * But argv[] may contain "--"; we should make it the
118
- * first option.
119
- */
106
+ /*
107
+ * We have enough room in argv[] to muck it in place, because
108
+ * --output must have been given on the original command line
109
+ * if we get to this point, and parse_options() must have eaten
110
+ * it, i.e. we can add back one element to the array.
111
+ *
112
+ * We add a fake --format option at the beginning, with the
113
+ * format inferred from our output filename. This way explicit
114
+ * --format options can override it, and the fake option is
115
+ * inserted before any "--" that might have been given.
116
+ */
117
+ if (format_option ) {
120
118
memmove (argv + 2 , argv + 1 , sizeof (* argv ) * argc );
121
- argv [1 ] = fmt_opt ;
119
+ argv [1 ] = format_option ;
122
120
argv [++ argc ] = NULL ;
123
121
}
124
122
0 commit comments