Class: Amp::WorkingDirectoryChangeset

Inherits:
Changeset show all
Defined in:
lib/amp/revlogs/changeset.rb

Overview

This is a special changeset that specifically works within the working directory. We sort of have to combine the old revision logs with the fact that files might be changed, and not in the revision logs! oh, mercy!

Constant Summary

Constants included from RevlogSupport::Node

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

Instance Attribute Summary

Attributes inherited from Changeset

#repo

Instance Method Summary collapse

Methods inherited from Changeset

#<=>, #[], #ancestor, #ancestors, #each, #easy_date, #file_info, #file_node, #hash, #hex, #inspect, #manifest_delta, #node_id, #raw_changeset, #revision, #tags, #to_i, #to_templated_s

Methods included from Enumerable

#inject, #select_map

Methods included from RevlogSupport::Node

#short

Constructor Details

#initialize(repo, opts = {:text => ""}) ⇒ WorkingDirectoryChangeset

Returns a new instance of WorkingDirectoryChangeset.



342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
# File 'lib/amp/revlogs/changeset.rb', line 342

def initialize(repo, opts={:text => ""})
  @repo = repo
  @revision = nil
  @node_id  = nil
  @text = opts[:text]
  require 'time' if opts[:date].kind_of?(String)
  @date = opts[:date].kind_of?(String) ? Time.parse(opts[:date]) : opts[:date]
  @user = opts[:user] if opts[:user]
  @parents = opts[:parents].map {|p| Changeset.new(@repo, p)} if opts[:parents]
  @status = opts[:changes] if opts[:changes]
  
  @extra = {}
  @extra = opts[:extra].dup if opts[:extra]
  unless @extra["branch"]
    branch = @repo.dirstate.branch
    # encoding - to UTF-8
    @extra["branch"] = branch
  end
  @extra["branch"] = "default" if @extra["branch"] && @extra["branch"].empty?
  
end

Instance Method Details

#addedObject

What files have we added?



505
# File 'lib/amp/revlogs/changeset.rb', line 505

def added; status[:added]; end

#branchObject

What branch are we in?



515
# File 'lib/amp/revlogs/changeset.rb', line 515

def branch; @extra["branch"]; end

#childrenObject

No children. Returns the empty array.



519
# File 'lib/amp/revlogs/changeset.rb', line 519

def children; []; end

#cleanObject

What files are pristine since the last revision?



513
# File 'lib/amp/revlogs/changeset.rb', line 513

def clean; status[:normal]; end

#dateObject

Well, I guess the working directory’s date is… right now!



394
395
396
# File 'lib/amp/revlogs/changeset.rb', line 394

def date
  @date ||= Time.new
end

#deletedObject

What files have been deleted (but not officially)?



509
# File 'lib/amp/revlogs/changeset.rb', line 509

def deleted; status[:deleted]; end

#descriptionObject

If there’s a description, ok then



499
# File 'lib/amp/revlogs/changeset.rb', line 499

def description; @text; end

#extraObject

Any other extra data? i’d like to hear it



517
# File 'lib/amp/revlogs/changeset.rb', line 517

def extra; @extra; end

#filesObject

Files affected in this transaction: modified, added, removed.



501
# File 'lib/amp/revlogs/changeset.rb', line 501

def files; (status[:modified] + status[:added] + status[:removed]).sort; end

#flags(path) ⇒ String

Gets the flags for the file at current state in time

Parameters:

  • path (String)

    the path to the file

Returns:

  • (String)

    the flags, such as “x”, “l”, or “”



463
464
465
466
467
468
469
470
471
472
# File 'lib/amp/revlogs/changeset.rb', line 463

def flags(path)
  if @manifest
    return manifest.flags[path] || ""
  end
  pnode = parents[0].raw_changeset[0]

  orig = @repo.dirstate.copy_map[path] || path
  node, flag = @repo.manifest.find(pnode, orig)
  return @repo.dirstate.flags(@repo.working_join(path))
end

#get_file(path, file_log = nil) ⇒ Amp::VersionedWorkingFile

Returns a VersionedWorkingFile to represent the file at the given point in time. It represents a file in the working directory, which obvious don’t read from the history, but from the actual file in question.

Parameters:

  • path

    the path to the file

  • file_log (defaults to: nil)

    the log for the file to save some computation

Returns:



453
454
455
456
# File 'lib/amp/revlogs/changeset.rb', line 453

def get_file(path, file_log=nil)
  VersionedWorkingFile.new(@repo, path, :working_changeset => self, 
                                        :file_log => file_log)
end

#include?(key) ⇒ Boolean

Do I include a given file? (not sure this is ever used yet)

Returns:



377
# File 'lib/amp/revlogs/changeset.rb', line 377

def include?(key); "?r".include?(@repo.dirstate[key].status.to_hg_letter); end

#manifestObject

OK, so we’ve got the last revision’s manifest, that part’s simple and makes sense. except now, we need to get the status of the working directory, and add in all the other files, because they’re in the “manifest” by being in existence. Oh, and we need to remove any files from the parent’s manifest that don’t exist anymore. Make sense?



417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
# File 'lib/amp/revlogs/changeset.rb', line 417

def manifest
  return @manifest if @manifest
  
  # Start off with the last revision's manifest, that's safe.
  man = parents()[0].manifest.dup
  # Any copied files since the last revision?
  copied = @repo.dirstate.copy_map
  # Any modified, added, etc files since the last revision?
  modified, added, removed  = status[:modified], status[:added], status[:removed]
  deleted, unknown          = status[:deleted], status[:unknown]
  # Merge these discoveries in!
  {:a => added, :m => modified, :u => unknown}.each do |k, list|
    list.each do |file|
      copy_name = (copied[file] || file)
      man[file] = (man.flags[copy_name] || NULL_ID) + k.to_s
      man.flags[file] = @repo.dirstate.flags(file)
    end
  end
  
  # Delete files from the real manifest that don't exist.
  (deleted + removed).each do |file|
    man.delete file if man[file]
  end
  
  man
end

#modifiedObject

What files have changed?



503
# File 'lib/amp/revlogs/changeset.rb', line 503

def modified; status[:modified]; end

#nil?Boolean

Am I nil? never!

Returns:



373
# File 'lib/amp/revlogs/changeset.rb', line 373

def nil?; false; end

#parentsObject

Who is the working directory’s father? Is it Chef? Mr. Garrison? the 1989 denver broncos?

hahaha mike that’s hilarious



403
404
405
406
407
408
409
# File 'lib/amp/revlogs/changeset.rb', line 403

def parents
  return @parents if @parents
  p = @repo.dirstate.parents
  p = [p[0]] if p[1] == NULL_ID
  @parents = p.map {|x| Changeset.new(@repo, x) }
  @parents
end

#removedObject

What files have been removed?



507
# File 'lib/amp/revlogs/changeset.rb', line 507

def removed; status[:removed]; end

#statusObject

What is the status of the working directory? This little method hides quite a bit of work!



382
383
384
# File 'lib/amp/revlogs/changeset.rb', line 382

def status
  @status ||= @repo.status(:unknown => true)
end

#to_sObject

Converts to a string. I’m my first parent, plus a little extra.



367
368
369
# File 'lib/amp/revlogs/changeset.rb', line 367

def to_s
  parents.first.to_s + "+"
end

#unknownObject

What files are hanging out, but untracked?



511
# File 'lib/amp/revlogs/changeset.rb', line 511

def unknown; status[:unknown]; end

#useful_parents(log, revision) ⇒ Object



474
475
476
477
478
479
480
481
482
483
484
# File 'lib/amp/revlogs/changeset.rb', line 474

def useful_parents(log, revision)
  parents = @parents.map {|p| p.revision}
  if parents[1] == -1
    if parents[0] >= @repo.size - 1
      parents = []
    else
      parents = [parents[0]]
    end
  end
  parents
end

#userObject

Who is the user working on me?



388
389
390
# File 'lib/amp/revlogs/changeset.rb', line 388

def user 
  @user ||= @repo.config.username
end

#walk(match, check_ignored = false) ⇒ Array<String>

Recursively walk the directory tree, getting all files that match says are good.

Parameters:

  • match (Amp::Match)

    how to select the files in the tree

  • check_ignored (Boolean) (defaults to: false)

    (false) should we check for ignored files?

Returns:

  • (Array<String>)

    an array of filenames in the tree that match match



493
494
495
496
# File 'lib/amp/revlogs/changeset.rb', line 493

def walk(match, check_ignored = false)
  tree = @repo.dirstate.walk true, check_ignored, match
  tree.keys.sort
end