git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Clément Poulain" <clement.poulain@ensimag.imag.fr>
To: git@vger.kernel.org
Cc: spearce@spearce.org, drizzd@aon.at, matthieu.moy@grenoble-inp.fr,
	"Clément Poulain" <clement.poulain@ensimag.imag.fr>,
	"Diane Gasselin" <diane.gasselin@ensimag.imag.fr>,
	"Axel Bonnet" <axel.bonnet@ensimag.imag.fr>
Subject: [RFC/PATCH 2/4] textconv: support for cat-file
Date: Sun,  6 Jun 2010 13:30:46 +0200	[thread overview]
Message-ID: <1275823848-7151-3-git-send-email-clement.poulain@ensimag.imag.fr> (raw)
In-Reply-To: <1275823848-7151-2-git-send-email-clement.poulain@ensimag.imag.fr>

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

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>
---
 builtin/blame.c    |    8 ++++----
 builtin/cat-file.c |   21 ++++++++++++++++++++-
 2 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/builtin/blame.c b/builtin/blame.c
index 4679fd9..869be1d 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,
-			   unsigned short mode,
-			   struct strbuf *buf)
+int textconv_object(const char *path,
+		    const unsigned char *sha1,
+		    unsigned short mode,
+		    struct strbuf *buf)
 {
 	struct diff_filespec *df;
 
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 124e0a9..fde5fb9 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -9,6 +9,7 @@
 #include "tree.h"
 #include "builtin.h"
 #include "parse-options.h"
+#include "diff.h"
 
 #define BATCH 1
 #define BATCH_CHECK 2
@@ -135,6 +136,21 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
 
 		/* otherwise just spit out the data */
 		break;
+
+	case 'c':
+		if (!object_context.path[0])
+			die("git cat-file --textconv %s: <object> must be <sha1:path>",
+			    obj_name);
+
+		if(textconv_object(object_context.path, sha1,
+				   object_context.mode, &sbuf))
+			buf = strbuf_detach(&sbuf, (size_t *) &size);
+		else
+			buf = read_object_with_reference(sha1, "blob", &size, NULL);
+
+		strbuf_release(&sbuf);
+		break;
+
 	case 0:
 		buf = read_object_with_reference(sha1, exp_type, &size, NULL);
 		break;
@@ -204,7 +220,7 @@ static int batch_objects(int print_contents)
 }
 
 static const char * const cat_file_usage[] = {
-	"git cat-file (-t|-s|-e|-p|<type>) <object>",
+	"git cat-file (-t|-s|-e|-p|<type>|--textconv) <object>",
 	"git cat-file (--batch|--batch-check) < <list_of_objects>",
 	NULL
 };
@@ -221,6 +237,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),
@@ -231,6 +249,7 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
 	};
 
 	git_config(git_default_config, NULL);
+	git_config(git_diff_basic_config, NULL);
 
 	if (argc != 3 && argc != 2)
 		usage_with_options(cat_file_usage, options);
-- 
1.6.6.7.ga5fe3

  reply	other threads:[~2010-06-06 11:32 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-06 11:30 [RFC/PATCH 0/4] git-gui blame: use textconv Clément Poulain
2010-06-06 11:30 ` [RFC/PATCH 1/4] sha1_name: creating context cache Clément Poulain
2010-06-06 11:30   ` Clément Poulain [this message]
2010-06-06 11:30     ` [RFC/PATCH 3/4] git-gui: use textconv filter for diff and blame Clément Poulain
2010-06-06 11:30       ` [RFC/PATCH 4/4] t/t8007: test textconv support for cat-file Clément Poulain
2010-06-06 15:56   ` [RFC/PATCH 1/4] sha1_name: creating context cache Matthieu Moy
2010-06-06 22:15     ` Jeff King
2010-06-07  8:34       ` Clément Poulain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1275823848-7151-3-git-send-email-clement.poulain@ensimag.imag.fr \
    --to=clement.poulain@ensimag.imag.fr \
    --cc=axel.bonnet@ensimag.imag.fr \
    --cc=diane.gasselin@ensimag.imag.fr \
    --cc=drizzd@aon.at \
    --cc=git@vger.kernel.org \
    --cc=matthieu.moy@grenoble-inp.fr \
    --cc=spearce@spearce.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).