Class: PVN::Log::Command

Inherits:
Command::Command show all
Defined in:
lib/pvn/log/command.rb

Constant Summary collapse

DEFAULT_LIMIT =
15

Instance Method Summary collapse

Methods inherited from Command::Command

description, example, getdoc, #initialize, matches_subcommand?, options, optscls, optset, #show_help, subcommands, summary, #to_doc, usage

Constructor Details

This class inherits a constructor from PVN::Command::Command

Instance Method Details

#find_entries_for_path(path, options) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/pvn/log/command.rb', line 60

def find_entries_for_path path, options
  cmdargs = Hash.new
  cmdargs[:path] = path
  
  [ :limit, :verbose, :revision ].each do |field|
    cmdargs[field] = options.send field
  end

  if options.user
    cmdargs[:limit] = nil
  end
  
  # we can't cache this, because we don't know if there has been an svn
  # update since the previous run:
  cmdargs[:use_cache] = false

  logargs = SVNx::LogCommandArgs.new cmdargs
  elmt    = PVN::IO::Element.new :local => path || '.'
  log     = elmt.log logargs
  entries = log.entries

  info { "options: #{options}" }
  info { "options.user: #{options.user}" }

  if options.user
    entries = find_entries_for_user entries, options.user, options.limit
    info { "entries: #{entries}" }

    # don't show relative revisions, since we've got a slice out of the list:
    from_head = nil
    from_tail = nil
  end

  entries
end

#find_entries_for_user(entries, user, limit) ⇒ Object



96
97
98
99
100
101
102
103
104
# File 'lib/pvn/log/command.rb', line 96

def find_entries_for_user entries, user, limit
  entries = entries.select { |entry| entry.author == user }

  raise "ERROR: no matching log entries for '#{user}'" if entries.empty?

  info { "entries: #{entries}" }

  limit ? entries[0 ... limit] : entries
end

#init(options) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/pvn/log/command.rb', line 34

def init options
  paths = options.paths

  paths = %w{ . } if paths.empty?

  info "paths: #{paths}"

  allentries = Array.new

  paths.each do |path|
    allentries.concat find_entries_for_path path, options
  end

  # we can show relative revisions for a single path, without filtering by
  # user, or by limit or revision.

  show_relative = !options.user && paths.size == 1 && !options.revision
  
  # this should be refined to options.revision.head?
  from_head = show_relative
  from_tail = show_relative && !options.limit

  ef = PVN::Log::EntriesFormatter.new options.color, allentries, from_head, from_tail
  puts ef.format
end