git-less: a specialized pager for git-log
Subsystems (2)
cover git-less: a specialized pager for git-log
Hi Junio C Hamano and git people,
I'd like to post this patch series for adding a pager program for git-log, named "git-less". It seems that less is today's the most popular pager for git-log. But I don't think that less is confortable pager when its input is come from git-log. Because less treats its input as a simple text. So less cannot recognize the end of each commit.
If the pager can recognize the end of each commit, more confortable viewing of git-log's output will be possible.
So I'd like to introduce git-less, and the modification of git itself to support this pager.
The main difference between less and git-less is recognition of each commit. With this feature, git-log specific functionalities can be implemented. e.g.
* move with commit unit. Under git-less, hitting 'h' key means move to previous (parent) commit, 'l' means move to next (child) commit.
* commit local regex search. regular expression search limiting its range within commit, not entire log. I assigned '\' for commit local forward regex search and '?' for commit local regex search.
And other features like yanking commit ID might be implemented simply (not implemented yet).
For implementing this feature, I had to make modification of git-log
* Changed output for inserting ETX (0x03) between each commit.
* Added new configuration parameter for git-log only pager: "log.pager". git-less only focuses on git-log, so it is not suitable for git-grep, etc.
This is the reason why I'm posting this patch. git-less is not git-independent program. The source code of git-less have to be integrated with the git tree. I understand this is not so good manner. And the source code is still dirty and may be buggy, but I believe that this new pager is useful. I'd like to hear your feedbacks.
Thanks,
Hitoshi Mitake (2):
git-less: a specialized pager for git-log
git-less: git side support for git-less
.gitignore | 1 + Documentation/git-log.txt | 6 +- Makefile | 5 + builtin/log.c | 32 ++ cache.h | 1 + less.c | 899 +++++++++++++++++++++++++++++++++++++++++++++ pager.c | 9 +- 7 files changed, 949 insertions(+), 4 deletions(-) create mode 100644 less.c
Signature · 1 line
1.7.10.rc1.33.g64ff3.dirty
PATCH 1/2 git-less: a specialized pager for git-log
This patch adds a specialized pager for git-log: "git-less". Basically git-less works like ordinal less, but it uses some new keys. The important feature of this pager is git's commit oriented log viewing.
This is the key mapping of commit oriented operations:
h ... show previous commit
l ... show next commit
g ... goto top of viewing commit
G ... goto bottom of viewing commit
H ... show root of the commit tree
L ... show HEAD of the commit tree
\ ... regex forward search only in viewing commit ! ... regex backward search only in viewing commit
As this mapping shows, commit oriented move and search are implemented. Especially I like commit local regex searches.
This patch adds the new source file less.c, the implementation of git-less. And modifies .gitignore and Makefile for ignoring the binary and buliding.
--- .gitignore | 1 + Makefile | 5 + less.c | 899 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 905 insertions(+) create mode 100644 less.c
.gitignore +1 -0
@@ -163,6 +163,7 @@ /git-web--browse /git-whatchanged /git-write-tree +/git-less /git-core-*/?* /gitk-git/gitk-wish /gitweb/GITWEB-BUILD-OPTIONS
Makefile +5 -0
@@ -463,6 +463,7 @@ PROGRAM_OBJS += upload-pack.o PROGRAM_OBJS += http-backend.o PROGRAM_OBJS += sh-i18n--envsubst.o PROGRAM_OBJS += credential-store.o +PROGRAM_OBJS += less.o # Binary suffix, set to .exe for Windows builds X =
@@ -2239,6 +2240,10 @@ git-http-push$X: revision.o http.o http-push.o GIT-LDFLAGS $(GITLIBS) $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \ $(LIBS) $(CURL_LIBCURL) $(EXPAT_LIBEXPAT) +gitless$X: gitless.o + $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \ + $(LIBS) $(OPENSSL_LINK) $(OPENSSL_LIBSSL) $(LIB_4_CRYPTO) + $(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY) $(QUIET_LNCP)$(RM) $@ && \ ln $< $@ 2>/dev/null || \
less.c new file +899 -0
899 lines not on this page · raw message
Signature · 1 line
1.7.10.rc1.33.g64ff3.dirty
PATCH 2/2 git-less: git side support for git-less
In reply to Hitoshi MitakeThis 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.
--- Documentation/git-log.txt | 6 +++++- builtin/log.c | 32 ++++++++++++++++++++++++++++++++ cache.h | 1 + pager.c | 9 ++++++--- 4 files changed, 44 insertions(+), 4 deletions(-)
Documentation/git-log.txt +5 -1
@@ -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.
builtin/log.c +32 -0
@@ -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); }
cache.h +1 -0
@@ -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;
pager.c +6 -3
@@ -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;
Signature · 1 line
1.7.10.rc1.33.g64ff3.dirty
Quoted 2 lines · Hitoshi Mitake
If the pager can recognize the end of each commit, more confortable viewing of git-log's output will be possible.
I think people just use "/^commit .*<RET>" once and then nagivate with "n" (and to change direction, "?<RET>") for this.
Quoted 1 line
For implementing this feature, I had to make modification of git-log
I do not think the change to "log" is necessary nor worth it. If the pager is so specialized to be tied to git, it should learn to recognize the output from "git", namely, "git log" and "git log -p" would never have a line that begins with "^commit " that is not the beginning of one record for a commit.
If you are not comfortable using "less", perhaps a program like "tig" that is very specialized for working with git might help you better.
Quoted 8 lines · Junio C Hamano
Quoted 2 lines · Hitoshi Mitake
If the pager can recognize the end of each commit, more confortable viewing of git-log's output will be possible.
I think people just use "/^commit .*<RET>" once and then nagivate with "n" (and to change direction, "?<RET>") for this.
Or capital N.
It's mostly useful when one wants to view the patch as well as the message, so an alias like
logp = !PAGER='less -p ^commit' git log -p
should work well, and also make LISP nerds giggle.
Signature · 7 lines
Andreas Ericsson [email protected] OP5 AB www.op5.se Tel: +46 8-230225 Fax: +46 8-230231 Considering the successes of the wars on alcohol, poverty, drugs and terror, I think we should give some serious thought to declaring war on peace.
I have on occasion also wished to view log messages (especially with patches) one at a time. And although I agree that a dedicated pager is overkill, perhaps a small script wouldn't be.
The attached script will eventually run afoul of argument length limits, but seems to work well otherwise. If you're using less(1), you can step through the files using :n, :p, and :x.
Cheers,
-- Alex
#!/bin/sh
# Use csplit(1) to split a git log into one commit per file, then run the
# pager on the split files.
. $(git --exec-path)/git-sh-setup
SPLIT_DIR="$GIT_DIR/split-$$"
CSPLIT="csplit -s -k"
if csplit --help 2>/dev/null | sane_grep -- "-z" >/dev/null; then
CSPLIT="$CSPLIT -z"
fi
_x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
_x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
_infty=1000000
mkdir "$SPLIT_DIR" && cd "$SPLIT_DIR" || exit 1
trap 'rm -rf "$SPLIT_DIR"' 0 1 2 3 15
git log "$@" | $CSPLIT - "/^commit $_x40/" "{$_infty}" 2>/dev/null git_pager "$SPLIT_DIR"/xx*
Hmm, let's say you'd like to view the last 10 commits in a specialized program that divides them up and provides good search capabilities:
mutt -f <(git format-patch --stdout -10)
one shortcoming is that the whole git format-patch process must finish before mutt will begin showing the mailbox .. otherwise, this seems pretty awesome.
Jeff
Quoted 10 lines · Andreas Ericsson
Quoted 8 lines · Junio C Hamano
Quoted 2 lines · Hitoshi Mitake
If the pager can recognize the end of each commit, more confortable viewing of git-log's output will be possible.
I think people just use "/^commit .*<RET>" once and then nagivate with "n" (and to change direction, "?<RET>") for this.
Quoted 6 lines
Or capital N.
It's mostly useful when one wants to view the patch as well as the message, so an alias like
logp = !PAGER='less -p ^commit' git log -p
Yes, moving is not so large problem. But less cannot search regex with specified limit. Sometime I want to search string e.g. "something" only in the commit I'm focusing on.
Quoted 3 lines
should work well, and also make LISP nerds giggle.
p? :)
Quoted 8 lines
--
Andreas Ericsson [email protected] OP5 AB www.op5.se
Tel: +46 8-230225 Fax: +46 8-230231Considering the successes of the wars on alcohol, poverty, drugs and terror, I think we should give some serious thought to declaring war on peace.
Signature · 2 lines
Hitoshi Mitake [email protected]
Quoted 7 lines · Junio C Hamano
Quoted 2 lines · Hitoshi Mitake
If the pager can recognize the end of each commit, more confortable viewing of git-log's output will be possible.
I think people just use "/^commit .*<RET>" once and then nagivate with "n" (and to change direction, "?<RET>") for this.
Yes, but less cannot search regex with specified range of text (in this case, from the beginning to the end of the commit).
Quoted 8 lines
Quoted 2 lines
For implementing this feature, I had to make modification of git-log
I do not think the change to "log" is necessary nor worth it. If the pager is so specialized to be tied to git, it should learn to recognize the output from "git", namely, "git log" and "git log -p" would never have a line that begins with "^commit " that is not the beginning of one record for a commit.
This rule is useful for detection of each commit from pager. I didn't have to modify git-log... With this rule, the pager can be independent from the tree of git, thanks!
Quoted 4 lines
If you are not comfortable using "less", perhaps a program like "tig" that is very specialized for working with git might help you better.
Thanks for your information. I didn't know about tig. I'd like to test it or modify my pager for more comfortable git-log viewing.
Thanks for your feedback,
Signature · 2 lines
Hitoshi Mitake [email protected]
Quoted 7 lines · Hitoshi Mitake
Hi Junio C Hamano and git people,
I'd like to post this patch series for adding a pager program for git-log, named "git-less". It seems that less is today's the most popular pager for git-log. But I don't think that less is confortable pager when its input is come from git-log. Because less treats its input as a simple text. So less cannot recognize the end of each commit.
How does it compare to tig?
Signature · 1 line
Duy