Add new git-graph command
Subsystems (2)
PATCH 1/1 Add new git-graph command
This is a first pass at a command to print a text-based graph of the commit history. It is similar to the history graph shown by gitk, but doesn't require a windowing system.
---
I added this since I really like gitk, but don't always have easy access to an X display on some of the systems I use. I tried using tig, but I found its graph output very hard to read. The graph produced by git-graph is less compact, but much more readable.
Ultimately, it would probably be better to integrate this functionality into git-log, instead of having it as a standalone command. For example, a new --graph option could be added to cause the graph to be displayed alongside the existing git log output. However, this would require tighter integration between the graphing code and the log_tree.c and pretty.c code, which I'm not all that familiar with.
.gitignore | 1 + Documentation/git-graph.txt | 56 ++++ Documentation/pretty-formats.txt | 4 + Documentation/rev-list-options.txt | 15 + Makefile | 1 + builtin-graph.c | 553 ++++++++++++++++++++++++++++++++++++ builtin.h | 1 + git.c | 1 + 8 files changed, 632 insertions(+), 0 deletions(-) create mode 100644 Documentation/git-graph.txt create mode 100644 builtin-graph.c
.gitignore +1 -0
@@ -49,6 +49,7 @@ git-fsck git-fsck-objects git-gc git-get-tar-commit-id +git-graph git-grep git-hash-object git-http-fetch
Documentation/git-graph.txt new file +56 -0
56 lines not on this page · raw message
Documentation/pretty-formats.txt +4 -0
@@ -1,6 +1,7 @@ PRETTY FORMATS -------------- +ifndef::git-graph[] If the commit is a merge, and if the pretty-format is not 'oneline', 'email' or 'raw', an additional line is inserted before the 'Author:' line. This line begins with
@@ -10,6 +11,7 @@ necessarily be the list of the *direct* parent commits if you have limited your view of history: for example, if you are only interested in changes related to a certain directory or file. +endif::git-graph[] Here are some additional details for each format:
@@ -19,6 +21,7 @@ Here are some additional details for each format: + This is designed to be as compact as possible. +ifndef::git-graph[] * 'short' commit <sha1>
@@ -75,6 +78,7 @@ displayed in full, regardless of whether --abbrev or --no-abbrev are used, and 'parents' information show the true parent commits, without taking grafts nor history simplification into account. +endif::git-graph[] * 'format:' +
Documentation/rev-list-options.txt +15 -0
@@ -9,6 +9,7 @@ endif::git-rev-list[] include::pretty-options.txt[] +ifndef::git-graph[] --relative-date:: Synonym for `--date=relative`.
@@ -37,11 +38,13 @@ format, often found in E-mail messages. Print the contents of the commit in raw-format; each record is separated with a NUL character. +endif::git-graph[] --parents:: Print the parents of the commit. +ifndef::git-graph[] --timestamp:: Print the raw commit timestamp.
@@ -104,6 +107,7 @@ options may be given. See linkgit:git-diff-files[1] for more options. -t:: Show the tree objects in the diff output. This implies '-r'. +endif::git-graph[] Commit Limiting ~~~~~~~~~~~~~~~
@@ -136,6 +140,7 @@ ifdef::git-rev-list[] Limit the commits output to specified time range. endif::git-rev-list[] +ifndef::git-graph[] --author='pattern', --committer='pattern':: Limit the commits output to ones with author/committer
@@ -184,6 +189,7 @@ endif::git-rev-list[] adjusting to updated upstream from time to time, and this option allows you to ignore the individual commits brought in to your history by such a merge. +endif::git-graph[] --not::
@@ -195,6 +201,7 @@ endif::git-rev-list[] Pretend as if all the refs in `$GIT_DIR/refs/` are listed on the command line as '<commit>'. +ifndef::git-graph[] --stdin:: In addition to the '<commit>' listed on the command
@@ -260,6 +267,7 @@ merges that do not touch the given paths. Use the '--sparse' flag to makes the command output all eligible commits (still subject to count and age limitation), but apply merge simplification nevertheless. +endif::git-graph[] ifdef::git-rev-list[] --bisect::
@@ -316,7 +324,12 @@ endif::git-rev-list[] Commit Ordering ~~~~~~~~~~~~~~~ +ifndef::git-graph[] By default, the commits are shown in reverse chronological order. +endif::git-graph[] +ifdef::git-graph[] +By default, the commits are shown in topological order. +endif::git-graph[] --topo-order::
@@ -329,6 +342,7 @@ By default, the commits are shown in reverse chronological order. parent comes before all of its children, but otherwise things are still ordered in the commit timestamp order. +ifndef::git-graph[] --reverse:: Output the commits in reverse order.
@@ -366,3 +380,4 @@ These options are mostly targeted for packing of git repositories. --do-walk:: Overrides a previous --no-walk. +endif::git-graph[]
Makefile +1 -0
@@ -495,6 +495,7 @@ BUILTIN_OBJS += builtin-fmt-merge-msg.o BUILTIN_OBJS += builtin-for-each-ref.o BUILTIN_OBJS += builtin-fsck.o BUILTIN_OBJS += builtin-gc.o +BUILTIN_OBJS += builtin-graph.o BUILTIN_OBJS += builtin-grep.o BUILTIN_OBJS += builtin-init-db.o BUILTIN_OBJS += builtin-log.o
builtin-graph.c new file +553 -0
553 lines not on this page · raw message
builtin.h +1 -0
@@ -43,6 +43,7 @@ extern int cmd_format_patch(int argc, const char **argv, const char *prefix);extern int cmd_fsck (int argc,const char **argv,const char *prefix);extern int cmd_gc (int argc,const char **argv,const char *prefix);extern int cmd_get_tar_commit_id (int argc,const char **argv,const char *prefix); +extern int cmd_graph (int argc,const char **argv,const char *prefix);extern int cmd_grep (int argc,const char **argv,const char *prefix);extern int cmd_help (int argc,const char **argv,const char *prefix);extern int cmd_http_fetch (int argc,const char **argv,const char *prefix);
git.c +1 -0
@@ -306,6 +306,7 @@ static void handle_internal_command(int argc, const char **argv) { "fsck-objects", cmd_fsck, RUN_SETUP }, { "gc", cmd_gc, RUN_SETUP }, { "get-tar-commit-id", cmd_get_tar_commit_id }, + { "graph", cmd_graph, RUN_SETUP | USE_PAGER }, { "grep", cmd_grep, RUN_SETUP | USE_PAGER }, { "help", cmd_help }, #ifndef NO_CURL
Signature · 1 line
1.5.5.rc2.1.ge6b5a.dirty
Adam Simpkins kirjoitti:
Quoted 5 lines
I added this since I really like gitk, but don't always have easy access to an X display on some of the systems I use. I tried using tig, but I found its graph output very hard to read. The graph produced by git-graph is less compact, but much more readable.
Quoted 7 lines
Ultimately, it would probably be better to integrate this functionality into git-log, instead of having it as a standalone command. For example, a new --graph option could be added to cause the graph to be displayed alongside the existing git log output. However, this would require tighter integration between the graphing code and the
log_tree.candpretty.ccode, which I'm not all that familiar with.
I just want to say that I really like your 'git graph'. I would like to see it integrated to 'git log', perhaps as 'git log --pretty=graph' or 'git log --graph'.
Quoted 10 lines · Teemu Likonen
Adam Simpkins kirjoitti:
Quoted 7 lines
Ultimately, it would probably be better to integrate this functionality into git-log, instead of having it as a standalone command. For example, a new --graph option could be added to cause the graph to be displayed alongside the existing git log output. However, this would require tighter integration between the graphing code and the
log_tree.candpretty.ccode, which I'm not all that familiar with.
Quoted 3 lines
I just want to say that I really like your 'git graph'. I would like to see it integrated to 'git log', perhaps as 'git log --pretty=graph' or 'git log --graph'.
Thanks!
I was thinking more about how to add it to 'git log', and it might not be all that difficult. Instead of providing the graphing functionality as a standalone command, it could be wrapped up in the following API:
struct graph; void graph_update(struct graph *graph, struct commit *commit); void graph_next_line(struct graph *graph, struct strbuf *sb); bool graph_is_commit_finished(struct graph *graph);
While walking through the commit list, graph_update() should be called once for each commit. After graph_update() has been called, graph_next_line() can then be called to format the next line of the graph into the strbuf. It should be called multiple times, until graph_is_commit_finished() returns true. Then graph_update() can be called with the next commit.
If graph_next_line() is called when graph_is_commit_finished() returns, it would simply format straight lines for each column. For example, if there were currently 3 columns, it would format "| | |". This allows graph_next_line() to be used to vertically pad the graph.
This API would allow the 'git log' code to format each line of the graph into a strbuf, and print it out in front of each line of normal log output. This way, it could work even with something like "git log --graph --pretty=full". The graph would be prefixed to the normal output, and padded vertically for as long as necessary.
I'm just not sure how difficult it will be to change the log-tree.c code to invoke graph_next_line() before each individual line of output. It certainly shouldn't be that difficult just to implement 'git log --pretty=graph', but it may be more complicated if we want to make the graphing be a boolean option that can be enabled with any --pretty format.
I might try coding it up next weekend.
Signature · 2 lines
Adam Simpkins [email protected]
Quoted 3 lines · Teemu Likonen
I just want to say that I really like your 'git graph'. I would like to see it integrated to 'git log', perhaps as 'git log --pretty=graph' or 'git log --graph'.
Any reason?
I don't see why it's necessary to bundle all useful commands into one big super-command. I like the idea of typing "git-graph". Then again, I happen to like the git-command syntax which seems to have fallen out of favour, so don't pay attention to me.
Steve
Stephen Sinclair kirjoitti:
Quoted 1 line
On Mon, Mar 31, 2008 at 1:17 PM, Teemu Likonen <[email protected]>
Quoted 10 lines · wrote:
Quoted 3 lines
I just want to say that I really like your 'git graph'. I would
like to see it integrated to 'git log', perhaps as 'git log --pretty=graph' or 'git log --graph'.Any reason?
I don't see why it's necessary to bundle all useful commands into one big super-command. I like the idea of typing "git-graph". Then again, I happen to like the git-command syntax which seems to have fallen out of favour, so don't pay attention to me.
Adam's 'git graph' is a way of viewing log (in terminal environment), it looks very similar to 'git log --pretty=oneline' and it accepts very much the same command line options. That's why I see 'git log' being logical place for such functionality.
Actually, to me it would be more logical if 'git whatchanged' was 'git log --changed' or '--verbose / -v' something.
Quoted 4 lines · Teemu Likonen
Adam's 'git graph' is a way of viewing log (in terminal environment), it looks very similar to 'git log --pretty=oneline' and it accepts very much the same command line options. That's why I see 'git log' being logical place for such functionality.
Adam suggested that it may be possible to abstract the graphing API so that it can be called progressively. I would love to see:
git log --pretty=format:'%g %h %s'
where %g would be "the graph lines for this commit." But maybe that is not workable since the graph may take multiple lines to show.
Quoted 2 lines
Actually, to me it would be more logical if 'git whatchanged' was 'git log --changed' or '--verbose / -v' something.
How about:
git log --raw --full-history --always
which is identical. Though in most cases, one would be happy with "git log --raw". I think whatchanged really only exists separately because it predates the merging of many of the revision-walking commands.
-Peff
Teemu Likonen kirjoitti:
Quoted 7 lines
Adam's 'git graph' is a way of viewing log (in terminal environment), it looks very similar to 'git log --pretty=oneline' and it accepts very much the same command line options. That's why I see 'git log' being logical place for such functionality.
Actually, to me it would be more logical if 'git whatchanged' was 'git log --changed' or '--verbose / -v' something.
May I add that I'm the kind of user who only understands the porcelain Git. In my mindset it's best when commands are in logical units by their functionality (from user's point of view).
I see 'git log' as a command for studying history log and to me 'git whatchanged' sounds like some user's personal _alias_ to 'git log --raw --full-history --always' or something (thanks Jeff). Similarly 'git graph' sounds like an alias to 'git log --pretty=graph' for someone who uses this a lot.
What's wrong with "tig -g", I have to wonder...
Quoted 1 line · Junio C Hamano
What's wrong with "tig -g", I have to wonder...
As I mentioned in my initial email, I tried using the graph in tig, but I found it very hard to read. However, going back and taking a closer look at tig, I think its graph is just plain wrong in some cases.
For example, here's a comparison of the first several lines of output of "git-graph --date-order --all" and "tig -- --all" in my repository for one of the projects I am working on. I've replaced the commit subjects with just the abbreviated hashes. (Hopefully your mail reader displays this with a monospace font.)
git-graph:
* 8076867
* 2613e2b
M 542f526
|\
* | 642b381
| | * e73dfa2 | \ \ | \ \ M-. \ \ 64e1d85 |\ \ \ \ | | * | | 836521f | | | | | * ce43181 | | | | | * eaeeb08 | | | | | M 79d3db3 | | | | | |\ | | | | | | * da5bc9e | * | | | | | b947aab | | | | | M \ 9ade1bc | | | | | |\ | | | | | * | | | 8f3727b | | | | * | | | 2d102cd * | | | | | | | bf5c6e3 | |/ / / / / / |/| / / / / / * | | | | | | a570370 |/ / / / / / * | | | | | dde9a00 | | | | | * 09048ce | | | | |/ | | | | * 4ee2351
tig (version 0.10.git):
+ 8076867
* 2613e2b
M 542f526
* | 642b381 | | + e73dfa2 M | \ \ 64e1d85 |`.`* | | 836521f | | | | | + ce43181 | | | | | * eaeeb08 | | | | | M 79d3db3 | | | | | |`* da5bc9e | * | | | | | b947aab | | | | | M \ 9ade1bc | | | | * |`.`. 8f3727b | | | | * | | | 2d102cd * | | | | | | | bf5c6e3 *' / / / / / / a570370 *' / / / / / dde9a00 | | | | | * 09048ce | | | | *' 4ee2351
Looking at the tig output, it seems like tig is definitely screwing up around the 3-way merge at 64e1d85. The way I read the output, it looks like it is telling me that commit 836521f is a parent of 542f526, which is incorrect.
It also doesn't seem to display things correctly when branch lines need to cross. For example, 836521f is a child of a570370, and b947aab is a child of dde9a00. However, the way I read tig's graph, it looks like it is telling me exactly the opposite--that 836521f is a child of dde9a00 and b947aab is a child of a570370.
I think part of the problem is that tig displays exactly 1 commit per line. It's hard to represent octopus merges and crossing branches if it all has to fit in 1 line. This is why git-graph sometimes takes extra lines in between commits to display where the branch lines are going.
The git-forest command that Matthieu Moy pointed out also seems to do a good job of representing the graph, while being a bit more compact than git-graph when displaying crossing branches. (I just joined the list in the last couple of days, so I wasn't aware of git-forest. I did try googling for similar tools before I started, but only came up with tig.)
Signature · 2 lines
Adam Simpkins [email protected]
Hi,
Quoted 12 lines · Adam Simpkins
This is a first pass at a command to print a text-based graph of the commit history. It is similar to the history graph shown by gitk, but doesn't require a windowing system.
Signed-off-by Adam Simpkins <[email protected]>---
I added this since I really like gitk, but don't always have easy access to an X display on some of the systems I use. I tried using tig, but I found its graph output very hard to read. The graph produced by git-graph is less compact, but much more readable.
Quoted 6 lines
Ultimately, it would probably be better to integrate this functionality into git-log, instead of having it as a standalone command. For example, a new --graph option could be added to cause the graph to be displayed alongside the existing git log output. However, this would require tighter integration between the graphing code and the
log_tree.candpretty.ccode, which I'm not all that familiar with.
Funny. Some time ago, Shawn and I mused how involved it would be to write some tool very similar to this, only that the output could be read back by git-gui. This would be needed for a sensible "rebase -i" implementation in git-gui.
Ciao,
Dscho
Quoted 3 lines · Adam Simpkins
This is a first pass at a command to print a text-based graph of the commit history. It is similar to the history graph shown by gitk, but doesn't require a windowing system.
Should I understand that git-show-branch has too cryptic an output?
Signature · 3 lines
Jakub Narebski Poland ShadeHawk on #git
Quoted 7 lines · Jakub Narebski
Quoted 3 lines · Adam Simpkins
This is a first pass at a command to print a text-based graph of the commit history. It is similar to the history graph shown by gitk, but doesn't require a windowing system.
Should I understand that git-show-branch has too cryptic an output?
Yes, I find it a bit hard to read with more than just a few branches.
Signature · 2 lines
Adam Simpkins [email protected]
Quoted 3 lines · Adam Simpkins
This is a first pass at a command to print a text-based graph of the commit history. It is similar to the history graph shown by gitk, but doesn't require a windowing system.
Did you look at git-forest too?
http://git.or.cz/gitwiki/InterfacesFrontendsAndTools#head-ed34e1966c28f24d459c5ad30a21457baa9bed23
Signature · 1 line
Matthieu
Quoted 9 lines · Matthieu Moy
Quoted 3 lines · Adam Simpkins
This is a first pass at a command to print a text-based graph of the commit history. It is similar to the history graph shown by gitk, but doesn't require a windowing system.
Did you look at git-forest too?
http://git.or.cz/gitwiki/InterfacesFrontendsAndTools#head-ed34e1966c28f24d459c5ad30a21457baa9bed23
Interesting, I wasn't aware of this utility. It does look very similar.
Signature · 2 lines
Adam Simpkins [email protected]