Module: Amp::CommandSupport
- Included in:
- Command
- Defined in:
- lib/amp/commands/command_support.rb
Constant Summary collapse
- REV_SEP =
When a user specifies a range, REV_SEP is between the given revisions.
":"
Instance Method Summary collapse
-
#expand_path(*arr) ⇒ Object
Return repository location relative to cwd or from [paths].
- #local_path(path) ⇒ Object
- #log_message(message, logfile) ⇒ Object
-
#parse_url(*arr) ⇒ Object
returns [String, Array || nil, String].
-
#print_update_stats(stats) ⇒ Object
Prints the statistics returned from an update or merge.
-
#revision_lookup(repo, value, default = nil) ⇒ String
Looks up the node ID of a given revision in the repository.
-
#revision_pair(repo, revisions) ⇒ Array<String>
Parses strings that represent a range of.
Instance Method Details
#expand_path(*arr) ⇒ Object
Return repository location relative to cwd or from [paths]
105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/amp/commands/command_support.rb', line 105 def (*arr) loc = arr.shift dflt = arr.shift # dflt = default cnfg = arr.pop # always take the last return loc if loc =~ /:\/\// or File.directory?(File.join(loc, '.hg')) path = cnfg['paths'][loc] if !path && dflt path = cnfg['paths'][dflt] end path || loc end |
#local_path(path) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/amp/commands/command_support.rb', line 91 def local_path(path) case path when /file:\/\/localhost\// path[17..-1] when /file:\/\// path[8..-1] when /file:/ path[6..-1] else path end end |
#log_message(message, logfile) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/amp/commands/command_support.rb', line 120 def (, logfile) if && logfile raise abort('options --message and --logfile are mutually exclusive') end if ! && logfile begin = logfile == '-' ? $stdin.read : File.read(logfile) rescue IOError => e raise abort("can't read commit message '#{logfile}': #{e}") end end end |
#parse_url(*arr) ⇒ Object
returns [String, Array || nil, String]
77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/amp/commands/command_support.rb', line 77 def parse_url(*arr) url = arr.shift revs = arr.shift || [] unless url =~ /#/ hds = revs.any? ? revs : [] return url, hds, revs[-1] end url, branch = url.split('#')[0..1] checkout = revs[-1] || branch [url, revs + [branch], checkout] end |
#print_update_stats(stats) ⇒ Object
Prints the statistics returned from an update or merge. These are given in the form of a hash, such as => 0, :unresolved => 3, …, and should be printed in a nice manner.
31 32 33 |
# File 'lib/amp/commands/command_support.rb', line 31 def print_update_stats(stats) Amp::UI.status stats.map {|note, files| "#{files.size} files #{note}" }.join(", ") end |
#revision_lookup(repo, value, default = nil) ⇒ String
Looks up the node ID of a given revision in the repository. Since this method uses Repository#lookup, the choices for “value” are very flexible. You can choose a revision number, a partial node ID, “tip”, and so on. See LocalRepository#lookup for more details.
19 20 21 22 |
# File 'lib/amp/commands/command_support.rb', line 19 def revision_lookup(repo, value, default = nil) value ||= default repo.lookup(value) end |
#revision_pair(repo, revisions) ⇒ Array<String>
Parses strings that represent a range of
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/amp/commands/command_support.rb', line 47 def revision_pair(repo, revisions) #revisions = [revisions] unless revisions.is_a?(Array) if !revisions || revisions.empty? return repo.dirstate.parents.first, nil end stop = nil if revisions.size == 1 #old revision compared with working dir? if revisions[0].include? REV_SEP start, stop = revisions.first.split REV_SEP, 2 start = revision_lookup repo, start, 0 stop = revision_lookup repo, stop, repo.size - 1 else start = revision_lookup repo, revisions.first end elsif revisions.size == 2 if revisions.first.include?(REV_SEP) || revisions.second.include?(REV_SEP) raise ArgumentError.new("too many revisions specified") end start = revision_lookup(repo, revisions.first) stop = revision_lookup(repo, revisions.second) else raise ArgumentError.new("too many revisions specified") end [start, stop] end |