summaryrefslogtreecommitdiff
path: root/git-mirror-cgit
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2016-12-15 04:36:19 -0500
committerLuke Shumaker <lukeshu@sbcglobal.net>2016-12-15 04:36:19 -0500
commit381a9b85d4ea82c5792fcc75383b2d0d98b72100 (patch)
tree182f7421375f771c210405e8586674b2a9f31c06 /git-mirror-cgit
parent445d6d320e75917eb6678648b1571be97cf3dcd9 (diff)
more
Diffstat (limited to 'git-mirror-cgit')
-rwxr-xr-xgit-mirror-cgit69
1 files changed, 69 insertions, 0 deletions
diff --git a/git-mirror-cgit b/git-mirror-cgit
new file mode 100755
index 0000000..8c1b799
--- /dev/null
+++ b/git-mirror-cgit
@@ -0,0 +1,69 @@
+#!/usr/bin/env ruby
+# coding: utf-8
+
+load 'git-mirror-backend.rb'
+require 'uri'
+require 'open-uri'
+require 'nokogiri'
+
+class Cgit < GitMirrorBackend
+ def initialize()
+ @config = {}
+ end
+
+ def cmd_config(*args)
+ args.each do |arg|
+ key, val = arg.split('=', 2)
+ case key
+ when "url"
+ val = URI(val)
+ unless val.path.end_with?("/")
+ val.path += "/"
+ end
+ end
+ @config[key] = val
+ end
+ end
+
+ def cmd_get_meta(path)
+ doc = Nokogiri::HTML(open(@config[url]+path))
+ head = open(@config[url]+path+'/HEAD').read
+ return {
+ 'description' => doc.css('#header .sub')[0].text,
+ 'owner' => doc.css('#header .sub')[1].text,
+ 'default_branch' => head.split("\n")[0].sub(/^ref: /, '').sub(/^refs\/heads\//, ''),
+ }
+ end
+
+ def cmd_set_meta(path, *pairs)
+ raise "no can do"
+ end
+
+ def urls(path)
+ doc = Nokogiri::HTML(open(@config[url]+path))
+ return doc.css('a[rel="vcs-git"]').map{|a| a['href']}
+ end
+
+ def cmd_push_url(path)
+ prefs = ['ssh', 'https', 'http', 'git']
+ return self.urls.sort_by{|url| prefs.index(url)}
+ end
+
+ def cmd_pull_url(path)
+ # prefer https ahead of git because of a bug in git-daemon
+ # with '~'.
+ prefs = ['https', 'git', 'http', 'ssh']
+ return self.urls.sort_by{|url| prefs.index(url)}
+ end
+
+ def cmd_repo_mode(path)
+ return "passive"
+ end
+end
+
+if __FILE__ == $0
+ if ARGV.length != 1
+ throw "Usage: $0 ACCOUNT_NAME"
+ end
+ Cgit.new().repl(ARGV[1])
+end