Class: Amp::VersionedWorkingFile

Inherits:
VersionedFile show all
Defined in:
lib/amp/repository/versioned_file.rb

Overview

This is a VersionedFile, except it’s in the working directory, so its data is stored on disk in the actual file. Other than that, it’s basically the same in its interface!

Constant Summary

Constants included from RevlogSupport::Node

RevlogSupport::Node::NULL_ID, RevlogSupport::Node::NULL_REV

Instance Attribute Summary

Attributes inherited from VersionedFile

#change_id, #file_id, #path

Instance Method Summary collapse

Methods inherited from VersionedFile

#<=>, #==, #===, #ancestor, #annotate, #annotate_decorate, #annotate_diff_pair, #annotate_get_file, #annotate_parents_helper, #branch, #description, #file_node, #file_rev, #files, #flags, #get_parents_helper, #hash, #inspect, #linkrev, #manifest, #nil?, #node, #to_i, #user

Methods included from RevlogSupport::Node

#short

Constructor Details

#initialize(repo, path, opts = {}) ⇒ VersionedWorkingFile

Initializes a new working dir file - slightly different semantics here



361
362
363
364
365
366
367
368
# File 'lib/amp/repository/versioned_file.rb', line 361

def initialize(repo, path, opts={})
  @repo, @path = repo, path
  @change_id = nil
  @file_rev, @file_node = nil, nil
  
  @file_log = opts[:file_log] if opts[:file_log]
  @changeset = opts[:working_changeset]
end

Instance Method Details

#changesetObject

Gets the working directory changeset



372
373
374
# File 'lib/amp/repository/versioned_file.rb', line 372

def changeset
  @changeset ||= WorkingDirectoryChangeset.new(@repo)
end

#childrenObject

Working directory has no children!



444
# File 'lib/amp/repository/versioned_file.rb', line 444

def children; []; end

#cmp(text) ⇒ Boolean

Compares to the given text. Overridden because this file is stored on disk in the actual working directory.

Parameters:

  • text (String)

    the text to compare to

Returns:

  • (Boolean)

    true if the two are different



470
471
472
# File 'lib/amp/repository/versioned_file.rb', line 470

def cmp(text)
  @repo.working_read(@path) != text
end

#dataObject

Get the contents of this file



409
410
411
412
# File 'lib/amp/repository/versioned_file.rb', line 409

def data
  data = @repo.working_read(@path)
  data
end

#dateObject

Returns the date that this file was last modified.



455
456
457
458
459
460
461
462
# File 'lib/amp/repository/versioned_file.rb', line 455

def date
  t, tz = changeset.date
  begin
    return [FileUtils.lstat(@repo.join(@path)).mtime, tz]
  rescue Errno::ENOENT
    return [t, tz]
  end
end

#file(file_id) ⇒ Object

Returns the file at a different revision



396
397
398
# File 'lib/amp/repository/versioned_file.rb', line 396

def file(file_id)
  VersionedFile.new(@repo, repo_path, :file_id => file_id, :file_log => file_log)
end

#file_logObject

Gets the file log?



384
385
386
# File 'lib/amp/repository/versioned_file.rb', line 384

def file_log
  @repo.file(repo_path)
end

#parentsObject

The working directory’s parents are the heads, so get this file in the previous revision.



425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
# File 'lib/amp/repository/versioned_file.rb', line 425

def parents
  p = @path
  rp = repo_path
  pcl = @changeset.parents
  fl = file_log
  pl = [[rp, pcl[0].manifest[rp] || NULL_ID, fl]]
  if pcl.size > 1
    if rp != p
      fl = nil
    end
    pl << [p, pcl[1].manifest[p] || NULL_ID, fl]
  end
  pl.select {|_, n, __| n != NULL_ID}.map do |parent, n, l|
    VersionedFile.new(@repo, parent, :file_id => n, :file_log => l)
  end
end

#renamedObject

Has this file been renamed? If so give some good info.



416
417
418
419
420
# File 'lib/amp/repository/versioned_file.rb', line 416

def renamed
  rp = repo_path
  return nil if rp == @path
  [rp, (self.changeset.parents[0].manifest[rp] || NULL_ID)]
end

#repo_pathObject

Dunno why this is here



378
379
380
# File 'lib/amp/repository/versioned_file.rb', line 378

def repo_path
  @repo.dirstate.copy_map[@path] || @path
end

#revisionObject

Get what revision this is



402
403
404
405
# File 'lib/amp/repository/versioned_file.rb', line 402

def revision
  return @changeset.revision if @changeset
  file_log[@file_rev].link_rev
end

#sizeObject

Returns the current size of the file



449
450
451
# File 'lib/amp/repository/versioned_file.rb', line 449

def size
  File.stat(@repo.join(@path)).size
end

#to_sObject

String representation



390
391
392
# File 'lib/amp/repository/versioned_file.rb', line 390

def to_s
  "#{path}@#{@changeset}"
end