Class: Amp::WorkingDirectoryChangeset
- 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
Instance Method Summary collapse
-
#added ⇒ Object
What files have we added?.
-
#branch ⇒ Object
What branch are we in?.
-
#children ⇒ Object
No children.
-
#clean ⇒ Object
What files are pristine since the last revision?.
-
#date ⇒ Object
Well, I guess the working directory’s date is…
-
#deleted ⇒ Object
What files have been deleted (but not officially)?.
-
#description ⇒ Object
If there’s a description, ok then.
-
#extra ⇒ Object
Any other extra data? i’d like to hear it.
-
#files ⇒ Object
Files affected in this transaction: modified, added, removed.
-
#flags(path) ⇒ String
Gets the flags for the file at current state in time.
-
#get_file(path, file_log = nil) ⇒ Amp::VersionedWorkingFile
Returns a VersionedWorkingFile to represent the file at the given point in time.
-
#include?(key) ⇒ Boolean
Do I include a given file? (not sure this is ever used yet).
-
#initialize(repo, opts = {:text => ""}) ⇒ WorkingDirectoryChangeset
constructor
A new instance of WorkingDirectoryChangeset.
-
#manifest ⇒ Object
OK, so we’ve got the last revision’s manifest, that part’s simple and makes sense.
-
#modified ⇒ Object
What files have changed?.
-
#nil? ⇒ Boolean
Am I nil? never!.
-
#parents ⇒ Object
Who is the working directory’s father? Is it Chef? Mr.
-
#removed ⇒ Object
What files have been removed?.
-
#status ⇒ Object
What is the status of the working directory? This little method hides quite a bit of work!.
-
#to_s ⇒ Object
Converts to a string.
-
#unknown ⇒ Object
What files are hanging out, but untracked?.
- #useful_parents(log, revision) ⇒ Object
-
#user ⇒ Object
Who is the user working on me?.
-
#walk(match, check_ignored = false) ⇒ Array<String>
Recursively walk the directory tree, getting all files that
match
says are good.
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
Methods included from RevlogSupport::Node
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
#added ⇒ Object
What files have we added?
505 |
# File 'lib/amp/revlogs/changeset.rb', line 505 def added; status[:added]; end |
#branch ⇒ Object
What branch are we in?
515 |
# File 'lib/amp/revlogs/changeset.rb', line 515 def branch; @extra["branch"]; end |
#children ⇒ Object
No children. Returns the empty array.
519 |
# File 'lib/amp/revlogs/changeset.rb', line 519 def children; []; end |
#clean ⇒ Object
What files are pristine since the last revision?
513 |
# File 'lib/amp/revlogs/changeset.rb', line 513 def clean; status[:normal]; end |
#date ⇒ Object
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 |
#deleted ⇒ Object
What files have been deleted (but not officially)?
509 |
# File 'lib/amp/revlogs/changeset.rb', line 509 def deleted; status[:deleted]; end |
#description ⇒ Object
If there’s a description, ok then
499 |
# File 'lib/amp/revlogs/changeset.rb', line 499 def description; @text; end |
#extra ⇒ Object
Any other extra data? i’d like to hear it
517 |
# File 'lib/amp/revlogs/changeset.rb', line 517 def extra; @extra; end |
#files ⇒ Object
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
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.
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)
377 |
# File 'lib/amp/revlogs/changeset.rb', line 377 def include?(key); "?r".include?(@repo.dirstate[key].status.to_hg_letter); end |
#manifest ⇒ Object
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 |
#modified ⇒ Object
What files have changed?
503 |
# File 'lib/amp/revlogs/changeset.rb', line 503 def modified; status[:modified]; end |
#nil? ⇒ Boolean
Am I nil? never!
373 |
# File 'lib/amp/revlogs/changeset.rb', line 373 def nil?; false; end |
#parents ⇒ Object
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 |
#removed ⇒ Object
What files have been removed?
507 |
# File 'lib/amp/revlogs/changeset.rb', line 507 def removed; status[:removed]; end |
#status ⇒ Object
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_s ⇒ Object
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 |
#unknown ⇒ Object
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 |
#user ⇒ Object
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.
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 |