[PATCH] git show <tree>: show mode and hash, and handle -r

Subsystems: the rest

DORMANTno replies

3 messages, 2 authors, 2016-06-15 · open the first message on its own page

[PATCH] git show <tree>: show mode and hash, and handle -r

From: Johannes Schindelin <hidden>
Date: 2016-06-15 22:45:32

Now, git show <tree> shows some more information, and with the -r option,
it recurses into subdirectories.

Requested by Scott Chacon.

Signed-off-by: Johannes Schindelin <redacted>
---

	The only quirk is the command line parsing for -r: we cannot use 
	DIFF_OPT_TST(&rev.diffopt, RECURSIVE), because that is switched 
	on not only by cmd_log_init(), but implicitly by 
	diff_setup_done(), because FORMAT_PATCH is selected by git-show.

 builtin-log.c |   16 +++++++++++++---
 1 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/builtin-log.c b/builtin-log.c
index 3796dda..b00d353 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -297,8 +297,12 @@ static int show_tree_object(const unsigned char *sha1,
 		const char *base, int baselen,
 		const char *pathname, unsigned mode, int stage, void *context)
 {
-	printf("%s%s\n", pathname, S_ISDIR(mode) ? "/" : "");
-	return 0;
+	int *recursive = context;
+	printf("%06o %s %.*s%s%s\n", mode,
+			find_unique_abbrev(sha1, DEFAULT_ABBREV),
+			baselen, base,
+			pathname, S_ISDIR(mode) ? "/" : "");
+	return *recursive ? READ_TREE_RECURSIVE : 0;
 }
 
 int cmd_show(int argc, const char **argv, const char *prefix)
@@ -306,6 +310,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
 	struct rev_info rev;
 	struct object_array_entry *objects;
 	int i, count, ret = 0;
+	int tree_recursive = 0;
 
 	git_config(git_log_config, NULL);
 
@@ -319,6 +324,11 @@ int cmd_show(int argc, const char **argv, const char *prefix)
 	rev.always_show_header = 1;
 	rev.ignore_merges = 0;
 	rev.no_walk = 1;
+	for (i = 1; i < argc && strcmp(argv[i], "--"); i++)
+		if (!strcmp(argv[i], "-r")) {
+			tree_recursive = 1;
+			break;
+		}
 	cmd_log_init(argc, argv, prefix, &rev);
 
 	count = rev.pending.nr;
@@ -348,7 +358,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
 					name,
 					diff_get_color_opt(&rev.diffopt, DIFF_RESET));
 			read_tree_recursive((struct tree *)o, "", 0, 0, NULL,
-					show_tree_object, NULL);
+					show_tree_object, &tree_recursive);
 			break;
 		case OBJ_COMMIT:
 			rev.pending.nr = rev.pending.alloc = 0;
-- 
1.6.0.2.763.g72663

Re: [PATCH] git show <tree>: show mode and hash, and handle -r

From: Johannes Sixt <hidden>
Date: 2016-06-15 22:45:32

Johannes Schindelin schrieb:
Now, git show <tree> shows some more information, and with the -r option,
it recurses into subdirectories.

Requested by Scott Chacon.

Signed-off-by: Johannes Schindelin <redacted>
---

	The only quirk is the command line parsing for -r: we cannot use 
	DIFF_OPT_TST(&rev.diffopt, RECURSIVE), because that is switched 
	on not only by cmd_log_init(), but implicitly by 
	diff_setup_done(), because FORMAT_PATCH is selected by git-show.
This comment should for sure go into the commit message.

-- Hannes

Re: [PATCH] git show <tree>: show mode and hash, and handle -r

From: Johannes Schindelin <hidden>
Date: 2016-06-15 22:45:32

Hi,

On Wed, 29 Oct 2008, Johannes Sixt wrote:
Johannes Schindelin schrieb:
quoted
Now, git show <tree> shows some more information, and with the -r option,
it recurses into subdirectories.

Requested by Scott Chacon.

Signed-off-by: Johannes Schindelin <redacted>
---

	The only quirk is the command line parsing for -r: we cannot use 
	DIFF_OPT_TST(&rev.diffopt, RECURSIVE), because that is switched 
	on not only by cmd_log_init(), but implicitly by 
	diff_setup_done(), because FORMAT_PATCH is selected by git-show.
This comment should for sure go into the commit message.
Fair enough.

Junio, you want me to resend?

Ciao,
Dscho
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help