git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hitoshi Mitake <h.mitake@gmail.com>
To: gitster@pobox.com
Cc: git@vger.kernel.org, Hitoshi Mitake <h.mitake@gmail.com>
Subject: [PATCH v0 2/2] git-less: git side support for git-less
Date: Fri, 23 Mar 2012 03:42:24 +0900	[thread overview]
Message-ID: <1332441744-5142-3-git-send-email-h.mitake@gmail.com> (raw)
In-Reply-To: <1332441744-5142-1-git-send-email-h.mitake@gmail.com>

This patch modifies three parts of git.
1. git-log ... insert ETX(0x03) between each commit for the detection the boarder
   of commits by git-less.
2. pager selection ... current git uses single pager program for every command.
   I designed git-less for git-log so it is not suitable for other commands like
   git-grep, etc.
3. new configuration parameter for specifying git-less as a pager of git-log

(I think these three changes are one logical unit.)

The most important commit is 2. As described above, current git supports only
one pager and this is not good for git-less because git-less only assumes
git-log. So I modified setup_pager() in pager.c to separate pager selection
mechanism and pager setup mechanism.

As described in 3, git-log specific pager can be specified with the new string
typed parameter "log.pager". git-less can be set as the pager like this config:
[log]
	pager = git-less

The description of this new parameter is also added in the help of git-log.

Signed-off-by: Hitoshi Mitake <h.mitake@gmail.com>
---
 Documentation/git-log.txt |    6 +++++-
 builtin/log.c             |   32 ++++++++++++++++++++++++++++++++
 cache.h                   |    1 +
 pager.c                   |    9 ++++++---
 4 files changed, 44 insertions(+), 4 deletions(-)

diff --git a/Documentation/git-log.txt b/Documentation/git-log.txt
index 249fc87..f2e07f4 100644
--- a/Documentation/git-log.txt
+++ b/Documentation/git-log.txt
@@ -177,7 +177,11 @@ notes.displayRef::
 	or 'GIT_NOTES_REF', to read notes from when showing commit
 	messages with the 'log' family of commands.  See
 	linkgit:git-notes[1].
-+
+
+log.pager::
+       Pager program for git-log. Currently this option only assumes
+       "git-less".
+
 May be an unabbreviated ref name or a glob and may be specified
 multiple times.  A warning will be issued for refs that do not exist,
 but a glob that does not match any refs is silently ignored.
diff --git a/builtin/log.c b/builtin/log.c
index 8a47012..2ef3ada 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -88,6 +88,22 @@ static void cmd_log_init_defaults(struct rev_info *rev)
 		rev->date_mode = parse_date_format(default_date_mode);
 }
 
+static int use_git_less;
+
+static int setup_log_pager(const char *myname)
+{
+	if (strcmp(myname, "log")) {
+		use_git_less = 0;
+		return 0;
+	}
+
+	if (!use_git_less)
+		return 0;
+
+	__setup_pager("git-less");
+	return 1;
+}
+
 static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
 			 struct rev_info *rev, struct setup_revision_opt *opt)
 {
@@ -149,6 +165,10 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
 		rev->show_decorations = 1;
 		load_ref_decorations(decoration_style);
 	}
+
+	if (setup_log_pager(argv[0]))
+		return;
+
 	setup_pager();
 }
 
@@ -314,6 +334,9 @@ static int cmd_log_walk(struct rev_info *rev)
 			saved_nrl = rev->diffopt.needed_rename_limit;
 		if (rev->diffopt.degraded_cc_to_c)
 			saved_dcctc = 1;
+
+		if (use_git_less)
+			printf("\003");
 	}
 	rev->diffopt.degraded_cc_to_c = saved_dcctc;
 	rev->diffopt.needed_rename_limit = saved_nrl;
@@ -349,6 +372,15 @@ static int git_log_config(const char *var, const char *value, void *cb)
 	}
 	if (!prefixcmp(var, "color.decorate."))
 		return parse_decorate_color_config(var, 15, value);
+	if (!strcmp(var, "log.pager")) {
+		if (!strcmp(value, "git-less")) {
+			use_git_less = 1;
+			return 0;
+		} else {
+			fprintf(stderr, "unknown pager for git-log: %s\n", value);
+			return -1;
+		}
+	}
 
 	return git_diff_ui_config(var, value, cb);
 }
diff --git a/cache.h b/cache.h
index e5e1aa4..e5e57ff 100644
--- a/cache.h
+++ b/cache.h
@@ -1185,6 +1185,7 @@ static inline ssize_t write_str_in_full(int fd, const char *str)
 
 /* pager.c */
 extern void setup_pager(void);
+extern void __setup_pager(const char *pager);
 extern const char *pager_program;
 extern int pager_in_use(void);
 extern int pager_use_color;
diff --git a/pager.c b/pager.c
index 05584de..45fe9ea 100644
--- a/pager.c
+++ b/pager.c
@@ -69,10 +69,8 @@ const char *git_pager(int stdout_is_tty)
 	return pager;
 }
 
-void setup_pager(void)
+void __setup_pager(const char *pager)
 {
-	const char *pager = git_pager(isatty(1));
-
 	if (!pager)
 		return;
 
@@ -110,6 +108,11 @@ void setup_pager(void)
 	atexit(wait_for_pager);
 }
 
+void setup_pager(void)
+{
+	__setup_pager(git_pager(isatty(1)));
+}
+
 int pager_in_use(void)
 {
 	const char *env;
-- 
1.7.10.rc1.33.g64ff3.dirty

  parent reply	other threads:[~2012-03-22 18:43 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-22 18:42 [PATCH v0 0/2] git-less: a specialized pager for git-log Hitoshi Mitake
2012-03-22 18:42 ` [PATCH v0 1/2] " Hitoshi Mitake
2012-03-22 18:42 ` Hitoshi Mitake [this message]
2012-03-22 19:00 ` [PATCH v0 0/2] " Junio C Hamano
2012-03-23 10:07   ` Andreas Ericsson
2012-03-23 17:18     ` Hitoshi Mitake
2012-03-23 20:44     ` Alex Plotnick
2012-03-30 14:23       ` Jeff Epler
2012-03-23 17:15   ` Hitoshi Mitake
2012-03-24  4:43 ` Nguyen Thai Ngoc Duy

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=1332441744-5142-3-git-send-email-h.mitake@gmail.com \
    --to=h.mitake@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /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).