Class: GitDB::Commands::UploadPack

Inherits:
Object
  • Object
show all
Defined in:
lib/git-db/commands/upload-pack.rb

Instance Method Summary collapse

Instance Method Details

#execute(args) ⇒ Object

Raises:

  • (ArgumentError)

6
7
8
9
10
11
12
13
14
# File 'lib/git-db/commands/upload-pack.rb', line 6

def execute(args)
  repository = args.first
  raise ArgumentError, "repository required" unless repository

  database = GitDB.database(repository)

  #execute_transcript(database)
  execute_real(database)
end

#execute_real(database) ⇒ Object


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/git-db/commands/upload-pack.rb', line 43

def execute_real(database)
  write_ref 'HEAD', database.get_ref('refs/heads/master')['sha']

  database.get_refs.each do |ref, sha|
    write_ref(ref, sha)
  end
  io.write_eof

  shas_to_read   = []
  shas_to_ignore = []

  while (data = io.read_command)
    GitDB.log("GOT COMMAND: #{data.inspect}")
    command, sha, options = data.split(' ', 3)
    shas_to_read << sha
  end

  while (data = io.read_command)
    data = data.strip
    break if data == 'done'
    command, sha = data.split(" ", 2)
    case command
      when 'have' then 
        shas_to_ignore << sha
      else
        raise "Unknown SHA command: #{command}"
    end
  end

  if shas_to_ignore.length.zero?
    io.write_command("NAK\n")
  else
    io.write_command("ACK #{shas_to_ignore.last}\n")
  end

  shas_to_ignore, _ = load_entries(database, shas_to_ignore, false)
  shas, entries     = load_entries(database, shas_to_read, true, shas_to_ignore)

  GitDB.log(entries.map { |e| e.inspect })

  io.write_pack(entries)
end

#execute_transcript(database) ⇒ Object


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/git-db/commands/upload-pack.rb', line 16

def execute_transcript(database)
  cmd = GitDB::Protocol.new(IO.popen("/opt/local/bin/git-upload-pack '/tmp/foo'", 'r+'))

  while (data = cmd.read_command)
    GitDB.log("CMD COMMAND: #{data}")
    io.write_command(data)
  end
  io.write_eof

  while (data = io.read_command)
    GitDB.log("IO COMMAND: #{data}")
    cmd.write_command(data)
  end
  cmd.write_eof

  while (data = io.read_command)
    cmd.write_command(data)
    data = data.strip
    break if data == 'done'
    GitDB.log("READ FROM IO #{data}")
  end
  
  while (data = cmd.read_command)
    GitDB.log("GOT COMMAND DATA: #{data.inspect}")
  end
end