Skip to content

Commit

Permalink
Add max_entries argument to 'log' porcelain.
Browse files Browse the repository at this point in the history
  • Loading branch information
jelmer committed Jan 18, 2014
1 parent 08640c1 commit 084c7a6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
10 changes: 6 additions & 4 deletions dulwich/porcelain.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
Tag,
parse_timezone,
)
from dulwich.objectspec import parse_object
from dulwich.patch import write_tree_diff
from dulwich.repo import (BaseRepo, Repo)
from dulwich.server import update_server_info as server_update_server_info
Expand Down Expand Up @@ -288,14 +289,15 @@ def show_object(repo, obj, outstream):
}[obj.type_name](repo, obj, outstream)


def log(repo=".", outstream=sys.stdout):
def log(repo=".", outstream=sys.stdout, max_entries=None):
"""Write commit logs.
:param repo: Path to repository
:param outstream: Stream to write log output to
:param max_entries: Optional maximum number of entries to display
"""
r = open_repo(repo)
walker = r.get_walker()
walker = r.get_walker(max_entries=max_entries)
for entry in walker:
print_commit(entry.commit, outstream)

Expand All @@ -312,8 +314,8 @@ def show(repo=".", objects=None, outstream=sys.stdout):
if not isinstance(objects, list):
objects = [objects]
r = open_repo(repo)
for obj in objects:
show_object(r, r[obj], outstream)
for objectish in objects:
show_object(r, parse_object(r, objectish), outstream)


def diff_tree(repo, old_tree, new_tree, outstream=sys.stdout):
Expand Down
10 changes: 9 additions & 1 deletion dulwich/tests/test_porcelain.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,15 @@ def test_simple(self):
self.repo.refs["HEAD"] = c3.id
outstream = StringIO()
porcelain.log(self.repo.path, outstream=outstream)
self.assertTrue(outstream.getvalue().startswith("-" * 50))
self.assertEquals(3, outstream.getvalue().count("-" * 50))

def test_max_entries(self):
c1, c2, c3 = build_commit_graph(self.repo.object_store, [[1], [2, 1],
[3, 1, 2]])
self.repo.refs["HEAD"] = c3.id
outstream = StringIO()
porcelain.log(self.repo.path, outstream=outstream, max_entries=1)
self.assertEquals(1, outstream.getvalue().count("-" * 50))


class ShowTests(PorcelainTestCase):
Expand Down

0 comments on commit 084c7a6

Please sign in to comment.