Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
491332a378 | |||
6c8d403712 |
10
shard.lock
10
shard.lock
|
@ -1,8 +1,8 @@
|
||||||
version: 1.0
|
version: 1.0
|
||||||
shards:
|
shards:
|
||||||
crystal-libgit2:
|
git:
|
||||||
github: puppetpies/crystal-libgit2
|
github: mosop/git
|
||||||
commit: e6992b53f6af9c2bef0f1f4fcb4424ce6ada956b
|
commit: 27cc31b40fc358457b37ab12b2b572c97200755b
|
||||||
|
|
||||||
kemal:
|
kemal:
|
||||||
github: kemalcr/kemal
|
github: kemalcr/kemal
|
||||||
|
@ -20,6 +20,10 @@ shards:
|
||||||
github: luislavena/radix
|
github: luislavena/radix
|
||||||
version: 0.3.8
|
version: 0.3.8
|
||||||
|
|
||||||
|
safec:
|
||||||
|
github: mosop/safec
|
||||||
|
version: 0.2.1
|
||||||
|
|
||||||
slang:
|
slang:
|
||||||
github: jeromegn/slang
|
github: jeromegn/slang
|
||||||
commit: b817c89c7e5ae39562710c0d6c7f42cee685e14f
|
commit: b817c89c7e5ae39562710c0d6c7f42cee685e14f
|
||||||
|
|
|
@ -22,6 +22,6 @@ dependencies:
|
||||||
slang:
|
slang:
|
||||||
github: jeromegn/slang
|
github: jeromegn/slang
|
||||||
branch: master
|
branch: master
|
||||||
crystal-libgit2:
|
git:
|
||||||
github: puppetpies/crystal-libgit2
|
github: mosop/git
|
||||||
branch: master
|
branch: master
|
||||||
|
|
|
@ -1,8 +1,17 @@
|
||||||
require "./options"
|
require "./options"
|
||||||
|
|
||||||
module Wikicr::Git
|
module Wikicr
|
||||||
Dir.mkdir_p Wikicr::OPTIONS.basedir
|
REPO = Git::Repo.open(Wikicr::OPTIONS.basedir)
|
||||||
REPO = Pointer(LibGit2::X_Repository).null
|
|
||||||
# todo: check result
|
extend self
|
||||||
LibGit2.repository_init(REPO, Wikicr::OPTIONS.basedir, 0)
|
|
||||||
|
def repo
|
||||||
|
REPO
|
||||||
end
|
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
|
self.jail user
|
||||||
Dir.mkdir_p self.dirname
|
Dir.mkdir_p self.dirname
|
||||||
File.write self.file, body
|
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
|
end
|
||||||
|
|
||||||
def delete(user : User)
|
def delete(user : User)
|
||||||
|
|
|
@ -23,6 +23,7 @@ class Wikicr::Users
|
||||||
@list = File.read(@file).split("\n")
|
@list = File.read(@file).split("\n")
|
||||||
.select { |line| !line.empty? }
|
.select { |line| !line.empty? }
|
||||||
.map { |line| u = User.new(line); {u.name, u} }.to_h
|
.map { |line| u = User.new(line); {u.name, u} }.to_h
|
||||||
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
# save the users into the file
|
# save the users into the file
|
||||||
|
@ -30,12 +31,14 @@ class Wikicr::Users
|
||||||
File.open(@file, "w") do |fd|
|
File.open(@file, "w") do |fd|
|
||||||
@list.each { |name, user| user.to_s(fd) }
|
@list.each { |name, user| user.to_s(fd) }
|
||||||
end
|
end
|
||||||
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
# add an user to the list
|
# add an user to the list
|
||||||
def add(u : User)
|
def add(u : User)
|
||||||
raise AlreadyExist.new "User #{u.name} already exists" if (@list[u.name]?)
|
raise AlreadyExist.new "User #{u.name} already exists" if (@list[u.name]?)
|
||||||
@list[u.name] = u
|
@list[u.name] = u
|
||||||
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
# remove an user from the list
|
# remove an user from the list
|
||||||
|
@ -48,6 +51,7 @@ class Wikicr::Users
|
||||||
def remove(name : String)
|
def remove(name : String)
|
||||||
raise NotExist.new "User #{name} is not in the list" if (!@list[name]?)
|
raise NotExist.new "User #{name} is not in the list" if (!@list[name]?)
|
||||||
@list.remove(name)
|
@list.remove(name)
|
||||||
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
# replace an entry
|
# replace an entry
|
||||||
|
@ -61,6 +65,7 @@ class Wikicr::Users
|
||||||
else
|
else
|
||||||
@list[u.name] = u
|
@list[u.name] = u
|
||||||
end
|
end
|
||||||
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
# find an user based on its name
|
# find an user based on its name
|
||||||
|
|
|
@ -4,7 +4,7 @@ require "markdown"
|
||||||
require "kemal"
|
require "kemal"
|
||||||
require "kemal-session"
|
require "kemal-session"
|
||||||
require "kilt/slang"
|
require "kilt/slang"
|
||||||
require "crystal-libgit2"
|
require "git"
|
||||||
|
|
||||||
require "./version"
|
require "./version"
|
||||||
require "./lib"
|
require "./lib"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user