# File lib/perforce.rb, line 32
  def initialize(spec = {})
    #
    # Remove PWD during creation to avoid some troubles.  The user
    # probably wants perforce to use the absolute path of the current
    # directory, not a path infected by symlinks.
    # 
    # Since ~/project was a symlink to my perforce-based project,
    # perforce would not run when I got there via "cd project" from my
    # home directory.
    #
    @p4 = 
      if self.class.use_pwd_symlinks
        P4.new
      else
        Thread.exclusive {
          previous_pwd = ENV["PWD"]
          ENV.delete("PWD")
          begin
            P4.new
          ensure
            if previous_pwd
              ENV["PWD"] = previous_pwd
            end
          end
        }
      end
    spec.each_pair { |key, value|
      @p4.send("#{key}=", value)
    }
    unless spec.has_key?(:user)
      # guess user
      @p4.user = [
        ENV["USER"],
        ENV["USERNAME"],
      ].select { |name|
        name != nil and name != ""
      }.first.tap { |user|
        unless user 
          raise "Could not determine username"
        end
      }
    end
    @p4.exception_level = P4::RAISE_ERRORS
    @p4.connect
  end