git-codereview: fix branch "behind" count

git-codereview pending's count of how far behind a branch is is
currently wrong. It computes this from the length of the string
printed by git log --format=format:x, but forgets that git log
automatically adds new lines between each commit. As a result, given
that the true count is n, git pending prints 2n-1.

Fix this by counting the number of lines printed by git log, not the
number of characters.

Change-Id: I5702a833d34333099cad7d88c03837088ac4f9a8
Reviewed-by: Brad Fitzpatrick <>
diff --git a/git-codereview/branch.go b/git-codereview/branch.go
index b451507..1f08337 100644
--- a/git-codereview/branch.go
+++ b/git-codereview/branch.go
@@ -184,7 +184,7 @@
 	b.commitsAhead = len(b.pending)
-	b.commitsBehind = len(trim(cmdOutput("git", "log", "--format=format:x", b.FullName()+".."+b.OriginBranch(), "--")))
+	b.commitsBehind = len(lines(cmdOutput("git", "log", "--format=format:x", b.FullName()+".."+b.OriginBranch(), "--")))
 // Submitted reports whether some form of b's pending commit
diff --git a/git-codereview/pending_test.go b/git-codereview/pending_test.go
index f43dd36..7f2d354 100644
--- a/git-codereview/pending_test.go
+++ b/git-codereview/pending_test.go
@@ -102,7 +102,7 @@
-		work REVHASH..REVHASH (5 behind)
+		work REVHASH..REVHASH (3 behind)