Skip to content

Commit

Permalink
avoid `git log --graph' inefficiency
Browse files Browse the repository at this point in the history
`git log --graph --max-count=N' calculates the graph for the complete
history; the `--max-count=N' only affects the output phase.

`git log --graph HEAD~N..HEAD' only calculates the graph for
HEAD~N..HEAD but the graph is not the same; commits that are reachable
from HEAD but do not descend from HEAD~N will appear as root commits.

Address this by using `--max-count' and REV~M..REV to together when
possible.  More precisely do so when showing the log for a single rev
in the log buffer.  M is usually twice as large as N but at least 1024,
which greatly reduces the risk of the graphs for REV~M..REV and REV to
differ.

In the status buffer also limit the range for the log section inserted
by `magit-insert-recent-commits', but without avoiding that non-root
commits appear as root commits (because that happens for the sections
inserted by `magit-insert-{unpulled and unpushed}-commits' too).

Also see http://www.spinics.net/lists/git/msg232230.html.
  • Loading branch information
tarsius committed Sep 7, 2015
1 parent f9f5a06 commit 55a61d1
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions lisp/magit-log.el
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,16 @@ Type \\[magit-reset] to reset HEAD to the commit at point.
(setq args (remove "--follow" args)))
(when (--any-p (string-match-p magit-log-remove-graph-re it) args)
(setq args (remove "--graph" args)))
(when (and magit-log-cutoff-length
(= (length revs) 1)
(setq revs (car revs))
(not (string-match-p "\\.\\." revs))
(not (member revs '("--all" "--branches"))))
(setq revs (format "%s~%s..%s" revs
(min (1- (string-to-number
(magit-git-string "rev-list" "--count" revs)))
(max 1024 (* 2 magit-log-cutoff-length)))
revs)))
(magit-insert-section (logbuf)
(magit-insert-log revs args files)))

Expand Down Expand Up @@ -1216,8 +1226,12 @@ commits."
Show the last `magit-log-section-commit-count' commits."
(magit-insert-section (recent nil collapse)
(magit-insert-heading "Recent commits:")
(magit-insert-log nil (cons (format "-%d" magit-log-section-commit-count)
magit-log-section-arguments))))
(magit-insert-log
(let ((beg (format "HEAD~%s" magit-log-section-commit-count)))
(and (magit-rev-verify beg)
(concat beg "..HEAD")))
(cons (format "-%d" magit-log-section-commit-count)
magit-log-section-arguments))))

(defun magit-insert-unpulled-cherries ()
"Insert section showing unpulled commits.
Expand Down

0 comments on commit 55a61d1

Please sign in to comment.