Class: Amp::Git::VersionedFile

Inherits:
Core::Repositories::AbstractVersionedFile
  • Object
show all
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

VersionedWorkingFile

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#pathObject

Returns the value of attribute path.



25
26
27
# File 'lib/amp-git/repo_format/versioned_file.rb', line 25

def path
  @path
end

#repoObject

Returns the value of attribute repo.



26
27
28
# File 'lib/amp-git/repo_format/versioned_file.rb', line 26

def repo
  @repo
end

#revisionObject

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.

Parameters:

  • vfile (AbstractVersionedFile)

    what we’re being compared to

Returns:

  • (Boolean)


93
94
95
# File 'lib/amp-git/repo_format/versioned_file.rb', line 93

def ==(vfile)
  !cmp(vfile)
end

#changesetAbstractChangeset

The changeset to which this versioned file belongs.

Returns:

  • (AbstractChangeset)


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)

Parameters:

  • item (AbstractVersionedFile, String)

    what we’re being compared to

Returns:

  • (Boolean)

    true if different, false if 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

#dataString

The contents of a file at the given revision

Returns:

  • (String)

    the data at the current 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

#flagsString

Gets the flags for this file (‘x’, ‘l’, or ”)

Returns:

  • (String)

    ‘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

#hashInteger

The hash value for sticking this fucker in a hash.

Returns:

  • (Integer)


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

Returns:

  • (Boolean)


68
69
70
# File 'lib/amp-git/repo_format/versioned_file.rb', line 68

def renamed?
  nil
end

#sizeInteger

The size of this file

Returns:

  • (Integer)


46
47
48
# File 'lib/amp-git/repo_format/versioned_file.rb', line 46

def size
  @size ||= data.size
end