1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | from csvn.repos import * |
---|
4 | from csvn.auth import User |
---|
5 | import csvn.core |
---|
6 | import time, sys, gc |
---|
7 | from optparse import OptionParser |
---|
8 | import textwrap |
---|
9 | |
---|
10 | usage = """python log.py [OPTION]... URL |
---|
11 | |
---|
12 | Print all of the log messages for a repository at a given URL, |
---|
13 | similar to 'svn log URL'. Useful for demo purposes only. |
---|
14 | """ |
---|
15 | |
---|
16 | parser = OptionParser(usage=usage) |
---|
17 | parser.add_option("-u", "--username", dest="username", |
---|
18 | help="commit the changes as USERNAME") |
---|
19 | parser.add_option("-v", "--verbose", dest="verbose", |
---|
20 | action='store_true', help="verbose mode", |
---|
21 | default=False) |
---|
22 | parser.add_option("", "--stop-on-copy", dest="stop_on_copy", |
---|
23 | action='store_true', help="verbose mode", |
---|
24 | default=False) |
---|
25 | parser.add_option("-r", "", dest="rev", |
---|
26 | help="revision range") |
---|
27 | |
---|
28 | (options, args) = parser.parse_args() |
---|
29 | |
---|
30 | if len(args) != 1: |
---|
31 | parser.print_help() |
---|
32 | sys.exit(1) |
---|
33 | |
---|
34 | csvn.core.svn_cmdline_init("", csvn.core.stderr) |
---|
35 | repos_url = args[0] |
---|
36 | revs = options.rev |
---|
37 | if revs and ":" in revs: |
---|
38 | [start_rev, end_rev] = revs.split(":") |
---|
39 | elif revs: |
---|
40 | start_rev = revs |
---|
41 | end_rev = revs |
---|
42 | else: |
---|
43 | start_rev = 1 |
---|
44 | end_rev = "HEAD" |
---|
45 | |
---|
46 | session = RemoteRepository(repos_url, user=User(options.username)) |
---|
47 | |
---|
48 | if end_rev == "HEAD": |
---|
49 | end_rev = session.latest_revnum() |
---|
50 | if start_rev == "HEAD": |
---|
51 | start_rev = session.latest_revnum() |
---|
52 | start_rev = int(start_rev) |
---|
53 | end_rev = int(end_rev) |
---|
54 | |
---|
55 | def count_lines(message): |
---|
56 | num_lines = message.count("\n") + 1 |
---|
57 | if num_lines == 1: |
---|
58 | num_lines = "1 line" |
---|
59 | else: |
---|
60 | num_lines = "%d lines" % num_lines |
---|
61 | return num_lines |
---|
62 | |
---|
63 | for entry in \ |
---|
64 | session.log(start_rev, end_rev, discover_changed_paths=options.verbose, |
---|
65 | stop_on_copy=options.stop_on_copy): |
---|
66 | |
---|
67 | num_lines = count_lines(entry.message) |
---|
68 | print("-" * 72) |
---|
69 | print("r%d | %s | %s | %s" % (entry.revision, entry.author, |
---|
70 | entry.date.as_human_string(), num_lines)) |
---|
71 | if options.verbose: |
---|
72 | print("Changed paths:") |
---|
73 | for key, value in entry.changed_paths.items(): |
---|
74 | value = value[0] |
---|
75 | if value.copyfrom_rev != SVN_INVALID_REVNUM: |
---|
76 | print(" %s %s (from %s:%d)" % (value.action, key, |
---|
77 | value.copyfrom_path, |
---|
78 | value.copyfrom_rev)) |
---|
79 | else: |
---|
80 | print(" %s %s" % (value.action, key)) |
---|
81 | print("") |
---|
82 | print(entry.message) |
---|
83 | |
---|
84 | print("-" * 72) |
---|