Class: Amp::Git::VersionedFile
- Inherits:
-
Core::Repositories::AbstractVersionedFile
- Object
- Core::Repositories::AbstractVersionedFile
- Amp::Git::VersionedFile
- Defined in:
- lib/amp-git/repo_format/versioned_file.rb
Overview
This class allows you to access a file at a given revision in the repo’s history. You can compare them, sort them, access the changeset, and all sorts of stuff.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
-
#repo ⇒ Object
Returns the value of attribute repo.
-
#revision ⇒ Object
Returns the value of attribute revision.
Instance Method Summary collapse
-
#==(vfile) ⇒ Boolean
Are two versioned files the same? This means same path and revision indexes.
-
#changeset ⇒ AbstractChangeset
The changeset to which this versioned file belongs.
-
#cmp(item) ⇒ Boolean
Compares to either a bit of text or another versioned file.
-
#data ⇒ String
The contents of a file at the given revision.
-
#flags ⇒ String
Gets the flags for this file (‘x’, ‘l’, or ”).
-
#hash ⇒ Integer
The hash value for sticking this fucker in a hash.
-
#initialize(repo, path, opts = {}) ⇒ VersionedFile
constructor
A new instance of VersionedFile.
-
#renamed? ⇒ Boolean
Has this file been renamed? If so, return some useful info.
-
#size ⇒ Integer
The size of this file.
Constructor Details
#initialize(repo, path, opts = {}) ⇒ VersionedFile
Returns a new instance of VersionedFile.
28 29 30 31 32 |
# File 'lib/amp-git/repo_format/versioned_file.rb', line 28 def initialize(repo, path, opts={}) @repo = repo @path = path @revision = opts[:revision] end |
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
25 26 27 |
# File 'lib/amp-git/repo_format/versioned_file.rb', line 25 def path @path end |
#repo ⇒ Object
Returns the value of attribute repo.
26 27 28 |
# File 'lib/amp-git/repo_format/versioned_file.rb', line 26 def repo @repo end |
#revision ⇒ Object
Returns the value of attribute revision.
24 25 26 |
# File 'lib/amp-git/repo_format/versioned_file.rb', line 24 def revision @revision end |
Instance Method Details
#==(vfile) ⇒ Boolean
Are two versioned files the same? This means same path and revision indexes.
93 94 95 |
# File 'lib/amp-git/repo_format/versioned_file.rb', line 93 def ==(vfile) !cmp(vfile) end |
#changeset ⇒ AbstractChangeset
The changeset to which this versioned file belongs.
38 39 40 |
# File 'lib/amp-git/repo_format/versioned_file.rb', line 38 def changeset @changeset ||= Changeset.new @repo, @revision end |
#cmp(item) ⇒ Boolean
Compares to either a bit of text or another versioned file. Returns true if different, false for the same. (much like <=> == 0 for the same)
79 80 81 82 83 84 85 86 |
# File 'lib/amp-git/repo_format/versioned_file.rb', line 79 def cmp(item) return data == item if item.is_a? String not (data == item.data && size == item.size && revision == item.revision && repo.root == item.repo.root ) end |
#data ⇒ String
The contents of a file at the given revision
54 55 56 |
# File 'lib/amp-git/repo_format/versioned_file.rb', line 54 def data @data ||= `git show #{revision}:#{path} 2> /dev/null` end |
#flags ⇒ String
Gets the flags for this file (‘x’, ‘l’, or ”)
101 102 103 |
# File 'lib/amp-git/repo_format/versioned_file.rb', line 101 def flags '' # because git doesn't track them end |
#hash ⇒ Integer
The hash value for sticking this fucker in a hash.
62 63 64 |
# File 'lib/amp-git/repo_format/versioned_file.rb', line 62 def hash "#{size}--#{path}--#{repo.root}--#{revision} 2> /dev/null".hash end |
#renamed? ⇒ Boolean
Has this file been renamed? If so, return some useful info
68 69 70 |
# File 'lib/amp-git/repo_format/versioned_file.rb', line 68 def renamed? nil end |
#size ⇒ Integer
The size of this file
46 47 48 |
# File 'lib/amp-git/repo_format/versioned_file.rb', line 46 def size @size ||= data.size end |