@matheusbsbs / matheus-bagliano / commits / e5fba602e5
Fork 0

textconv: support for cat_file

Make the textconv_object function public, and add --textconv option to cat-file to perform conversion on blob objects. Using --textconv implies that we are working on a blob. As files drivers need to be initialized, a new config is required in addition to git_default_config. Therefore git_cat_file_config() is introduced Signed-off-by: Clément Poulain <clement.poulain@ensimag.imag.fr> Signed-off-by: Diane Gasselin <diane.gasselin@ensimag.imag.fr> Signed-off-by: Axel Bonnet <axel.bonnet@ensimag.imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Clément Poulain committed Jun 15, 2010 at 17:50 UTC e5fba602e59292c8c383a7a587897b5f7cbd5c78
3 files changed +40 -8
builtin.h
+2
@@ -36,6 +36,8 @@ void finish_copy_notes_for_rewrite(struct notes_rewrite_cfg *c);
36
37 extern int check_pager_config(const char *cmd);
38
39 +extern int textconv_object(const char *path, const unsigned char *sha1, char **buf, unsigned long *buf_size);
40 +
41 extern int cmd_add(int argc, const char **argv, const char *prefix);
42 extern int cmd_annotate(int argc, const char **argv, const char *prefix);
43 extern int cmd_apply(int argc, const char **argv, const char *prefix);
builtin/blame.c
+4 -4
@@ -91,10 +91,10 @@ struct origin {
91 * if the textconv driver exists.
92 * Return 1 if the conversion succeeds, 0 otherwise.
93 */
94 -static int textconv_object(const char *path,
95 - const unsigned char *sha1,
96 - char **buf,
97 - unsigned long *buf_size)
94 +int textconv_object(const char *path,
95 + const unsigned char *sha1,
96 + char **buf,
97 + unsigned long *buf_size)
98 {
99 struct diff_filespec *df;
100 struct userdiff_driver *textconv;
builtin/cat-file.c
+34 -4
@@ -9,6 +9,8 @@
9 #include "tree.h"
10 #include "builtin.h"
11 #include "parse-options.h"
12 +#include "diff.h"
13 +#include "userdiff.h"
14
15 #define BATCH 1
16 #define BATCH_CHECK 2
@@ -84,10 +86,11 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
86 {
87 unsigned char sha1[20];
88 enum object_type type;
87 - void *buf;
89 + char *buf;
90 unsigned long size;
91 + struct object_context obj_context;
92
90 - if (get_sha1(obj_name, sha1))
93 + if (get_sha1_with_context(obj_name, sha1, &obj_context))
94 die("Not a valid object name %s", obj_name);
95
96 buf = NULL;
@@ -132,6 +135,17 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
135
136 /* otherwise just spit out the data */
137 break;
138 +
139 + case 'c':
140 + if (!obj_context.path[0])
141 + die("git cat-file --textconv %s: <object> must be <sha1:path>",
142 + obj_name);
143 +
144 + if (!textconv_object(obj_context.path, sha1, &buf, &size))
145 + die("git cat-file --textconv: unable to run textconv on %s",
146 + obj_name);
147 + break;
148 +
149 case 0:
150 buf = read_object_with_reference(sha1, exp_type, &size, NULL);
151 break;
@@ -201,11 +215,25 @@ static int batch_objects(int print_contents)
215 }
216
217 static const char * const cat_file_usage[] = {
204 - "git cat-file (-t|-s|-e|-p|<type>) <object>",
218 + "git cat-file (-t|-s|-e|-p|<type>|--textconv) <object>",
219 "git cat-file (--batch|--batch-check) < <list_of_objects>",
220 NULL
221 };
222
223 +static int git_cat_file_config(const char *var, const char *value, void *cb)
224 +{
225 + switch (userdiff_config(var, value)) {
226 + case 0:
227 + break;
228 + case -1:
229 + return -1;
230 + default:
231 + return 0;
232 + }
233 +
234 + return git_default_config(var, value, cb);
235 +}
236 +
237 int cmd_cat_file(int argc, const char **argv, const char *prefix)
238 {
239 int opt = 0, batch = 0;
@@ -218,6 +246,8 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
246 OPT_SET_INT('e', NULL, &opt,
247 "exit with zero when there's no error", 'e'),
248 OPT_SET_INT('p', NULL, &opt, "pretty-print object's content", 'p'),
249 + OPT_SET_INT(0, "textconv", &opt,
250 + "for blob objects, run textconv on object's content", 'c'),
251 OPT_SET_INT(0, "batch", &batch,
252 "show info and content of objects fed from the standard input",
253 BATCH),
@@ -227,7 +257,7 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
257 OPT_END()
258 };
259
230 - git_config(git_default_config, NULL);
260 + git_config(git_cat_file_config, NULL);
261
262 if (argc != 3 && argc != 2)
263 usage_with_options(cat_file_usage, options);