From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?UTF-8?q?Cl=C3=A9ment=20Poulain?= Subject: [PATCH v3 2/4] textconv: support for cat_file Date: Tue, 15 Jun 2010 17:50:28 +0200 Message-ID: <1276617028-5265-1-git-send-email-clement.poulain@ensimag.imag.fr> References: <1276102929-31712-1-git-send-email-clement.poulain@ensimag.imag.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: =?UTF-8?q?Cl=C3=A9ment=20Poulain?= , Diane Gasselin , Axel Bonnet To: git@vger.kernel.org X-From: git-owner@vger.kernel.org Tue Jun 15 17:50:56 2010 connect(): No such file or directory Return-path: Envelope-to: gcvg-git-2@lo.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1OOYPf-00026X-Rf for gcvg-git-2@lo.gmane.org; Tue, 15 Jun 2010 17:50:56 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751497Ab0FOPuu convert rfc822-to-quoted-printable (ORCPT ); Tue, 15 Jun 2010 11:50:50 -0400 Received: from mx1.imag.fr ([129.88.30.5]:34407 "EHLO shiva.imag.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751201Ab0FOPut (ORCPT ); Tue, 15 Jun 2010 11:50:49 -0400 Received: from ensikerberos.imag.fr (ensimag.imag.fr [195.221.228.12]) by shiva.imag.fr (8.13.8/8.13.8) with ESMTP id o5FFgiNC012750 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 15 Jun 2010 17:42:44 +0200 Received: from ensibm.imag.fr (ensibm.imag.fr [195.221.228.8]) by ensikerberos.imag.fr (8.13.8/8.13.8/ImagV2.1.r_ens) with ESMTP id o5FFoicG023040; Tue, 15 Jun 2010 17:50:44 +0200 Received: from ensibm.imag.fr (localhost [127.0.0.1]) by ensibm.imag.fr (8.13.8/8.13.8/ImagV2.1.sb_ens.pm) with ESMTP id o5FFoiKH005641; Tue, 15 Jun 2010 17:50:44 +0200 Received: (from poulainc@localhost) by ensibm.imag.fr (8.13.8/8.13.8/Submit) id o5FFoiJT005640; Tue, 15 Jun 2010 17:50:44 +0200 X-Mailer: git-send-email 1.6.6.7.ga5fe3 In-Reply-To: <1276102929-31712-1-git-send-email-clement.poulain@ensimag.imag.fr> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.0.1 (shiva.imag.fr [129.88.30.5]); Tue, 15 Jun 2010 17:42:44 +0200 (CEST) X-IMAG-MailScanner-Information: Please contact MI2S MIM for more information X-MailScanner-ID: o5FFgiNC012750 X-IMAG-MailScanner: Found to be clean X-IMAG-MailScanner-SpamCheck: X-IMAG-MailScanner-From: clement.poulain@ensimag.imag.fr MailScanner-NULL-Check: 1277221367.46@5bP2y+4Hsh5VLBwv4i2Q5g Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: 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 ad= dition to git_default_config. Therefore git_cat_file_config() is introduced Signed-off-by: Cl=C3=A9ment Poulain Signed-off-by: Diane Gasselin Signed-off-by: Axel Bonnet --- This is a little fix in response of: http://mid.gmane.org/7vfx0p9wlm.fsf@alter.siamese.dyndns.org It is based on the modifications submitted by Axel. It also corrects the style issue in the switch. builtin.h | 2 ++ builtin/blame.c | 8 ++++---- builtin/cat-file.c | 36 +++++++++++++++++++++++++++++++++--- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/builtin.h b/builtin.h index 5c887ef..5a1dba0 100644 --- a/builtin.h +++ b/builtin.h @@ -36,6 +36,8 @@ void finish_copy_notes_for_rewrite(struct notes_rewri= te_cfg *c); =20 extern int check_pager_config(const char *cmd); =20 +extern int textconv_object(const char *path, const unsigned char *sha1= , char **buf, unsigned long *buf_size); + extern int cmd_add(int argc, const char **argv, const char *prefix); extern int cmd_annotate(int argc, const char **argv, const char *prefi= x); extern int cmd_apply(int argc, const char **argv, const char *prefix); diff --git a/builtin/blame.c b/builtin/blame.c index 62d040c..d477bbe 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -91,10 +91,10 @@ struct origin { * if the textconv driver exists. * Return 1 if the conversion succeeds, 0 otherwise. */ -static int textconv_object(const char *path, - const unsigned char *sha1, - char **buf, - unsigned long *buf_size) +int textconv_object(const char *path, + const unsigned char *sha1, + char **buf, + unsigned long *buf_size) { struct diff_filespec *df; struct userdiff_driver *textconv; diff --git a/builtin/cat-file.c b/builtin/cat-file.c index a933eaa..f31684d 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -9,6 +9,8 @@ #include "tree.h" #include "builtin.h" #include "parse-options.h" +#include "diff.h" +#include "userdiff.h" =20 #define BATCH 1 #define BATCH_CHECK 2 @@ -86,8 +88,9 @@ static int cat_one_file(int opt, const char *exp_type= , const char *obj_name) enum object_type type; void *buf; unsigned long size; + struct object_context obj_context; =20 - if (get_sha1(obj_name, sha1)) + if (get_sha1_with_context(obj_name, sha1, &obj_context)) die("Not a valid object name %s", obj_name); =20 buf =3D NULL; @@ -132,6 +135,17 @@ static int cat_one_file(int opt, const char *exp_t= ype, const char *obj_name) =20 /* otherwise just spit out the data */ break; + + case 'c': + if (!obj_context.path[0]) + die("git cat-file --textconv %s: must be ", + obj_name); + + if(!textconv_object(obj_context.path, sha1, (char **) &buf, &size)) + die("git cat-file --textconv: unable to run textconv on %s", + obj_name); + break; + case 0: buf =3D read_object_with_reference(sha1, exp_type, &size, NULL); break; @@ -201,11 +215,25 @@ static int batch_objects(int print_contents) } =20 static const char * const cat_file_usage[] =3D { - "git cat-file (-t|-s|-e|-p|) ", + "git cat-file (-t|-s|-e|-p||--textconv) ", "git cat-file (--batch|--batch-check) < ", NULL }; =20 +static int git_cat_file_config(const char *var, const char *value, voi= d *cb) +{ + switch (userdiff_config(var, value)) { + case 0: + break; + case -1: + return -1; + default: + return 0; + } + + return git_default_config(var, value, cb); +} + int cmd_cat_file(int argc, const char **argv, const char *prefix) { int opt =3D 0, batch =3D 0; @@ -218,6 +246,8 @@ int cmd_cat_file(int argc, const char **argv, const= char *prefix) OPT_SET_INT('e', NULL, &opt, "exit with zero when there's no error", 'e'), OPT_SET_INT('p', NULL, &opt, "pretty-print object's content", 'p'), + OPT_SET_INT(0, "textconv", &opt, + "for blob objects, run textconv on object's content", 'c'), OPT_SET_INT(0, "batch", &batch, "show info and content of objects fed from the standard input", BATCH), @@ -227,7 +257,7 @@ int cmd_cat_file(int argc, const char **argv, const= char *prefix) OPT_END() }; =20 - git_config(git_default_config, NULL); + git_config(git_cat_file_config, NULL); =20 if (argc !=3D 3 && argc !=3D 2) usage_with_options(cat_file_usage, options); --=20 1.7.1.258.g8ea745.dirty