Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
491332a378 | |||
6c8d403712 |
10
shard.lock
10
shard.lock
|
@ -1,8 +1,8 @@
|
|||
version: 1.0
|
||||
shards:
|
||||
crystal-libgit2:
|
||||
github: puppetpies/crystal-libgit2
|
||||
commit: e6992b53f6af9c2bef0f1f4fcb4424ce6ada956b
|
||||
git:
|
||||
github: mosop/git
|
||||
commit: 27cc31b40fc358457b37ab12b2b572c97200755b
|
||||
|
||||
kemal:
|
||||
github: kemalcr/kemal
|
||||
|
@ -20,6 +20,10 @@ shards:
|
|||
github: luislavena/radix
|
||||
version: 0.3.8
|
||||
|
||||
safec:
|
||||
github: mosop/safec
|
||||
version: 0.2.1
|
||||
|
||||
slang:
|
||||
github: jeromegn/slang
|
||||
commit: b817c89c7e5ae39562710c0d6c7f42cee685e14f
|
||||
|
|
|
@ -22,6 +22,6 @@ dependencies:
|
|||
slang:
|
||||
github: jeromegn/slang
|
||||
branch: master
|
||||
crystal-libgit2:
|
||||
github: puppetpies/crystal-libgit2
|
||||
git:
|
||||
github: mosop/git
|
||||
branch: master
|
||||
|
|
|
@ -1,8 +1,17 @@
|
|||
require "./options"
|
||||
|
||||
module Wikicr::Git
|
||||
Dir.mkdir_p Wikicr::OPTIONS.basedir
|
||||
REPO = Pointer(LibGit2::X_Repository).null
|
||||
# todo: check result
|
||||
LibGit2.repository_init(REPO, Wikicr::OPTIONS.basedir, 0)
|
||||
module Wikicr
|
||||
REPO = Git::Repo.open(Wikicr::OPTIONS.basedir)
|
||||
|
||||
extend self
|
||||
|
||||
def repo
|
||||
REPO
|
||||
end
|
||||
|
||||
def init!
|
||||
end
|
||||
end
|
||||
|
||||
require "./users"
|
||||
Wikicr::Page.new("testX").write("OK", Wikicr::USERS.read!.find("arthur"))
|
||||
|
|
|
@ -64,6 +64,36 @@ struct Wikicr::Page
|
|||
self.jail user
|
||||
Dir.mkdir_p self.dirname
|
||||
File.write self.file, body
|
||||
commit!(user)
|
||||
end
|
||||
|
||||
private def commit!(user)
|
||||
puts "--------------- COMMIT ! ------------"
|
||||
# You can check git_repository_head_unborn() to see if HEAD points at a reference or not.
|
||||
tree_id = Pointer(Git::C::Oid).null
|
||||
parent_id = Pointer(Git::C::Oid).null
|
||||
commit_id = Pointer(Git::C::Oid).null
|
||||
tree = nil.as(Git::C::X_Tree)
|
||||
parent = nil.as(Git::C::X_Commit)
|
||||
index = nil.as(Git::C::X_Index)
|
||||
puts "repository_index"
|
||||
puts Git::C.repository_index(pointerof(index), Wikicr.repo.safe)
|
||||
pp index, index.address, index.value
|
||||
puts "index_write_tree"
|
||||
puts Git::C.index_write_tree(tree.as(Pointer(Git::C::Oid)), index)
|
||||
pp tree
|
||||
|
||||
puts "reference_name_to_id"
|
||||
puts Git::C.reference_name_to_id(parent_id, Wikicr.repo.safe, "HEAD")
|
||||
puts "commit_lookup"
|
||||
puts Git::C.commit_lookup(pointerof(parent), Wikicr.repo.safe, parent_id)
|
||||
|
||||
sign = Pointer(Git::C::Signature).null
|
||||
puts "signature_now"
|
||||
puts Git::C.signature_now(pointerof(sign), user.name, "#{user.name}@localhost")
|
||||
|
||||
puts "commit_create"
|
||||
puts Git::C.commit_create(commit_id, Wikicr.repo.safe, "HEAD", sign, sign, "UTF-8", "update #{self.name}", tree.value, 1, pointerof(parent))
|
||||
end
|
||||
|
||||
def delete(user : User)
|
||||
|
|
|
@ -23,6 +23,7 @@ class Wikicr::Users
|
|||
@list = File.read(@file).split("\n")
|
||||
.select { |line| !line.empty? }
|
||||
.map { |line| u = User.new(line); {u.name, u} }.to_h
|
||||
self
|
||||
end
|
||||
|
||||
# save the users into the file
|
||||
|
@ -30,12 +31,14 @@ class Wikicr::Users
|
|||
File.open(@file, "w") do |fd|
|
||||
@list.each { |name, user| user.to_s(fd) }
|
||||
end
|
||||
self
|
||||
end
|
||||
|
||||
# add an user to the list
|
||||
def add(u : User)
|
||||
raise AlreadyExist.new "User #{u.name} already exists" if (@list[u.name]?)
|
||||
@list[u.name] = u
|
||||
self
|
||||
end
|
||||
|
||||
# remove an user from the list
|
||||
|
@ -48,6 +51,7 @@ class Wikicr::Users
|
|||
def remove(name : String)
|
||||
raise NotExist.new "User #{name} is not in the list" if (!@list[name]?)
|
||||
@list.remove(name)
|
||||
self
|
||||
end
|
||||
|
||||
# replace an entry
|
||||
|
@ -61,6 +65,7 @@ class Wikicr::Users
|
|||
else
|
||||
@list[u.name] = u
|
||||
end
|
||||
self
|
||||
end
|
||||
|
||||
# find an user based on its name
|
||||
|
|
|
@ -4,7 +4,7 @@ require "markdown"
|
|||
require "kemal"
|
||||
require "kemal-session"
|
||||
require "kilt/slang"
|
||||
require "crystal-libgit2"
|
||||
require "git"
|
||||
|
||||
require "./version"
|
||||
require "./lib"
|
||||
|
|
Loading…
Reference in New Issue
Block a user