Class: Gifts::CommitTable

Inherits:
TableBase show all
Defined in:
lib/gifts/commit_table.rb

Constant Summary collapse

StatusProcessing =
0
StatusCompleted =
1
StatusTimeout =
2

Instance Method Summary collapse

Methods inherited from TableBase

#initialize

Constructor Details

This class inherits a constructor from Gifts::TableBase

Instance Method Details

#add(git_repo, db_repo) ⇒ Object



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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/gifts/commit_table.rb', line 26

def add(git_repo, db_repo)
  result = []

  offset = 0
  count = 100
  processed_prev_commit = false

  begin
    commits = Grit::Commit.find_all(git_repo, nil, { all: true, date_order: true, max_count: count, skip: offset })
    commits.each do |git_commit|
      key = db_repo.id.to_s + ":" + git_commit.id

      if key == db_repo.last_commit_key
        processed_prev_commit = true
        break

      else
        author = @db.users.add(git_commit.author.name)
        committer = @db.users.add(git_commit.committer.name)

        db_commit =
          table[key] ||
          table.add(
            key,
            author: author,
            authored_date: git_commit.authored_date,
            committer: committer,
            committed_date: git_commit.committed_date,
            message: git_commit.message,
            repo: db_repo,
            rev: git_commit.id,
            status: StatusProcessing
          )

          db_diffs = @db.diffs.add(git_commit, db_commit)
          result << db_commit
      end
    end
    offset += count
  end until commits.count == 0 || processed_prev_commit

  result
end

#define_schemaObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/gifts/commit_table.rb', line 11

def define_schema
  Groonga::Schema.define do |schema|
    schema.create_table(table_name, type: :hash) do |table|
      table.reference("author", "user")
      table.time("authored_date")
      table.reference("committer", "user")
      table.time("committed_date")
      table.string("message")
      table.reference("repo")
      table.string("rev")
      table.int32("status")
    end
  end
end

#table_nameObject



7
8
9
# File 'lib/gifts/commit_table.rb', line 7

def table_name
  "commit"
end