Class: GitDB::Commands::ReceivePack

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

Instance Method Summary collapse

Instance Method Details

#execute(args) ⇒ Object

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
13
14
15
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
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/git-db/commands/receive-pack.rb', line 6

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

  database = GitDB.database(repository)

  needs_capabilities = true
  database.get_refs.each do |ref, sha|
    GitDB.log("ISAERF #{ref} #{sha}")
    write_ref(ref, sha, needs_capabilities)
    needs_capabilities = false
  end
  write_ref("capabilities^{}", GitDB.null_sha1) if needs_capabilities
  io.write_eof

  refs = []
  new_shas = []

  while (data = io.read_command)
    old_sha, new_sha, ref = data.split(' ')
    ref, report = ref.split(0.chr)

    refs << ref
    new_shas << new_sha

    if new_sha == GitDB.null_sha1
      database.delete_ref(ref)
    else
      database.write_ref(ref, new_sha)
    end
  end

  unless new_shas.reject { |sha| sha == GitDB.null_sha1 }.length.zero?
    while (entries = io.read_pack)

      # bulk in 50 at a time
      while (page = entries.shift(50)).length > 0
        database.write_objects(page)
      end
    end
  end

  io.write_command("unpack ok\n")
  refs.each do |ref|
    io.write_command("ok #{ref}\n")
  end
  io.write_eof
end