Class: Ed::RepositoryCopy

Inherits:
Repository show all
Defined in:
lib/ed/repository_copy.rb

Overview

A RepositoryCopy is a subclass of Repository but with a distinct
difference: it creates a copy of the repository it provides a interface to.

By creating copies, it can allow parallel access to the same repository
because every instance of RepositoryCopy has its own copy of the
repository to work off.

All remote repositories are always instances of RepositoryCopy, and
local repositories can be copied, too. It is recommended to create copies if
you plan to access the same repository in parallel (either from Ed, or
outside Ed).

The default behavior is to create a copy all the time, but it can be
configured from Config.copy_repository=. A RepositoryCopy is cached
per-thread, and lives for the life of a process but for no longer, it is
destroyed when the process exits.

Instance Attribute Summary

Attributes inherited from Repository

#path

Instance Method Summary collapse

Methods inherited from Repository

#checkout, local?, ls_remote, remote?

Constructor Details

#initialize(path) ⇒ Ed::RepositoryCopy

Returns a instance of Ed::RepositoryCopy.

Parameters:

  • path (String, #to_s)

    The URI to a git repository.



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ed/repository_copy.rb', line 29

def initialize path
  @source   = path
  @path     = copy!
  @copy_dir = nil

  parent = Process.pid

  at_exit do
    if parent == Process.pid
      FileUtils.rm_rf(@path.to_s)
    end
  end
end