git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH v3 0/4] git-gui blame: use textconv
@ 2010-06-09 17:02 Clément Poulain
  2010-06-09 17:02 ` [PATCH v3 1/4] sha1_name: add get_sha1_with_context() Clément Poulain
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Clément Poulain @ 2010-06-09 17:02 UTC (permalink / raw)
  To: git; +Cc: Clément Poulain

This patch adds support of textconv to git-gui blame.

It is based on our previous work which adds textconv support to blame:
http://mid.gmane.org/1275921713-3277-1-git-send-email-axel.bonnet@ensimag.imag.fr
It also uses a git-gui patch done by Clemens Buchacher which adds textconv
support to git-gui diff: http://mid.gmane.org/20100415193944.GA5848@localhost.

git-gui blame is based on cat-file to get the content of the file in different
revisions, so the patch adds textconv support to cat-file.
The first part of this patch adds get_sha1_with_context() in order to know 
the pathname of the concerned blob, as textconv needs it to work.

This third version corrects one bug and some compilation warnings

Clément Poulain (4):
  sha1_name: add get_sha1_with_context()
  textconv: support for cat_file
  git gui: use textconv filter for diff and blame
  t/t8007: test textconv support for cat-file

 builtin.h                    |    2 +
 builtin/blame.c              |    8 ++--
 builtin/cat-file.c           |   33 ++++++++++++++++++--
 cache.h                      |   11 ++++++
 git-gui/git-gui.sh           |   28 ++++++++++++++++-
 git-gui/lib/blame.tcl        |   21 +++++++++++-
 git-gui/lib/diff.tcl         |    5 ++-
 git-gui/lib/option.tcl       |    1 +
 sha1_name.c                  |   31 +++++++++++++++---
 t/t8007-cat-file-textconv.sh |   70 ++++++++++++++++++++++++++++++++++++++++++
 10 files changed, 194 insertions(+), 16 deletions(-)
 create mode 100755 t/t8007-cat-file-textconv.sh

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v3 1/4] sha1_name: add get_sha1_with_context()
  2010-06-09 17:02 [PATCH v3 0/4] git-gui blame: use textconv Clément Poulain
@ 2010-06-09 17:02 ` Clément Poulain
  2010-06-09 17:02   ` [PATCH v3 2/4] textconv: support for cat_file Clément Poulain
  2010-06-14 17:18 ` [PATCH v3 0/4] git-gui blame: use textconv Clément Poulain
  2010-06-15 15:50 ` [PATCH v3 2/4] textconv: support for cat_file Clément Poulain
  2 siblings, 1 reply; 9+ messages in thread
From: Clément Poulain @ 2010-06-09 17:02 UTC (permalink / raw)
  To: git; +Cc: Clément Poulain, Diane Gasselin, Axel Bonnet

Textconv is defined by the diff driver, which is associated with a pathname,
not a blob. This fonction permits to know the context for the sha1 you're
looking for, especially his pathname

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>
---
 cache.h     |   11 +++++++++++
 sha1_name.c |   31 ++++++++++++++++++++++++++-----
 2 files changed, 37 insertions(+), 5 deletions(-)

diff --git a/cache.h b/cache.h
index c966023..67030db 100644
--- a/cache.h
+++ b/cache.h
@@ -730,12 +730,23 @@ static inline unsigned int hexval(unsigned char c)
 #define MINIMUM_ABBREV 4
 #define DEFAULT_ABBREV 7
 
+struct object_context {
+	unsigned char tree[20];
+	char path[PATH_MAX];
+	unsigned mode;
+};
+
 extern int get_sha1(const char *str, unsigned char *sha1);
 extern int get_sha1_with_mode_1(const char *str, unsigned char *sha1, unsigned *mode, int gently, const char *prefix);
 static inline int get_sha1_with_mode(const char *str, unsigned char *sha1, unsigned *mode)
 {
 	return get_sha1_with_mode_1(str, sha1, mode, 1, NULL);
 }
+extern int get_sha1_with_context_1(const char *name, unsigned char *sha1, struct object_context *orc, int gently, const char *prefix);
+static inline int get_sha1_with_context(const char *str, unsigned char *sha1, struct object_context *orc)
+{
+	return get_sha1_with_context_1(str, sha1, orc, 1, NULL);
+}
 extern int get_sha1_hex(const char *hex, unsigned char *sha1);
 extern char *sha1_to_hex(const unsigned char *sha1);	/* static buffer result! */
 extern int read_ref(const char *filename, unsigned char *sha1);
diff --git a/sha1_name.c b/sha1_name.c
index bf92417..7fdb202 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -933,8 +933,8 @@ int interpret_branch_name(const char *name, struct strbuf *buf)
  */
 int get_sha1(const char *name, unsigned char *sha1)
 {
-	unsigned unused;
-	return get_sha1_with_mode(name, sha1, &unused);
+	struct object_context unused;
+	return get_sha1_with_context(name, sha1, &unused);
 }
 
 /* Must be called only when object_name:filename doesn't exist. */
@@ -1032,11 +1032,23 @@ static void diagnose_invalid_index_path(int stage,
 
 int get_sha1_with_mode_1(const char *name, unsigned char *sha1, unsigned *mode, int gently, const char *prefix)
 {
+	struct object_context oc;
+	int ret;
+	ret = get_sha1_with_context_1(name, sha1, &oc, gently, prefix);
+	*mode = oc.mode;
+	return ret;
+}
+
+int get_sha1_with_context_1(const char *name, unsigned char *sha1,
+			    struct object_context *oc,
+			    int gently, const char *prefix)
+{
 	int ret, bracket_depth;
 	int namelen = strlen(name);
 	const char *cp;
 
-	*mode = S_IFINVALID;
+	memset(oc, 0, sizeof(*oc));
+	oc->mode = S_IFINVALID;
 	ret = get_sha1_1(name, namelen, sha1);
 	if (!ret)
 		return ret;
@@ -1059,6 +1071,11 @@ int get_sha1_with_mode_1(const char *name, unsigned char *sha1, unsigned *mode,
 			cp = name + 3;
 		}
 		namelen = namelen - (cp - name);
+
+		strncpy(oc->path, cp,
+			sizeof(oc->path));
+		oc->path[sizeof(oc->path)-1] = '\0';
+
 		if (!active_cache)
 			read_cache();
 		pos = cache_name_pos(cp, namelen);
@@ -1071,7 +1088,6 @@ int get_sha1_with_mode_1(const char *name, unsigned char *sha1, unsigned *mode,
 				break;
 			if (ce_stage(ce) == stage) {
 				hashcpy(sha1, ce->sha1);
-				*mode = ce->ce_mode;
 				return 0;
 			}
 			pos++;
@@ -1098,12 +1114,17 @@ int get_sha1_with_mode_1(const char *name, unsigned char *sha1, unsigned *mode,
 		}
 		if (!get_sha1_1(name, cp-name, tree_sha1)) {
 			const char *filename = cp+1;
-			ret = get_tree_entry(tree_sha1, filename, sha1, mode);
+			ret = get_tree_entry(tree_sha1, filename, sha1, &oc->mode);
 			if (!gently) {
 				diagnose_invalid_sha1_path(prefix, filename,
 							   tree_sha1, object_name);
 				free(object_name);
 			}
+			hashcpy(oc->tree, tree_sha1);
+			strncpy(oc->path, filename,
+				sizeof(oc->path));
+			oc->path[sizeof(oc->path)-1] = '\0';
+
 			return ret;
 		} else {
 			if (!gently)
-- 
1.6.6.7.ga5fe3

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v3 2/4] textconv: support for cat_file
  2010-06-09 17:02 ` [PATCH v3 1/4] sha1_name: add get_sha1_with_context() Clément Poulain
@ 2010-06-09 17:02   ` Clément Poulain
  2010-06-09 17:02     ` [PATCH v3 3/4] git gui: use textconv filter for diff and blame Clément Poulain
  0 siblings, 1 reply; 9+ messages in thread
From: Clément Poulain @ 2010-06-09 17:02 UTC (permalink / raw)
  To: git; +Cc: Clément Poulain, Diane Gasselin, Axel Bonnet

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>
---
 builtin.h          |    2 ++
 builtin/blame.c    |    8 ++++----
 builtin/cat-file.c |   33 ++++++++++++++++++++++++++++++---
 3 files changed, 36 insertions(+), 7 deletions(-)

diff --git a/builtin.h b/builtin.h
index 5c887ef..7902d4d 100644
--- a/builtin.h
+++ b/builtin.h
@@ -36,6 +36,8 @@ void finish_copy_notes_for_rewrite(struct notes_rewrite_cfg *c);
 
 extern int check_pager_config(const char *cmd);
 
+extern int textconv_object(const char *path, const unsigned char *sha1, char **buf, size_t *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 *prefix);
 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,
-			   size_t *buf_size)
+int textconv_object(const char *path,
+		    const unsigned char *sha1,
+		    char **buf,
+		    size_t *buf_size)
 {
 	struct diff_filespec *df;
 	struct userdiff_driver *textconv;
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index a933eaa..fc7ec61 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"
 
 #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;
 
-	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);
 
 	buf = NULL;
@@ -132,6 +135,17 @@ 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 (!obj_context.path[0])
+			die("git cat-file --textconv %s: <object> must be <sha1:path>",
+			    obj_name);
+
+		if(!textconv_object(obj_context.path, sha1, (char **) &buf, (size_t *) &size))
+			die("git cat-file --textconv: unable to run textconv on %s",
+			    obj_name);
+		break;
+
 	case 0:
 		buf = read_object_with_reference(sha1, exp_type, &size, NULL);
 		break;
@@ -201,11 +215,22 @@ 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
 };
 
+static int git_cat_file_config(const char *var, const char *value, void *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 = 0, batch = 0;
@@ -218,6 +243,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 +254,7 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
 		OPT_END()
 	};
 
-	git_config(git_default_config, NULL);
+	git_config(git_cat_file_config, NULL);
 
 	if (argc != 3 && argc != 2)
 		usage_with_options(cat_file_usage, options);
-- 
1.6.6.7.ga5fe3

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v3 3/4] git gui: use textconv filter for diff and blame
  2010-06-09 17:02   ` [PATCH v3 2/4] textconv: support for cat_file Clément Poulain
@ 2010-06-09 17:02     ` Clément Poulain
  2010-06-09 17:02       ` [PATCH v3 4/4] t/t8007: test textconv support for cat-file Clément Poulain
  0 siblings, 1 reply; 9+ messages in thread
From: Clément Poulain @ 2010-06-09 17:02 UTC (permalink / raw)
  To: git; +Cc: Clément Poulain, Diane Gasselin, Axel Bonnet

Create a checkbox "Use Textconv For Diffs and Blame" in git-gui options.
If checked and if the driver for the concerned file exists, git-gui calls diff
and blame with --textconv option

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>
---
 git-gui/git-gui.sh     |   28 +++++++++++++++++++++++++++-
 git-gui/lib/blame.tcl  |   21 +++++++++++++++++++--
 git-gui/lib/diff.tcl   |    5 ++++-
 git-gui/lib/option.tcl |    1 +
 4 files changed, 51 insertions(+), 4 deletions(-)

diff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh
index 7d54511..59edf39 100755
--- a/git-gui/git-gui.sh
+++ b/git-gui/git-gui.sh
@@ -269,6 +269,17 @@ proc is_config_true {name} {
 	}
 }
 
+proc is_config_false {name} {
+	global repo_config
+	if {[catch {set v $repo_config($name)}]} {
+		return 0
+	} elseif {$v eq {false} || $v eq {0} || $v eq {no}} {
+		return 1
+	} else {
+		return 0
+	}
+}
+
 proc get_config {name} {
 	global repo_config
 	if {[catch {set v $repo_config($name)}]} {
@@ -782,6 +793,7 @@ set default_config(user.email) {}
 
 set default_config(gui.encoding) [encoding system]
 set default_config(gui.matchtrackingbranch) false
+set default_config(gui.textconv) true
 set default_config(gui.pruneduringfetch) false
 set default_config(gui.trustmtime) false
 set default_config(gui.fastcopyblame) false
@@ -3405,6 +3417,19 @@ lappend diff_actions [list $ctxmsm entryconf [$ctxmsm index last] -state]
 $ctxmsm add separator
 create_common_diff_popup $ctxmsm
 
+proc has_textconv {path} {
+	if {[is_config_false gui.textconv]} {
+		return 0
+	}
+	set filter [gitattr $path diff set]
+	set textconv [get_config [join [list diff $filter textconv] .]]
+	if {$filter ne {set} && $textconv ne {}} {
+		return 1
+	} else {
+		return 0
+	}
+}
+
 proc popup_diff_menu {ctxm ctxmmg ctxmsm x y X Y} {
 	global current_diff_path file_states
 	set ::cursorX $x
@@ -3440,7 +3465,8 @@ proc popup_diff_menu {ctxm ctxmmg ctxmsm x y X Y} {
 			|| {__} eq $state
 			|| {_O} eq $state
 			|| {_T} eq $state
-			|| {T_} eq $state} {
+			|| {T_} eq $state
+			|| [has_textconv $current_diff_path]} {
 			set s disabled
 		} else {
 			set s normal
diff --git a/git-gui/lib/blame.tcl b/git-gui/lib/blame.tcl
index 786b50b..b0f2f23 100644
--- a/git-gui/lib/blame.tcl
+++ b/git-gui/lib/blame.tcl
@@ -449,11 +449,28 @@ method _load {jump} {
 
 	$status show [mc "Reading %s..." "$commit:[escape_path $path]"]
 	$w_path conf -text [escape_path $path]
+
+	set do_textconv 0
+	if {![is_config_false gui.textconv]} {
+		set filter [gitattr $path diff set]
+		set textconv [get_config [join [list diff $filter textconv] .]]
+		if {$filter ne {set} && $textconv ne {}} {
+			set do_textconv 1
+		}
+	}
 	if {$commit eq {}} {
-		set fd [open $path r]
+		if {$do_textconv ne 0} {
+			set fd [open "|$textconv $path" r]
+		} else {
+			set fd [open $path r]
+		}
 		fconfigure $fd -eofchar {}
 	} else {
-		set fd [git_read cat-file blob "$commit:$path"]
+		if {$do_textconv ne 0} {
+			set fd [git_read cat-file --textconv "$commit:$path"]
+		} else {
+			set fd [git_read cat-file blob "$commit:$path"]
+		}
 	}
 	fconfigure $fd \
 		-blocking 0 \
diff --git a/git-gui/lib/diff.tcl b/git-gui/lib/diff.tcl
index ec8c11e..c628750 100644
--- a/git-gui/lib/diff.tcl
+++ b/git-gui/lib/diff.tcl
@@ -55,7 +55,7 @@ proc handle_empty_diff {} {
 
 	set path $current_diff_path
 	set s $file_states($path)
-	if {[lindex $s 0] ne {_M}} return
+	if {[lindex $s 0] ne {_M} || [has_textconv $path]} return
 
 	# Prevent infinite rescan loops
 	incr diff_empty_count
@@ -280,6 +280,9 @@ proc start_show_diff {cont_info {add_opts {}}} {
 			lappend cmd diff-files
 		}
 	}
+	if {![is_config_false gui.textconv] && [git-version >= 1.6.1]} {
+		lappend cmd --textconv
+	}
 
 	if {[string match {160000 *} [lindex $s 2]]
 	 || [string match {160000 *} [lindex $s 3]]} {
diff --git a/git-gui/lib/option.tcl b/git-gui/lib/option.tcl
index d4c5e45..3807c8d 100644
--- a/git-gui/lib/option.tcl
+++ b/git-gui/lib/option.tcl
@@ -148,6 +148,7 @@ proc do_options {} {
 		{b gui.trustmtime  {mc "Trust File Modification Timestamps"}}
 		{b gui.pruneduringfetch {mc "Prune Tracking Branches During Fetch"}}
 		{b gui.matchtrackingbranch {mc "Match Tracking Branches"}}
+		{b gui.textconv {mc "Use Textconv For Diffs and Blames"}}
 		{b gui.fastcopyblame {mc "Blame Copy Only On Changed Files"}}
 		{i-20..200 gui.copyblamethreshold {mc "Minimum Letters To Blame Copy On"}}
 		{i-0..300 gui.blamehistoryctx {mc "Blame History Context Radius (days)"}}
-- 
1.6.6.7.ga5fe3

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v3 4/4] t/t8007: test textconv support for cat-file
  2010-06-09 17:02     ` [PATCH v3 3/4] git gui: use textconv filter for diff and blame Clément Poulain
@ 2010-06-09 17:02       ` Clément Poulain
  0 siblings, 0 replies; 9+ messages in thread
From: Clément Poulain @ 2010-06-09 17:02 UTC (permalink / raw)
  To: git; +Cc: Clément Poulain, Diane Gasselin, Axel Bonnet

Test the correct functionning of textconv with cat-file <sha1:blob>
and cat-file HEAD^ <file>. Test the case when no driver is specified

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>
---
 t/t8007-cat-file-textconv.sh |   70 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 70 insertions(+), 0 deletions(-)
 create mode 100755 t/t8007-cat-file-textconv.sh

diff --git a/t/t8007-cat-file-textconv.sh b/t/t8007-cat-file-textconv.sh
new file mode 100755
index 0000000..38ac05e
--- /dev/null
+++ b/t/t8007-cat-file-textconv.sh
@@ -0,0 +1,70 @@
+#!/bin/sh
+
+test_description='git cat-file textconv support'
+. ./test-lib.sh
+
+cat >helper <<'EOF'
+#!/bin/sh
+sed 's/^/converted: /' "$@"
+EOF
+chmod +x helper
+
+test_expect_success 'setup ' '
+	echo test >one.bin &&
+	git add . &&
+	GIT_AUTHOR_NAME=Number1 git commit -a -m First --date="2010-01-01 18:00:00" &&
+	echo test version 2 >one.bin &&
+	GIT_AUTHOR_NAME=Number2 git commit -a -m Second --date="2010-01-01 20:00:00"
+'
+
+cat >expected <<EOF
+fatal: git cat-file --textconv: unable to run textconv on :one.bin
+EOF
+
+test_expect_success 'no filter specified' '
+	git cat-file --textconv :one.bin 2>result
+	test_cmp expected result
+'
+
+test_expect_success 'setup textconv filters' '
+	echo "*.bin diff=test" >.gitattributes &&
+	git config diff.test.textconv ./helper &&
+	git config diff.test.cachetextconv false
+'
+
+cat >expected <<EOF
+test version 2
+EOF
+
+test_expect_success 'cat-file without --textconv' '
+	git cat-file blob :one.bin >result &&
+	test_cmp expected result
+'
+
+cat >expected <<EOF
+test
+EOF
+
+test_expect_success 'cat-file without --textconv on previous commit' '
+	git cat-file -p HEAD^:one.bin >result &&
+	test_cmp expected result
+'
+
+cat >expected <<EOF
+converted: test version 2
+EOF
+
+test_expect_success 'cat-file --textconv on last commit' '
+	git cat-file --textconv :one.bin >result &&
+	test_cmp expected result
+'
+
+cat >expected <<EOF
+converted: test
+EOF
+
+test_expect_success 'cat-file --textconv on previous commit' '
+	git cat-file --textconv HEAD^:one.bin >result &&
+	test_cmp expected result
+'
+test_done
-- 
1.6.6.7.ga5fe3

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v3 0/4] git-gui blame: use textconv
  2010-06-09 17:02 [PATCH v3 0/4] git-gui blame: use textconv Clément Poulain
  2010-06-09 17:02 ` [PATCH v3 1/4] sha1_name: add get_sha1_with_context() Clément Poulain
@ 2010-06-14 17:18 ` Clément Poulain
  2010-06-14 17:29   ` Junio C Hamano
  2010-06-15 15:50 ` [PATCH v3 2/4] textconv: support for cat_file Clément Poulain
  2 siblings, 1 reply; 9+ messages in thread
From: Clément Poulain @ 2010-06-14 17:18 UTC (permalink / raw)
  To: gitster, spearce; +Cc: git

Hi,

I've seen this series is now on pu. I have 2 questions concerning the
fourth patch (ca23df5e, Clément Poulain, 2010-06-09 19:02:08) tagged with
[DONTMERGE] and annotated with [jc: shouldn't merge this to 'next' or
higher but take it via Shawn].

First, is the tag only for this patch, or for the whole series? 
Then, do we have something more to do?

Regards

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v3 0/4] git-gui blame: use textconv
  2010-06-14 17:18 ` [PATCH v3 0/4] git-gui blame: use textconv Clément Poulain
@ 2010-06-14 17:29   ` Junio C Hamano
  2010-06-16  7:50     ` Matthieu Moy
  0 siblings, 1 reply; 9+ messages in thread
From: Junio C Hamano @ 2010-06-14 17:29 UTC (permalink / raw)
  To: clement.poulain; +Cc: spearce, git

Clément Poulain <clement.poulain@ensimag.imag.fr> writes:

> I've seen this series is now on pu. I have 2 questions concerning the
> fourth patch (ca23df5e, Clément Poulain, 2010-06-09 19:02:08) tagged with
> [DONTMERGE] and annotated with [jc: shouldn't merge this to 'next' or
> higher but take it via Shawn].
>
> First, is the tag only for this patch, or for the whole series? 
> Then, do we have something more to do?

That was primarily a note to myself attached to that one commit.

Because I pull all the changes to git-gui from Shawn (and gitk from
Paulus) using subtree merge, I do not want to apply patches that touch
git-gui/ (or gitk-git/) part myself.  Sometime later when the earlier
patches in your series prove to be 'next'-worthy, I'll have to nag Shawn
to accept it to his tree (we might need to devise a transition strategy so
that people who want to use slightly newer git-gui with older git won't
get hurt).

Thanks for asking.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v3 2/4] textconv: support for cat_file
  2010-06-09 17:02 [PATCH v3 0/4] git-gui blame: use textconv Clément Poulain
  2010-06-09 17:02 ` [PATCH v3 1/4] sha1_name: add get_sha1_with_context() Clément Poulain
  2010-06-14 17:18 ` [PATCH v3 0/4] git-gui blame: use textconv Clément Poulain
@ 2010-06-15 15:50 ` Clément Poulain
  2 siblings, 0 replies; 9+ messages in thread
From: Clément Poulain @ 2010-06-15 15:50 UTC (permalink / raw)
  To: git; +Cc: Clément Poulain, Diane Gasselin, Axel Bonnet

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>
---

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_rewrite_cfg *c);
 
 extern int check_pager_config(const char *cmd);
 
+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 *prefix);
 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"
 
 #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;
 
-	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);
 
 	buf = NULL;
@@ -132,6 +135,17 @@ 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 (!obj_context.path[0])
+			die("git cat-file --textconv %s: <object> must be <sha1:path>",
+			    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 = read_object_with_reference(sha1, exp_type, &size, NULL);
 		break;
@@ -201,11 +215,25 @@ 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
 };
 
+static int git_cat_file_config(const char *var, const char *value, void *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 = 0, batch = 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()
 	};
 
-	git_config(git_default_config, NULL);
+	git_config(git_cat_file_config, NULL);
 
 	if (argc != 3 && argc != 2)
 		usage_with_options(cat_file_usage, options);
-- 
1.7.1.258.g8ea745.dirty

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v3 0/4] git-gui blame: use textconv
  2010-06-14 17:29   ` Junio C Hamano
@ 2010-06-16  7:50     ` Matthieu Moy
  0 siblings, 0 replies; 9+ messages in thread
From: Matthieu Moy @ 2010-06-16  7:50 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: clement.poulain, spearce, git

Junio C Hamano <gitster@pobox.com> writes:

> (we might need to devise a transition strategy so
> that people who want to use slightly newer git-gui with older git won't
> get hurt).

I don't think these users would really get hurt: they could still use
git gui blame on text files, and they would anyway not have obtained
anything sensible from "git gui blame binary-file". In the very
unlikely case where a user has a textconv filter activated for a file
which can be viewed as text too, there's a checkbox to disable
textconv provided by Clément's patch.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2010-06-16  7:51 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-09 17:02 [PATCH v3 0/4] git-gui blame: use textconv Clément Poulain
2010-06-09 17:02 ` [PATCH v3 1/4] sha1_name: add get_sha1_with_context() Clément Poulain
2010-06-09 17:02   ` [PATCH v3 2/4] textconv: support for cat_file Clément Poulain
2010-06-09 17:02     ` [PATCH v3 3/4] git gui: use textconv filter for diff and blame Clément Poulain
2010-06-09 17:02       ` [PATCH v3 4/4] t/t8007: test textconv support for cat-file Clément Poulain
2010-06-14 17:18 ` [PATCH v3 0/4] git-gui blame: use textconv Clément Poulain
2010-06-14 17:29   ` Junio C Hamano
2010-06-16  7:50     ` Matthieu Moy
2010-06-15 15:50 ` [PATCH v3 2/4] textconv: support for cat_file Clément Poulain

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).