Class: Vlad::Perforce

Inherits:
Object
  • Object
show all
Defined in:
lib/vlad/perforce.rb

Instance Method Summary collapse

Instance Method Details

#checkout(revision, destination) ⇒ Object

Returns the p4 command that will checkout revision into the directory destination.



10
11
12
# File 'lib/vlad/perforce.rb', line 10

def checkout(revision, destination)
  "#{p4_cmd} sync ...#{rev_no(revision)}"
end

#export(revision_or_source, destination) ⇒ Object

Returns the p4 command that will export revision into the directory directory.



18
19
20
21
22
23
24
# File 'lib/vlad/perforce.rb', line 18

def export(revision_or_source, destination)
  if revision_or_source =~ /^(\d+|head)$/i then
    "(cd #{destination} && #{p4_cmd} sync ...#{rev_no(revision_or_source)})"
  else
    "cp -r #{revision_or_source} #{destination}"
  end
end

#rev_no(revision) ⇒ Object

Maps revision revision into a Perforce revision.



37
38
39
40
41
42
43
44
45
46
# File 'lib/vlad/perforce.rb', line 37

def rev_no(revision)
  case revision.to_s
  when /head/i then
    "#head"
  when /^\d+$/ then
    "@#{revision}"
  else
    revision
  end
end

#revision(revision) ⇒ Object

Returns a command that maps human-friendly revision identifier revision into a Perforce revision specification.



30
31
32
# File 'lib/vlad/perforce.rb', line 30

def revision(revision)
  "`#{p4_cmd} changes -s submitted -m 1 ...#{rev_no(revision)} | cut -f 2 -d\\ `"
end