From e33d9e77f43e6829ea967e47964d13f5a8aec5cc Mon Sep 17 00:00:00 2001 From: Unknwon Date: Sun, 27 May 2018 09:07:15 +0800 Subject: vendor: rename "gogits" to "gogs" --- vendor/github.com/gogits/chardet/2022.go | 102 --- vendor/github.com/gogits/chardet/AUTHORS | 1 - vendor/github.com/gogits/chardet/LICENSE | 22 - vendor/github.com/gogits/chardet/README.md | 12 - vendor/github.com/gogits/chardet/detector.go | 136 ---- vendor/github.com/gogits/chardet/icu-license.html | 51 -- vendor/github.com/gogits/chardet/multi_byte.go | 345 -------- vendor/github.com/gogits/chardet/recognizer.go | 83 -- vendor/github.com/gogits/chardet/single_byte.go | 882 --------------------- vendor/github.com/gogits/chardet/unicode.go | 103 --- vendor/github.com/gogits/chardet/utf8.go | 71 -- vendor/github.com/gogits/cron/LICENSE | 21 - vendor/github.com/gogits/cron/README.md | 2 - vendor/github.com/gogits/cron/constantdelay.go | 27 - vendor/github.com/gogits/cron/cron.go | 243 ------ vendor/github.com/gogits/cron/doc.go | 129 --- vendor/github.com/gogits/cron/parser.go | 234 ------ vendor/github.com/gogits/cron/spec.go | 159 ---- vendor/github.com/gogits/git-module/LICENSE | 19 - vendor/github.com/gogits/git-module/README.md | 13 - vendor/github.com/gogits/git-module/blob.go | 35 - vendor/github.com/gogits/git-module/command.go | 150 ---- vendor/github.com/gogits/git-module/commit.go | 310 -------- .../github.com/gogits/git-module/commit_archive.go | 33 - vendor/github.com/gogits/git-module/error.go | 61 -- vendor/github.com/gogits/git-module/git.go | 80 -- vendor/github.com/gogits/git-module/hook.go | 111 --- vendor/github.com/gogits/git-module/repo.go | 295 ------- vendor/github.com/gogits/git-module/repo_branch.go | 126 --- vendor/github.com/gogits/git-module/repo_commit.go | 381 --------- vendor/github.com/gogits/git-module/repo_diff.go | 400 ---------- vendor/github.com/gogits/git-module/repo_hook.go | 13 - vendor/github.com/gogits/git-module/repo_object.go | 14 - vendor/github.com/gogits/git-module/repo_pull.go | 81 -- vendor/github.com/gogits/git-module/repo_tag.go | 209 ----- vendor/github.com/gogits/git-module/repo_tree.go | 26 - vendor/github.com/gogits/git-module/sha1.go | 93 --- vendor/github.com/gogits/git-module/signature.go | 48 -- vendor/github.com/gogits/git-module/submodule.go | 78 -- vendor/github.com/gogits/git-module/tag.go | 65 -- vendor/github.com/gogits/git-module/tree.go | 149 ---- vendor/github.com/gogits/git-module/tree_blob.go | 57 -- vendor/github.com/gogits/git-module/tree_entry.go | 226 ------ vendor/github.com/gogits/git-module/utils.go | 93 --- vendor/github.com/gogits/go-gogs-client/LICENSE | 22 - vendor/github.com/gogits/go-gogs-client/README.md | 8 - .../github.com/gogits/go-gogs-client/admin_org.go | 21 - .../github.com/gogits/go-gogs-client/admin_repo.go | 21 - .../github.com/gogits/go-gogs-client/admin_user.go | 68 -- vendor/github.com/gogits/go-gogs-client/gogs.go | 90 --- vendor/github.com/gogits/go-gogs-client/issue.go | 103 --- .../gogits/go-gogs-client/issue_comment.go | 70 -- .../gogits/go-gogs-client/issue_label.go | 99 --- .../gogits/go-gogs-client/issue_milestone.go | 69 -- .../gogits/go-gogs-client/miscellaneous.go | 11 - vendor/github.com/gogits/go-gogs-client/org.go | 60 -- .../github.com/gogits/go-gogs-client/org_member.go | 24 - .../github.com/gogits/go-gogs-client/org_team.go | 18 - vendor/github.com/gogits/go-gogs-client/pull.go | 37 - vendor/github.com/gogits/go-gogs-client/release.go | 22 - vendor/github.com/gogits/go-gogs-client/repo.go | 129 --- .../gogits/go-gogs-client/repo_branch.go | 25 - .../gogits/go-gogs-client/repo_collaborator.go | 44 - .../github.com/gogits/go-gogs-client/repo_file.go | 15 - .../github.com/gogits/go-gogs-client/repo_hook.go | 344 -------- .../github.com/gogits/go-gogs-client/repo_key.go | 50 -- vendor/github.com/gogits/go-gogs-client/user.go | 36 - .../github.com/gogits/go-gogs-client/user_app.go | 46 -- .../github.com/gogits/go-gogs-client/user_email.go | 43 - .../gogits/go-gogs-client/user_follow.go | 47 -- .../github.com/gogits/go-gogs-client/user_key.go | 49 -- vendor/github.com/gogits/go-gogs-client/utils.go | 23 - vendor/github.com/gogits/go-libravatar/LICENSE | 19 - vendor/github.com/gogits/go-libravatar/Makefile | 12 - vendor/github.com/gogits/go-libravatar/README.md | 28 - .../github.com/gogits/go-libravatar/libravatar.go | 300 ------- vendor/github.com/gogits/minwinsvc/LICENSE | 20 - vendor/github.com/gogits/minwinsvc/README.md | 18 - vendor/github.com/gogits/minwinsvc/minwinsvc.go | 18 - vendor/github.com/gogits/minwinsvc/svc_other.go | 11 - vendor/github.com/gogits/minwinsvc/svc_windows.go | 72 -- vendor/github.com/gogs/chardet/2022.go | 102 +++ vendor/github.com/gogs/chardet/AUTHORS | 1 + vendor/github.com/gogs/chardet/LICENSE | 22 + vendor/github.com/gogs/chardet/README.md | 12 + vendor/github.com/gogs/chardet/detector.go | 136 ++++ vendor/github.com/gogs/chardet/icu-license.html | 51 ++ vendor/github.com/gogs/chardet/multi_byte.go | 345 ++++++++ vendor/github.com/gogs/chardet/recognizer.go | 83 ++ vendor/github.com/gogs/chardet/single_byte.go | 882 +++++++++++++++++++++ vendor/github.com/gogs/chardet/unicode.go | 103 +++ vendor/github.com/gogs/chardet/utf8.go | 71 ++ vendor/github.com/gogs/cron/LICENSE | 21 + vendor/github.com/gogs/cron/README.md | 2 + vendor/github.com/gogs/cron/constantdelay.go | 27 + vendor/github.com/gogs/cron/cron.go | 243 ++++++ vendor/github.com/gogs/cron/doc.go | 129 +++ vendor/github.com/gogs/cron/parser.go | 234 ++++++ vendor/github.com/gogs/cron/spec.go | 159 ++++ vendor/github.com/gogs/git-module/LICENSE | 19 + vendor/github.com/gogs/git-module/README.md | 13 + vendor/github.com/gogs/git-module/blob.go | 35 + vendor/github.com/gogs/git-module/command.go | 150 ++++ vendor/github.com/gogs/git-module/commit.go | 310 ++++++++ .../github.com/gogs/git-module/commit_archive.go | 33 + vendor/github.com/gogs/git-module/error.go | 61 ++ vendor/github.com/gogs/git-module/git.go | 80 ++ vendor/github.com/gogs/git-module/hook.go | 111 +++ vendor/github.com/gogs/git-module/repo.go | 295 +++++++ vendor/github.com/gogs/git-module/repo_branch.go | 126 +++ vendor/github.com/gogs/git-module/repo_commit.go | 381 +++++++++ vendor/github.com/gogs/git-module/repo_diff.go | 400 ++++++++++ vendor/github.com/gogs/git-module/repo_hook.go | 13 + vendor/github.com/gogs/git-module/repo_object.go | 14 + vendor/github.com/gogs/git-module/repo_pull.go | 81 ++ vendor/github.com/gogs/git-module/repo_tag.go | 209 +++++ vendor/github.com/gogs/git-module/repo_tree.go | 26 + vendor/github.com/gogs/git-module/sha1.go | 93 +++ vendor/github.com/gogs/git-module/signature.go | 48 ++ vendor/github.com/gogs/git-module/submodule.go | 78 ++ vendor/github.com/gogs/git-module/tag.go | 65 ++ vendor/github.com/gogs/git-module/tree.go | 149 ++++ vendor/github.com/gogs/git-module/tree_blob.go | 57 ++ vendor/github.com/gogs/git-module/tree_entry.go | 226 ++++++ vendor/github.com/gogs/git-module/utils.go | 93 +++ vendor/github.com/gogs/go-gogs-client/LICENSE | 22 + vendor/github.com/gogs/go-gogs-client/README.md | 8 + vendor/github.com/gogs/go-gogs-client/admin_org.go | 21 + .../github.com/gogs/go-gogs-client/admin_repo.go | 21 + .../github.com/gogs/go-gogs-client/admin_user.go | 68 ++ vendor/github.com/gogs/go-gogs-client/gogs.go | 90 +++ vendor/github.com/gogs/go-gogs-client/issue.go | 103 +++ .../gogs/go-gogs-client/issue_comment.go | 70 ++ .../github.com/gogs/go-gogs-client/issue_label.go | 99 +++ .../gogs/go-gogs-client/issue_milestone.go | 69 ++ .../gogs/go-gogs-client/miscellaneous.go | 11 + vendor/github.com/gogs/go-gogs-client/org.go | 60 ++ .../github.com/gogs/go-gogs-client/org_member.go | 24 + vendor/github.com/gogs/go-gogs-client/org_team.go | 18 + vendor/github.com/gogs/go-gogs-client/pull.go | 37 + vendor/github.com/gogs/go-gogs-client/release.go | 22 + vendor/github.com/gogs/go-gogs-client/repo.go | 129 +++ .../github.com/gogs/go-gogs-client/repo_branch.go | 25 + .../gogs/go-gogs-client/repo_collaborator.go | 44 + vendor/github.com/gogs/go-gogs-client/repo_file.go | 15 + vendor/github.com/gogs/go-gogs-client/repo_hook.go | 344 ++++++++ vendor/github.com/gogs/go-gogs-client/repo_key.go | 50 ++ vendor/github.com/gogs/go-gogs-client/user.go | 36 + vendor/github.com/gogs/go-gogs-client/user_app.go | 46 ++ .../github.com/gogs/go-gogs-client/user_email.go | 43 + .../github.com/gogs/go-gogs-client/user_follow.go | 47 ++ vendor/github.com/gogs/go-gogs-client/user_key.go | 49 ++ vendor/github.com/gogs/go-gogs-client/utils.go | 23 + vendor/github.com/gogs/go-libravatar/LICENSE | 19 + vendor/github.com/gogs/go-libravatar/Makefile | 12 + vendor/github.com/gogs/go-libravatar/README.md | 28 + vendor/github.com/gogs/go-libravatar/libravatar.go | 300 +++++++ vendor/github.com/gogs/minwinsvc/LICENSE | 20 + vendor/github.com/gogs/minwinsvc/README.md | 18 + vendor/github.com/gogs/minwinsvc/minwinsvc.go | 18 + vendor/github.com/gogs/minwinsvc/svc_other.go | 11 + vendor/github.com/gogs/minwinsvc/svc_windows.go | 72 ++ 162 files changed, 7881 insertions(+), 7881 deletions(-) delete mode 100644 vendor/github.com/gogits/chardet/2022.go delete mode 100644 vendor/github.com/gogits/chardet/AUTHORS delete mode 100644 vendor/github.com/gogits/chardet/LICENSE delete mode 100644 vendor/github.com/gogits/chardet/README.md delete mode 100644 vendor/github.com/gogits/chardet/detector.go delete mode 100644 vendor/github.com/gogits/chardet/icu-license.html delete mode 100644 vendor/github.com/gogits/chardet/multi_byte.go delete mode 100644 vendor/github.com/gogits/chardet/recognizer.go delete mode 100644 vendor/github.com/gogits/chardet/single_byte.go delete mode 100644 vendor/github.com/gogits/chardet/unicode.go delete mode 100644 vendor/github.com/gogits/chardet/utf8.go delete mode 100644 vendor/github.com/gogits/cron/LICENSE delete mode 100644 vendor/github.com/gogits/cron/README.md delete mode 100644 vendor/github.com/gogits/cron/constantdelay.go delete mode 100644 vendor/github.com/gogits/cron/cron.go delete mode 100644 vendor/github.com/gogits/cron/doc.go delete mode 100644 vendor/github.com/gogits/cron/parser.go delete mode 100644 vendor/github.com/gogits/cron/spec.go delete mode 100644 vendor/github.com/gogits/git-module/LICENSE delete mode 100644 vendor/github.com/gogits/git-module/README.md delete mode 100644 vendor/github.com/gogits/git-module/blob.go delete mode 100644 vendor/github.com/gogits/git-module/command.go delete mode 100644 vendor/github.com/gogits/git-module/commit.go delete mode 100644 vendor/github.com/gogits/git-module/commit_archive.go delete mode 100644 vendor/github.com/gogits/git-module/error.go delete mode 100644 vendor/github.com/gogits/git-module/git.go delete mode 100644 vendor/github.com/gogits/git-module/hook.go delete mode 100644 vendor/github.com/gogits/git-module/repo.go delete mode 100644 vendor/github.com/gogits/git-module/repo_branch.go delete mode 100644 vendor/github.com/gogits/git-module/repo_commit.go delete mode 100644 vendor/github.com/gogits/git-module/repo_diff.go delete mode 100644 vendor/github.com/gogits/git-module/repo_hook.go delete mode 100644 vendor/github.com/gogits/git-module/repo_object.go delete mode 100644 vendor/github.com/gogits/git-module/repo_pull.go delete mode 100644 vendor/github.com/gogits/git-module/repo_tag.go delete mode 100644 vendor/github.com/gogits/git-module/repo_tree.go delete mode 100644 vendor/github.com/gogits/git-module/sha1.go delete mode 100644 vendor/github.com/gogits/git-module/signature.go delete mode 100644 vendor/github.com/gogits/git-module/submodule.go delete mode 100644 vendor/github.com/gogits/git-module/tag.go delete mode 100644 vendor/github.com/gogits/git-module/tree.go delete mode 100644 vendor/github.com/gogits/git-module/tree_blob.go delete mode 100644 vendor/github.com/gogits/git-module/tree_entry.go delete mode 100644 vendor/github.com/gogits/git-module/utils.go delete mode 100644 vendor/github.com/gogits/go-gogs-client/LICENSE delete mode 100644 vendor/github.com/gogits/go-gogs-client/README.md delete mode 100644 vendor/github.com/gogits/go-gogs-client/admin_org.go delete mode 100644 vendor/github.com/gogits/go-gogs-client/admin_repo.go delete mode 100644 vendor/github.com/gogits/go-gogs-client/admin_user.go delete mode 100644 vendor/github.com/gogits/go-gogs-client/gogs.go delete mode 100644 vendor/github.com/gogits/go-gogs-client/issue.go delete mode 100644 vendor/github.com/gogits/go-gogs-client/issue_comment.go delete mode 100644 vendor/github.com/gogits/go-gogs-client/issue_label.go delete mode 100644 vendor/github.com/gogits/go-gogs-client/issue_milestone.go delete mode 100644 vendor/github.com/gogits/go-gogs-client/miscellaneous.go delete mode 100644 vendor/github.com/gogits/go-gogs-client/org.go delete mode 100644 vendor/github.com/gogits/go-gogs-client/org_member.go delete mode 100644 vendor/github.com/gogits/go-gogs-client/org_team.go delete mode 100644 vendor/github.com/gogits/go-gogs-client/pull.go delete mode 100644 vendor/github.com/gogits/go-gogs-client/release.go delete mode 100644 vendor/github.com/gogits/go-gogs-client/repo.go delete mode 100644 vendor/github.com/gogits/go-gogs-client/repo_branch.go delete mode 100644 vendor/github.com/gogits/go-gogs-client/repo_collaborator.go delete mode 100644 vendor/github.com/gogits/go-gogs-client/repo_file.go delete mode 100644 vendor/github.com/gogits/go-gogs-client/repo_hook.go delete mode 100644 vendor/github.com/gogits/go-gogs-client/repo_key.go delete mode 100644 vendor/github.com/gogits/go-gogs-client/user.go delete mode 100644 vendor/github.com/gogits/go-gogs-client/user_app.go delete mode 100644 vendor/github.com/gogits/go-gogs-client/user_email.go delete mode 100644 vendor/github.com/gogits/go-gogs-client/user_follow.go delete mode 100644 vendor/github.com/gogits/go-gogs-client/user_key.go delete mode 100644 vendor/github.com/gogits/go-gogs-client/utils.go delete mode 100644 vendor/github.com/gogits/go-libravatar/LICENSE delete mode 100644 vendor/github.com/gogits/go-libravatar/Makefile delete mode 100644 vendor/github.com/gogits/go-libravatar/README.md delete mode 100644 vendor/github.com/gogits/go-libravatar/libravatar.go delete mode 100644 vendor/github.com/gogits/minwinsvc/LICENSE delete mode 100644 vendor/github.com/gogits/minwinsvc/README.md delete mode 100644 vendor/github.com/gogits/minwinsvc/minwinsvc.go delete mode 100644 vendor/github.com/gogits/minwinsvc/svc_other.go delete mode 100644 vendor/github.com/gogits/minwinsvc/svc_windows.go create mode 100644 vendor/github.com/gogs/chardet/2022.go create mode 100644 vendor/github.com/gogs/chardet/AUTHORS create mode 100644 vendor/github.com/gogs/chardet/LICENSE create mode 100644 vendor/github.com/gogs/chardet/README.md create mode 100644 vendor/github.com/gogs/chardet/detector.go create mode 100644 vendor/github.com/gogs/chardet/icu-license.html create mode 100644 vendor/github.com/gogs/chardet/multi_byte.go create mode 100644 vendor/github.com/gogs/chardet/recognizer.go create mode 100644 vendor/github.com/gogs/chardet/single_byte.go create mode 100644 vendor/github.com/gogs/chardet/unicode.go create mode 100644 vendor/github.com/gogs/chardet/utf8.go create mode 100644 vendor/github.com/gogs/cron/LICENSE create mode 100644 vendor/github.com/gogs/cron/README.md create mode 100644 vendor/github.com/gogs/cron/constantdelay.go create mode 100644 vendor/github.com/gogs/cron/cron.go create mode 100644 vendor/github.com/gogs/cron/doc.go create mode 100644 vendor/github.com/gogs/cron/parser.go create mode 100644 vendor/github.com/gogs/cron/spec.go create mode 100644 vendor/github.com/gogs/git-module/LICENSE create mode 100644 vendor/github.com/gogs/git-module/README.md create mode 100644 vendor/github.com/gogs/git-module/blob.go create mode 100644 vendor/github.com/gogs/git-module/command.go create mode 100644 vendor/github.com/gogs/git-module/commit.go create mode 100644 vendor/github.com/gogs/git-module/commit_archive.go create mode 100644 vendor/github.com/gogs/git-module/error.go create mode 100644 vendor/github.com/gogs/git-module/git.go create mode 100644 vendor/github.com/gogs/git-module/hook.go create mode 100644 vendor/github.com/gogs/git-module/repo.go create mode 100644 vendor/github.com/gogs/git-module/repo_branch.go create mode 100644 vendor/github.com/gogs/git-module/repo_commit.go create mode 100644 vendor/github.com/gogs/git-module/repo_diff.go create mode 100644 vendor/github.com/gogs/git-module/repo_hook.go create mode 100644 vendor/github.com/gogs/git-module/repo_object.go create mode 100644 vendor/github.com/gogs/git-module/repo_pull.go create mode 100644 vendor/github.com/gogs/git-module/repo_tag.go create mode 100644 vendor/github.com/gogs/git-module/repo_tree.go create mode 100644 vendor/github.com/gogs/git-module/sha1.go create mode 100644 vendor/github.com/gogs/git-module/signature.go create mode 100644 vendor/github.com/gogs/git-module/submodule.go create mode 100644 vendor/github.com/gogs/git-module/tag.go create mode 100644 vendor/github.com/gogs/git-module/tree.go create mode 100644 vendor/github.com/gogs/git-module/tree_blob.go create mode 100644 vendor/github.com/gogs/git-module/tree_entry.go create mode 100644 vendor/github.com/gogs/git-module/utils.go create mode 100644 vendor/github.com/gogs/go-gogs-client/LICENSE create mode 100644 vendor/github.com/gogs/go-gogs-client/README.md create mode 100644 vendor/github.com/gogs/go-gogs-client/admin_org.go create mode 100644 vendor/github.com/gogs/go-gogs-client/admin_repo.go create mode 100644 vendor/github.com/gogs/go-gogs-client/admin_user.go create mode 100644 vendor/github.com/gogs/go-gogs-client/gogs.go create mode 100644 vendor/github.com/gogs/go-gogs-client/issue.go create mode 100644 vendor/github.com/gogs/go-gogs-client/issue_comment.go create mode 100644 vendor/github.com/gogs/go-gogs-client/issue_label.go create mode 100644 vendor/github.com/gogs/go-gogs-client/issue_milestone.go create mode 100644 vendor/github.com/gogs/go-gogs-client/miscellaneous.go create mode 100644 vendor/github.com/gogs/go-gogs-client/org.go create mode 100644 vendor/github.com/gogs/go-gogs-client/org_member.go create mode 100644 vendor/github.com/gogs/go-gogs-client/org_team.go create mode 100644 vendor/github.com/gogs/go-gogs-client/pull.go create mode 100644 vendor/github.com/gogs/go-gogs-client/release.go create mode 100644 vendor/github.com/gogs/go-gogs-client/repo.go create mode 100644 vendor/github.com/gogs/go-gogs-client/repo_branch.go create mode 100644 vendor/github.com/gogs/go-gogs-client/repo_collaborator.go create mode 100644 vendor/github.com/gogs/go-gogs-client/repo_file.go create mode 100644 vendor/github.com/gogs/go-gogs-client/repo_hook.go create mode 100644 vendor/github.com/gogs/go-gogs-client/repo_key.go create mode 100644 vendor/github.com/gogs/go-gogs-client/user.go create mode 100644 vendor/github.com/gogs/go-gogs-client/user_app.go create mode 100644 vendor/github.com/gogs/go-gogs-client/user_email.go create mode 100644 vendor/github.com/gogs/go-gogs-client/user_follow.go create mode 100644 vendor/github.com/gogs/go-gogs-client/user_key.go create mode 100644 vendor/github.com/gogs/go-gogs-client/utils.go create mode 100644 vendor/github.com/gogs/go-libravatar/LICENSE create mode 100644 vendor/github.com/gogs/go-libravatar/Makefile create mode 100644 vendor/github.com/gogs/go-libravatar/README.md create mode 100644 vendor/github.com/gogs/go-libravatar/libravatar.go create mode 100644 vendor/github.com/gogs/minwinsvc/LICENSE create mode 100644 vendor/github.com/gogs/minwinsvc/README.md create mode 100644 vendor/github.com/gogs/minwinsvc/minwinsvc.go create mode 100644 vendor/github.com/gogs/minwinsvc/svc_other.go create mode 100644 vendor/github.com/gogs/minwinsvc/svc_windows.go (limited to 'vendor/github.com') diff --git a/vendor/github.com/gogits/chardet/2022.go b/vendor/github.com/gogits/chardet/2022.go deleted file mode 100644 index e667225e..00000000 --- a/vendor/github.com/gogits/chardet/2022.go +++ /dev/null @@ -1,102 +0,0 @@ -package chardet - -import ( - "bytes" -) - -type recognizer2022 struct { - charset string - escapes [][]byte -} - -func (r *recognizer2022) Match(input *recognizerInput) (output recognizerOutput) { - return recognizerOutput{ - Charset: r.charset, - Confidence: r.matchConfidence(input.input), - } -} - -func (r *recognizer2022) matchConfidence(input []byte) int { - var hits, misses, shifts int -input: - for i := 0; i < len(input); i++ { - c := input[i] - if c == 0x1B { - for _, esc := range r.escapes { - if bytes.HasPrefix(input[i+1:], esc) { - hits++ - i += len(esc) - continue input - } - } - misses++ - } else if c == 0x0E || c == 0x0F { - shifts++ - } - } - if hits == 0 { - return 0 - } - quality := (100*hits - 100*misses) / (hits + misses) - if hits+shifts < 5 { - quality -= (5 - (hits + shifts)) * 10 - } - if quality < 0 { - quality = 0 - } - return quality -} - -var escapeSequences_2022JP = [][]byte{ - {0x24, 0x28, 0x43}, // KS X 1001:1992 - {0x24, 0x28, 0x44}, // JIS X 212-1990 - {0x24, 0x40}, // JIS C 6226-1978 - {0x24, 0x41}, // GB 2312-80 - {0x24, 0x42}, // JIS X 208-1983 - {0x26, 0x40}, // JIS X 208 1990, 1997 - {0x28, 0x42}, // ASCII - {0x28, 0x48}, // JIS-Roman - {0x28, 0x49}, // Half-width katakana - {0x28, 0x4a}, // JIS-Roman - {0x2e, 0x41}, // ISO 8859-1 - {0x2e, 0x46}, // ISO 8859-7 -} - -var escapeSequences_2022KR = [][]byte{ - {0x24, 0x29, 0x43}, -} - -var escapeSequences_2022CN = [][]byte{ - {0x24, 0x29, 0x41}, // GB 2312-80 - {0x24, 0x29, 0x47}, // CNS 11643-1992 Plane 1 - {0x24, 0x2A, 0x48}, // CNS 11643-1992 Plane 2 - {0x24, 0x29, 0x45}, // ISO-IR-165 - {0x24, 0x2B, 0x49}, // CNS 11643-1992 Plane 3 - {0x24, 0x2B, 0x4A}, // CNS 11643-1992 Plane 4 - {0x24, 0x2B, 0x4B}, // CNS 11643-1992 Plane 5 - {0x24, 0x2B, 0x4C}, // CNS 11643-1992 Plane 6 - {0x24, 0x2B, 0x4D}, // CNS 11643-1992 Plane 7 - {0x4e}, // SS2 - {0x4f}, // SS3 -} - -func newRecognizer_2022JP() *recognizer2022 { - return &recognizer2022{ - "ISO-2022-JP", - escapeSequences_2022JP, - } -} - -func newRecognizer_2022KR() *recognizer2022 { - return &recognizer2022{ - "ISO-2022-KR", - escapeSequences_2022KR, - } -} - -func newRecognizer_2022CN() *recognizer2022 { - return &recognizer2022{ - "ISO-2022-CN", - escapeSequences_2022CN, - } -} diff --git a/vendor/github.com/gogits/chardet/AUTHORS b/vendor/github.com/gogits/chardet/AUTHORS deleted file mode 100644 index 842d0216..00000000 --- a/vendor/github.com/gogits/chardet/AUTHORS +++ /dev/null @@ -1 +0,0 @@ -Sheng Yu (yusheng dot sjtu at gmail dot com) diff --git a/vendor/github.com/gogits/chardet/LICENSE b/vendor/github.com/gogits/chardet/LICENSE deleted file mode 100644 index 35ee796b..00000000 --- a/vendor/github.com/gogits/chardet/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -Copyright (c) 2012 chardet Authors - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -Partial of the Software is derived from ICU project. See icu-license.html for -license of the derivative portions. diff --git a/vendor/github.com/gogits/chardet/README.md b/vendor/github.com/gogits/chardet/README.md deleted file mode 100644 index bbde23fb..00000000 --- a/vendor/github.com/gogits/chardet/README.md +++ /dev/null @@ -1,12 +0,0 @@ -# chardet - -chardet is library to automatically detect -[charset](http://en.wikipedia.org/wiki/Character_encoding) of texts for [Go -programming language](http://golang.org/). It's based on the algorithm and data -in [ICU](http://icu-project.org/)'s implementation. - -The project was created by [saintfish](http://github.com/saintfish/chardet). In January 2015 it was forked by the gogits project in order to incorporate bugfixes and new features. - -## Documentation and Usage - -See [pkgdoc](http://godoc.org/github.com/gogits/chardet) diff --git a/vendor/github.com/gogits/chardet/detector.go b/vendor/github.com/gogits/chardet/detector.go deleted file mode 100644 index e11c222e..00000000 --- a/vendor/github.com/gogits/chardet/detector.go +++ /dev/null @@ -1,136 +0,0 @@ -// Package chardet ports character set detection from ICU. -package chardet - -import ( - "errors" - "sort" -) - -// Result contains all the information that charset detector gives. -type Result struct { - // IANA name of the detected charset. - Charset string - // IANA name of the detected language. It may be empty for some charsets. - Language string - // Confidence of the Result. Scale from 1 to 100. The bigger, the more confident. - Confidence int -} - -// Detector implements charset detection. -type Detector struct { - recognizers []recognizer - stripTag bool -} - -// List of charset recognizers -var recognizers = []recognizer{ - newRecognizer_utf8(), - newRecognizer_utf16be(), - newRecognizer_utf16le(), - newRecognizer_utf32be(), - newRecognizer_utf32le(), - newRecognizer_8859_1_en(), - newRecognizer_8859_1_da(), - newRecognizer_8859_1_de(), - newRecognizer_8859_1_es(), - newRecognizer_8859_1_fr(), - newRecognizer_8859_1_it(), - newRecognizer_8859_1_nl(), - newRecognizer_8859_1_no(), - newRecognizer_8859_1_pt(), - newRecognizer_8859_1_sv(), - newRecognizer_8859_2_cs(), - newRecognizer_8859_2_hu(), - newRecognizer_8859_2_pl(), - newRecognizer_8859_2_ro(), - newRecognizer_8859_5_ru(), - newRecognizer_8859_6_ar(), - newRecognizer_8859_7_el(), - newRecognizer_8859_8_I_he(), - newRecognizer_8859_8_he(), - newRecognizer_windows_1251(), - newRecognizer_windows_1256(), - newRecognizer_KOI8_R(), - newRecognizer_8859_9_tr(), - - newRecognizer_sjis(), - newRecognizer_gb_18030(), - newRecognizer_euc_jp(), - newRecognizer_euc_kr(), - newRecognizer_big5(), - - newRecognizer_2022JP(), - newRecognizer_2022KR(), - newRecognizer_2022CN(), - - newRecognizer_IBM424_he_rtl(), - newRecognizer_IBM424_he_ltr(), - newRecognizer_IBM420_ar_rtl(), - newRecognizer_IBM420_ar_ltr(), -} - -// NewTextDetector creates a Detector for plain text. -func NewTextDetector() *Detector { - return &Detector{recognizers, false} -} - -// NewHtmlDetector creates a Detector for Html. -func NewHtmlDetector() *Detector { - return &Detector{recognizers, true} -} - -var ( - NotDetectedError = errors.New("Charset not detected.") -) - -// DetectBest returns the Result with highest Confidence. -func (d *Detector) DetectBest(b []byte) (r *Result, err error) { - var all []Result - if all, err = d.DetectAll(b); err == nil { - r = &all[0] - } - return -} - -// DetectAll returns all Results which have non-zero Confidence. The Results are sorted by Confidence in descending order. -func (d *Detector) DetectAll(b []byte) ([]Result, error) { - input := newRecognizerInput(b, d.stripTag) - outputChan := make(chan recognizerOutput) - for _, r := range d.recognizers { - go matchHelper(r, input, outputChan) - } - outputs := make([]recognizerOutput, 0, len(d.recognizers)) - for i := 0; i < len(d.recognizers); i++ { - o := <-outputChan - if o.Confidence > 0 { - outputs = append(outputs, o) - } - } - if len(outputs) == 0 { - return nil, NotDetectedError - } - - sort.Sort(recognizerOutputs(outputs)) - dedupOutputs := make([]Result, 0, len(outputs)) - foundCharsets := make(map[string]struct{}, len(outputs)) - for _, o := range outputs { - if _, found := foundCharsets[o.Charset]; !found { - dedupOutputs = append(dedupOutputs, Result(o)) - foundCharsets[o.Charset] = struct{}{} - } - } - if len(dedupOutputs) == 0 { - return nil, NotDetectedError - } - return dedupOutputs, nil -} - -func matchHelper(r recognizer, input *recognizerInput, outputChan chan<- recognizerOutput) { - outputChan <- r.Match(input) -} - -type recognizerOutputs []recognizerOutput - -func (r recognizerOutputs) Len() int { return len(r) } -func (r recognizerOutputs) Less(i, j int) bool { return r[i].Confidence > r[j].Confidence } -func (r recognizerOutputs) Swap(i, j int) { r[i], r[j] = r[j], r[i] } diff --git a/vendor/github.com/gogits/chardet/icu-license.html b/vendor/github.com/gogits/chardet/icu-license.html deleted file mode 100644 index d078d057..00000000 --- a/vendor/github.com/gogits/chardet/icu-license.html +++ /dev/null @@ -1,51 +0,0 @@ - - - - -ICU License - ICU 1.8.1 and later - - - -

ICU License - ICU 1.8.1 and later

- -

COPYRIGHT AND PERMISSION NOTICE

- -

-Copyright (c) 1995-2012 International Business Machines Corporation and others -

-

-All rights reserved. -

-

-Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), -to deal in the Software without restriction, including without limitation -the rights to use, copy, modify, merge, publish, distribute, and/or sell -copies of the Software, and to permit persons -to whom the Software is furnished to do so, provided that the above -copyright notice(s) and this permission notice appear in all copies -of the Software and that both the above copyright notice(s) and this -permission notice appear in supporting documentation. -

-

-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, -INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL -THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, -OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER -RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, -NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE -USE OR PERFORMANCE OF THIS SOFTWARE. -

-

-Except as contained in this notice, the name of a copyright holder shall not be -used in advertising or otherwise to promote the sale, use or other dealings in -this Software without prior written authorization of the copyright holder. -

- -
-

-All trademarks and registered trademarks mentioned herein are the property of their respective owners. -

- - diff --git a/vendor/github.com/gogits/chardet/multi_byte.go b/vendor/github.com/gogits/chardet/multi_byte.go deleted file mode 100644 index b5cdf3d6..00000000 --- a/vendor/github.com/gogits/chardet/multi_byte.go +++ /dev/null @@ -1,345 +0,0 @@ -package chardet - -import ( - "errors" - "math" -) - -type recognizerMultiByte struct { - charset string - language string - decoder charDecoder - commonChars []uint16 -} - -type charDecoder interface { - DecodeOneChar([]byte) (c uint16, remain []byte, err error) -} - -func (r *recognizerMultiByte) Match(input *recognizerInput) (output recognizerOutput) { - return recognizerOutput{ - Charset: r.charset, - Language: r.language, - Confidence: r.matchConfidence(input), - } -} - -func (r *recognizerMultiByte) matchConfidence(input *recognizerInput) int { - raw := input.raw - var c uint16 - var err error - var totalCharCount, badCharCount, singleByteCharCount, doubleByteCharCount, commonCharCount int - for c, raw, err = r.decoder.DecodeOneChar(raw); len(raw) > 0; c, raw, err = r.decoder.DecodeOneChar(raw) { - totalCharCount++ - if err != nil { - badCharCount++ - } else if c <= 0xFF { - singleByteCharCount++ - } else { - doubleByteCharCount++ - if r.commonChars != nil && binarySearch(r.commonChars, c) { - commonCharCount++ - } - } - if badCharCount >= 2 && badCharCount*5 >= doubleByteCharCount { - return 0 - } - } - - if doubleByteCharCount <= 10 && badCharCount == 0 { - if doubleByteCharCount == 0 && totalCharCount < 10 { - return 0 - } else { - return 10 - } - } - - if doubleByteCharCount < 20*badCharCount { - return 0 - } - if r.commonChars == nil { - confidence := 30 + doubleByteCharCount - 20*badCharCount - if confidence > 100 { - confidence = 100 - } - return confidence - } - maxVal := math.Log(float64(doubleByteCharCount) / 4) - scaleFactor := 90 / maxVal - confidence := int(math.Log(float64(commonCharCount)+1)*scaleFactor + 10) - if confidence > 100 { - confidence = 100 - } - if confidence < 0 { - confidence = 0 - } - return confidence -} - -func binarySearch(l []uint16, c uint16) bool { - start := 0 - end := len(l) - 1 - for start <= end { - mid := (start + end) / 2 - if c == l[mid] { - return true - } else if c < l[mid] { - end = mid - 1 - } else { - start = mid + 1 - } - } - return false -} - -var eobError = errors.New("End of input buffer") -var badCharError = errors.New("Decode a bad char") - -type charDecoder_sjis struct { -} - -func (charDecoder_sjis) DecodeOneChar(input []byte) (c uint16, remain []byte, err error) { - if len(input) == 0 { - return 0, nil, eobError - } - first := input[0] - c = uint16(first) - remain = input[1:] - if first <= 0x7F || (first > 0xA0 && first <= 0xDF) { - return - } - if len(remain) == 0 { - return c, remain, badCharError - } - second := remain[0] - remain = remain[1:] - c = c<<8 | uint16(second) - if (second >= 0x40 && second <= 0x7F) || (second >= 0x80 && second <= 0xFE) { - } else { - err = badCharError - } - return -} - -var commonChars_sjis = []uint16{ - 0x8140, 0x8141, 0x8142, 0x8145, 0x815b, 0x8169, 0x816a, 0x8175, 0x8176, 0x82a0, - 0x82a2, 0x82a4, 0x82a9, 0x82aa, 0x82ab, 0x82ad, 0x82af, 0x82b1, 0x82b3, 0x82b5, - 0x82b7, 0x82bd, 0x82be, 0x82c1, 0x82c4, 0x82c5, 0x82c6, 0x82c8, 0x82c9, 0x82cc, - 0x82cd, 0x82dc, 0x82e0, 0x82e7, 0x82e8, 0x82e9, 0x82ea, 0x82f0, 0x82f1, 0x8341, - 0x8343, 0x834e, 0x834f, 0x8358, 0x835e, 0x8362, 0x8367, 0x8375, 0x8376, 0x8389, - 0x838a, 0x838b, 0x838d, 0x8393, 0x8e96, 0x93fa, 0x95aa, -} - -func newRecognizer_sjis() *recognizerMultiByte { - return &recognizerMultiByte{ - "Shift_JIS", - "ja", - charDecoder_sjis{}, - commonChars_sjis, - } -} - -type charDecoder_euc struct { -} - -func (charDecoder_euc) DecodeOneChar(input []byte) (c uint16, remain []byte, err error) { - if len(input) == 0 { - return 0, nil, eobError - } - first := input[0] - remain = input[1:] - c = uint16(first) - if first <= 0x8D { - return uint16(first), remain, nil - } - if len(remain) == 0 { - return 0, nil, eobError - } - second := remain[0] - remain = remain[1:] - c = c<<8 | uint16(second) - if first >= 0xA1 && first <= 0xFE { - if second < 0xA1 { - err = badCharError - } - return - } - if first == 0x8E { - if second < 0xA1 { - err = badCharError - } - return - } - if first == 0x8F { - if len(remain) == 0 { - return 0, nil, eobError - } - third := remain[0] - remain = remain[1:] - c = c<<0 | uint16(third) - if third < 0xa1 { - err = badCharError - } - } - return -} - -var commonChars_euc_jp = []uint16{ - 0xa1a1, 0xa1a2, 0xa1a3, 0xa1a6, 0xa1bc, 0xa1ca, 0xa1cb, 0xa1d6, 0xa1d7, 0xa4a2, - 0xa4a4, 0xa4a6, 0xa4a8, 0xa4aa, 0xa4ab, 0xa4ac, 0xa4ad, 0xa4af, 0xa4b1, 0xa4b3, - 0xa4b5, 0xa4b7, 0xa4b9, 0xa4bb, 0xa4bd, 0xa4bf, 0xa4c0, 0xa4c1, 0xa4c3, 0xa4c4, - 0xa4c6, 0xa4c7, 0xa4c8, 0xa4c9, 0xa4ca, 0xa4cb, 0xa4ce, 0xa4cf, 0xa4d0, 0xa4de, - 0xa4df, 0xa4e1, 0xa4e2, 0xa4e4, 0xa4e8, 0xa4e9, 0xa4ea, 0xa4eb, 0xa4ec, 0xa4ef, - 0xa4f2, 0xa4f3, 0xa5a2, 0xa5a3, 0xa5a4, 0xa5a6, 0xa5a7, 0xa5aa, 0xa5ad, 0xa5af, - 0xa5b0, 0xa5b3, 0xa5b5, 0xa5b7, 0xa5b8, 0xa5b9, 0xa5bf, 0xa5c3, 0xa5c6, 0xa5c7, - 0xa5c8, 0xa5c9, 0xa5cb, 0xa5d0, 0xa5d5, 0xa5d6, 0xa5d7, 0xa5de, 0xa5e0, 0xa5e1, - 0xa5e5, 0xa5e9, 0xa5ea, 0xa5eb, 0xa5ec, 0xa5ed, 0xa5f3, 0xb8a9, 0xb9d4, 0xbaee, - 0xbbc8, 0xbef0, 0xbfb7, 0xc4ea, 0xc6fc, 0xc7bd, 0xcab8, 0xcaf3, 0xcbdc, 0xcdd1, -} - -var commonChars_euc_kr = []uint16{ - 0xb0a1, 0xb0b3, 0xb0c5, 0xb0cd, 0xb0d4, 0xb0e6, 0xb0ed, 0xb0f8, 0xb0fa, 0xb0fc, - 0xb1b8, 0xb1b9, 0xb1c7, 0xb1d7, 0xb1e2, 0xb3aa, 0xb3bb, 0xb4c2, 0xb4cf, 0xb4d9, - 0xb4eb, 0xb5a5, 0xb5b5, 0xb5bf, 0xb5c7, 0xb5e9, 0xb6f3, 0xb7af, 0xb7c2, 0xb7ce, - 0xb8a6, 0xb8ae, 0xb8b6, 0xb8b8, 0xb8bb, 0xb8e9, 0xb9ab, 0xb9ae, 0xb9cc, 0xb9ce, - 0xb9fd, 0xbab8, 0xbace, 0xbad0, 0xbaf1, 0xbbe7, 0xbbf3, 0xbbfd, 0xbcad, 0xbcba, - 0xbcd2, 0xbcf6, 0xbdba, 0xbdc0, 0xbdc3, 0xbdc5, 0xbec6, 0xbec8, 0xbedf, 0xbeee, - 0xbef8, 0xbefa, 0xbfa1, 0xbfa9, 0xbfc0, 0xbfe4, 0xbfeb, 0xbfec, 0xbff8, 0xc0a7, - 0xc0af, 0xc0b8, 0xc0ba, 0xc0bb, 0xc0bd, 0xc0c7, 0xc0cc, 0xc0ce, 0xc0cf, 0xc0d6, - 0xc0da, 0xc0e5, 0xc0fb, 0xc0fc, 0xc1a4, 0xc1a6, 0xc1b6, 0xc1d6, 0xc1df, 0xc1f6, - 0xc1f8, 0xc4a1, 0xc5cd, 0xc6ae, 0xc7cf, 0xc7d1, 0xc7d2, 0xc7d8, 0xc7e5, 0xc8ad, -} - -func newRecognizer_euc_jp() *recognizerMultiByte { - return &recognizerMultiByte{ - "EUC-JP", - "ja", - charDecoder_euc{}, - commonChars_euc_jp, - } -} - -func newRecognizer_euc_kr() *recognizerMultiByte { - return &recognizerMultiByte{ - "EUC-KR", - "ko", - charDecoder_euc{}, - commonChars_euc_kr, - } -} - -type charDecoder_big5 struct { -} - -func (charDecoder_big5) DecodeOneChar(input []byte) (c uint16, remain []byte, err error) { - if len(input) == 0 { - return 0, nil, eobError - } - first := input[0] - remain = input[1:] - c = uint16(first) - if first <= 0x7F || first == 0xFF { - return - } - if len(remain) == 0 { - return c, nil, eobError - } - second := remain[0] - remain = remain[1:] - c = c<<8 | uint16(second) - if second < 0x40 || second == 0x7F || second == 0xFF { - err = badCharError - } - return -} - -var commonChars_big5 = []uint16{ - 0xa140, 0xa141, 0xa142, 0xa143, 0xa147, 0xa149, 0xa175, 0xa176, 0xa440, 0xa446, - 0xa447, 0xa448, 0xa451, 0xa454, 0xa457, 0xa464, 0xa46a, 0xa46c, 0xa477, 0xa4a3, - 0xa4a4, 0xa4a7, 0xa4c1, 0xa4ce, 0xa4d1, 0xa4df, 0xa4e8, 0xa4fd, 0xa540, 0xa548, - 0xa558, 0xa569, 0xa5cd, 0xa5e7, 0xa657, 0xa661, 0xa662, 0xa668, 0xa670, 0xa6a8, - 0xa6b3, 0xa6b9, 0xa6d3, 0xa6db, 0xa6e6, 0xa6f2, 0xa740, 0xa751, 0xa759, 0xa7da, - 0xa8a3, 0xa8a5, 0xa8ad, 0xa8d1, 0xa8d3, 0xa8e4, 0xa8fc, 0xa9c0, 0xa9d2, 0xa9f3, - 0xaa6b, 0xaaba, 0xaabe, 0xaacc, 0xaafc, 0xac47, 0xac4f, 0xacb0, 0xacd2, 0xad59, - 0xaec9, 0xafe0, 0xb0ea, 0xb16f, 0xb2b3, 0xb2c4, 0xb36f, 0xb44c, 0xb44e, 0xb54c, - 0xb5a5, 0xb5bd, 0xb5d0, 0xb5d8, 0xb671, 0xb7ed, 0xb867, 0xb944, 0xbad8, 0xbb44, - 0xbba1, 0xbdd1, 0xc2c4, 0xc3b9, 0xc440, 0xc45f, -} - -func newRecognizer_big5() *recognizerMultiByte { - return &recognizerMultiByte{ - "Big5", - "zh", - charDecoder_big5{}, - commonChars_big5, - } -} - -type charDecoder_gb_18030 struct { -} - -func (charDecoder_gb_18030) DecodeOneChar(input []byte) (c uint16, remain []byte, err error) { - if len(input) == 0 { - return 0, nil, eobError - } - first := input[0] - remain = input[1:] - c = uint16(first) - if first <= 0x80 { - return - } - if len(remain) == 0 { - return 0, nil, eobError - } - second := remain[0] - remain = remain[1:] - c = c<<8 | uint16(second) - if first >= 0x81 && first <= 0xFE { - if (second >= 0x40 && second <= 0x7E) || (second >= 0x80 && second <= 0xFE) { - return - } - - if second >= 0x30 && second <= 0x39 { - if len(remain) == 0 { - return 0, nil, eobError - } - third := remain[0] - remain = remain[1:] - if third >= 0x81 && third <= 0xFE { - if len(remain) == 0 { - return 0, nil, eobError - } - fourth := remain[0] - remain = remain[1:] - if fourth >= 0x30 && fourth <= 0x39 { - c = c<<16 | uint16(third)<<8 | uint16(fourth) - return - } - } - } - err = badCharError - } - return -} - -var commonChars_gb_18030 = []uint16{ - 0xa1a1, 0xa1a2, 0xa1a3, 0xa1a4, 0xa1b0, 0xa1b1, 0xa1f1, 0xa1f3, 0xa3a1, 0xa3ac, - 0xa3ba, 0xb1a8, 0xb1b8, 0xb1be, 0xb2bb, 0xb3c9, 0xb3f6, 0xb4f3, 0xb5bd, 0xb5c4, - 0xb5e3, 0xb6af, 0xb6d4, 0xb6e0, 0xb7a2, 0xb7a8, 0xb7bd, 0xb7d6, 0xb7dd, 0xb8b4, - 0xb8df, 0xb8f6, 0xb9ab, 0xb9c9, 0xb9d8, 0xb9fa, 0xb9fd, 0xbacd, 0xbba7, 0xbbd6, - 0xbbe1, 0xbbfa, 0xbcbc, 0xbcdb, 0xbcfe, 0xbdcc, 0xbecd, 0xbedd, 0xbfb4, 0xbfc6, - 0xbfc9, 0xc0b4, 0xc0ed, 0xc1cb, 0xc2db, 0xc3c7, 0xc4dc, 0xc4ea, 0xc5cc, 0xc6f7, - 0xc7f8, 0xc8ab, 0xc8cb, 0xc8d5, 0xc8e7, 0xc9cf, 0xc9fa, 0xcab1, 0xcab5, 0xcac7, - 0xcad0, 0xcad6, 0xcaf5, 0xcafd, 0xccec, 0xcdf8, 0xceaa, 0xcec4, 0xced2, 0xcee5, - 0xcfb5, 0xcfc2, 0xcfd6, 0xd0c2, 0xd0c5, 0xd0d0, 0xd0d4, 0xd1a7, 0xd2aa, 0xd2b2, - 0xd2b5, 0xd2bb, 0xd2d4, 0xd3c3, 0xd3d0, 0xd3fd, 0xd4c2, 0xd4da, 0xd5e2, 0xd6d0, -} - -func newRecognizer_gb_18030() *recognizerMultiByte { - return &recognizerMultiByte{ - "GB18030", - "zh", - charDecoder_gb_18030{}, - commonChars_gb_18030, - } -} diff --git a/vendor/github.com/gogits/chardet/recognizer.go b/vendor/github.com/gogits/chardet/recognizer.go deleted file mode 100644 index 1bf8461c..00000000 --- a/vendor/github.com/gogits/chardet/recognizer.go +++ /dev/null @@ -1,83 +0,0 @@ -package chardet - -type recognizer interface { - Match(*recognizerInput) recognizerOutput -} - -type recognizerOutput Result - -type recognizerInput struct { - raw []byte - input []byte - tagStripped bool - byteStats []int - hasC1Bytes bool -} - -func newRecognizerInput(raw []byte, stripTag bool) *recognizerInput { - input, stripped := mayStripInput(raw, stripTag) - byteStats := computeByteStats(input) - return &recognizerInput{ - raw: raw, - input: input, - tagStripped: stripped, - byteStats: byteStats, - hasC1Bytes: computeHasC1Bytes(byteStats), - } -} - -func mayStripInput(raw []byte, stripTag bool) (out []byte, stripped bool) { - const inputBufferSize = 8192 - out = make([]byte, 0, inputBufferSize) - var badTags, openTags int32 - var inMarkup bool = false - stripped = false - if stripTag { - stripped = true - for _, c := range raw { - if c == '<' { - if inMarkup { - badTags += 1 - } - inMarkup = true - openTags += 1 - } - if !inMarkup { - out = append(out, c) - if len(out) >= inputBufferSize { - break - } - } - if c == '>' { - inMarkup = false - } - } - } - if openTags < 5 || openTags/5 < badTags || (len(out) < 100 && len(raw) > 600) { - limit := len(raw) - if limit > inputBufferSize { - limit = inputBufferSize - } - out = make([]byte, limit) - copy(out, raw[:limit]) - stripped = false - } - return -} - -func computeByteStats(input []byte) []int { - r := make([]int, 256) - for _, c := range input { - r[c] += 1 - } - return r -} - -func computeHasC1Bytes(byteStats []int) bool { - for _, count := range byteStats[0x80 : 0x9F+1] { - if count > 0 { - return true - } - } - return false -} diff --git a/vendor/github.com/gogits/chardet/single_byte.go b/vendor/github.com/gogits/chardet/single_byte.go deleted file mode 100644 index a7ce39bc..00000000 --- a/vendor/github.com/gogits/chardet/single_byte.go +++ /dev/null @@ -1,882 +0,0 @@ -package chardet - -// Recognizer for single byte charset family -type recognizerSingleByte struct { - charset string - hasC1ByteCharset string - language string - charMap *[256]byte - ngram *[64]uint32 -} - -func (r *recognizerSingleByte) Match(input *recognizerInput) recognizerOutput { - var charset string = r.charset - if input.hasC1Bytes && len(r.hasC1ByteCharset) > 0 { - charset = r.hasC1ByteCharset - } - return recognizerOutput{ - Charset: charset, - Language: r.language, - Confidence: r.parseNgram(input.input), - } -} - -type ngramState struct { - ngram uint32 - ignoreSpace bool - ngramCount, ngramHit uint32 - table *[64]uint32 -} - -func newNgramState(table *[64]uint32) *ngramState { - return &ngramState{ - ngram: 0, - ignoreSpace: false, - ngramCount: 0, - ngramHit: 0, - table: table, - } -} - -func (s *ngramState) AddByte(b byte) { - const ngramMask = 0xFFFFFF - if !(b == 0x20 && s.ignoreSpace) { - s.ngram = ((s.ngram << 8) | uint32(b)) & ngramMask - s.ignoreSpace = (s.ngram == 0x20) - s.ngramCount++ - if s.lookup() { - s.ngramHit++ - } - } - s.ignoreSpace = (b == 0x20) -} - -func (s *ngramState) HitRate() float32 { - if s.ngramCount == 0 { - return 0 - } - return float32(s.ngramHit) / float32(s.ngramCount) -} - -func (s *ngramState) lookup() bool { - var index int - if s.table[index+32] <= s.ngram { - index += 32 - } - if s.table[index+16] <= s.ngram { - index += 16 - } - if s.table[index+8] <= s.ngram { - index += 8 - } - if s.table[index+4] <= s.ngram { - index += 4 - } - if s.table[index+2] <= s.ngram { - index += 2 - } - if s.table[index+1] <= s.ngram { - index += 1 - } - if s.table[index] > s.ngram { - index -= 1 - } - if index < 0 || s.table[index] != s.ngram { - return false - } - return true -} - -func (r *recognizerSingleByte) parseNgram(input []byte) int { - state := newNgramState(r.ngram) - for _, inChar := range input { - c := r.charMap[inChar] - if c != 0 { - state.AddByte(c) - } - } - state.AddByte(0x20) - rate := state.HitRate() - if rate > 0.33 { - return 98 - } - return int(rate * 300) -} - -var charMap_8859_1 = [256]byte{ - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, - 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, - 0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, - 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, - 0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0xAA, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0xB5, 0x20, 0x20, - 0x20, 0x20, 0xBA, 0x20, 0x20, 0x20, 0x20, 0x20, - 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, - 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, - 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0x20, - 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xDF, - 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, - 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, - 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0x20, - 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF, -} - -var ngrams_8859_1_en = [64]uint32{ - 0x206120, 0x20616E, 0x206265, 0x20636F, 0x20666F, 0x206861, 0x206865, 0x20696E, 0x206D61, 0x206F66, 0x207072, 0x207265, 0x207361, 0x207374, 0x207468, 0x20746F, - 0x207768, 0x616964, 0x616C20, 0x616E20, 0x616E64, 0x617320, 0x617420, 0x617465, 0x617469, 0x642061, 0x642074, 0x652061, 0x652073, 0x652074, 0x656420, 0x656E74, - 0x657220, 0x657320, 0x666F72, 0x686174, 0x686520, 0x686572, 0x696420, 0x696E20, 0x696E67, 0x696F6E, 0x697320, 0x6E2061, 0x6E2074, 0x6E6420, 0x6E6720, 0x6E7420, - 0x6F6620, 0x6F6E20, 0x6F7220, 0x726520, 0x727320, 0x732061, 0x732074, 0x736169, 0x737420, 0x742074, 0x746572, 0x746861, 0x746865, 0x74696F, 0x746F20, 0x747320, -} - -var ngrams_8859_1_da = [64]uint32{ - 0x206166, 0x206174, 0x206465, 0x20656E, 0x206572, 0x20666F, 0x206861, 0x206920, 0x206D65, 0x206F67, 0x2070E5, 0x207369, 0x207374, 0x207469, 0x207669, 0x616620, - 0x616E20, 0x616E64, 0x617220, 0x617420, 0x646520, 0x64656E, 0x646572, 0x646574, 0x652073, 0x656420, 0x656465, 0x656E20, 0x656E64, 0x657220, 0x657265, 0x657320, - 0x657420, 0x666F72, 0x676520, 0x67656E, 0x676572, 0x696765, 0x696C20, 0x696E67, 0x6B6520, 0x6B6B65, 0x6C6572, 0x6C6967, 0x6C6C65, 0x6D6564, 0x6E6465, 0x6E6520, - 0x6E6720, 0x6E6765, 0x6F6720, 0x6F6D20, 0x6F7220, 0x70E520, 0x722064, 0x722065, 0x722073, 0x726520, 0x737465, 0x742073, 0x746520, 0x746572, 0x74696C, 0x766572, -} - -var ngrams_8859_1_de = [64]uint32{ - 0x20616E, 0x206175, 0x206265, 0x206461, 0x206465, 0x206469, 0x206569, 0x206765, 0x206861, 0x20696E, 0x206D69, 0x207363, 0x207365, 0x20756E, 0x207665, 0x20766F, - 0x207765, 0x207A75, 0x626572, 0x636820, 0x636865, 0x636874, 0x646173, 0x64656E, 0x646572, 0x646965, 0x652064, 0x652073, 0x65696E, 0x656974, 0x656E20, 0x657220, - 0x657320, 0x67656E, 0x68656E, 0x687420, 0x696368, 0x696520, 0x696E20, 0x696E65, 0x697420, 0x6C6963, 0x6C6C65, 0x6E2061, 0x6E2064, 0x6E2073, 0x6E6420, 0x6E6465, - 0x6E6520, 0x6E6720, 0x6E6765, 0x6E7465, 0x722064, 0x726465, 0x726569, 0x736368, 0x737465, 0x742064, 0x746520, 0x74656E, 0x746572, 0x756E64, 0x756E67, 0x766572, -} - -var ngrams_8859_1_es = [64]uint32{ - 0x206120, 0x206361, 0x20636F, 0x206465, 0x20656C, 0x20656E, 0x206573, 0x20696E, 0x206C61, 0x206C6F, 0x207061, 0x20706F, 0x207072, 0x207175, 0x207265, 0x207365, - 0x20756E, 0x207920, 0x612063, 0x612064, 0x612065, 0x61206C, 0x612070, 0x616369, 0x61646F, 0x616C20, 0x617220, 0x617320, 0x6369F3, 0x636F6E, 0x646520, 0x64656C, - 0x646F20, 0x652064, 0x652065, 0x65206C, 0x656C20, 0x656E20, 0x656E74, 0x657320, 0x657374, 0x69656E, 0x69F36E, 0x6C6120, 0x6C6F73, 0x6E2065, 0x6E7465, 0x6F2064, - 0x6F2065, 0x6F6E20, 0x6F7220, 0x6F7320, 0x706172, 0x717565, 0x726120, 0x726573, 0x732064, 0x732065, 0x732070, 0x736520, 0x746520, 0x746F20, 0x756520, 0xF36E20, -} - -var ngrams_8859_1_fr = [64]uint32{ - 0x206175, 0x20636F, 0x206461, 0x206465, 0x206475, 0x20656E, 0x206574, 0x206C61, 0x206C65, 0x207061, 0x20706F, 0x207072, 0x207175, 0x207365, 0x20736F, 0x20756E, - 0x20E020, 0x616E74, 0x617469, 0x636520, 0x636F6E, 0x646520, 0x646573, 0x647520, 0x652061, 0x652063, 0x652064, 0x652065, 0x65206C, 0x652070, 0x652073, 0x656E20, - 0x656E74, 0x657220, 0x657320, 0x657420, 0x657572, 0x696F6E, 0x697320, 0x697420, 0x6C6120, 0x6C6520, 0x6C6573, 0x6D656E, 0x6E2064, 0x6E6520, 0x6E7320, 0x6E7420, - 0x6F6E20, 0x6F6E74, 0x6F7572, 0x717565, 0x72206C, 0x726520, 0x732061, 0x732064, 0x732065, 0x73206C, 0x732070, 0x742064, 0x746520, 0x74696F, 0x756520, 0x757220, -} - -var ngrams_8859_1_it = [64]uint32{ - 0x20616C, 0x206368, 0x20636F, 0x206465, 0x206469, 0x206520, 0x20696C, 0x20696E, 0x206C61, 0x207065, 0x207072, 0x20756E, 0x612063, 0x612064, 0x612070, 0x612073, - 0x61746F, 0x636865, 0x636F6E, 0x64656C, 0x646920, 0x652061, 0x652063, 0x652064, 0x652069, 0x65206C, 0x652070, 0x652073, 0x656C20, 0x656C6C, 0x656E74, 0x657220, - 0x686520, 0x692061, 0x692063, 0x692064, 0x692073, 0x696120, 0x696C20, 0x696E20, 0x696F6E, 0x6C6120, 0x6C6520, 0x6C6920, 0x6C6C61, 0x6E6520, 0x6E6920, 0x6E6F20, - 0x6E7465, 0x6F2061, 0x6F2064, 0x6F2069, 0x6F2073, 0x6F6E20, 0x6F6E65, 0x706572, 0x726120, 0x726520, 0x736920, 0x746120, 0x746520, 0x746920, 0x746F20, 0x7A696F, -} - -var ngrams_8859_1_nl = [64]uint32{ - 0x20616C, 0x206265, 0x206461, 0x206465, 0x206469, 0x206565, 0x20656E, 0x206765, 0x206865, 0x20696E, 0x206D61, 0x206D65, 0x206F70, 0x207465, 0x207661, 0x207665, - 0x20766F, 0x207765, 0x207A69, 0x61616E, 0x616172, 0x616E20, 0x616E64, 0x617220, 0x617420, 0x636874, 0x646520, 0x64656E, 0x646572, 0x652062, 0x652076, 0x65656E, - 0x656572, 0x656E20, 0x657220, 0x657273, 0x657420, 0x67656E, 0x686574, 0x696520, 0x696E20, 0x696E67, 0x697320, 0x6E2062, 0x6E2064, 0x6E2065, 0x6E2068, 0x6E206F, - 0x6E2076, 0x6E6465, 0x6E6720, 0x6F6E64, 0x6F6F72, 0x6F7020, 0x6F7220, 0x736368, 0x737465, 0x742064, 0x746520, 0x74656E, 0x746572, 0x76616E, 0x766572, 0x766F6F, -} - -var ngrams_8859_1_no = [64]uint32{ - 0x206174, 0x206176, 0x206465, 0x20656E, 0x206572, 0x20666F, 0x206861, 0x206920, 0x206D65, 0x206F67, 0x2070E5, 0x207365, 0x20736B, 0x20736F, 0x207374, 0x207469, - 0x207669, 0x20E520, 0x616E64, 0x617220, 0x617420, 0x646520, 0x64656E, 0x646574, 0x652073, 0x656420, 0x656E20, 0x656E65, 0x657220, 0x657265, 0x657420, 0x657474, - 0x666F72, 0x67656E, 0x696B6B, 0x696C20, 0x696E67, 0x6B6520, 0x6B6B65, 0x6C6520, 0x6C6C65, 0x6D6564, 0x6D656E, 0x6E2073, 0x6E6520, 0x6E6720, 0x6E6765, 0x6E6E65, - 0x6F6720, 0x6F6D20, 0x6F7220, 0x70E520, 0x722073, 0x726520, 0x736F6D, 0x737465, 0x742073, 0x746520, 0x74656E, 0x746572, 0x74696C, 0x747420, 0x747465, 0x766572, -} - -var ngrams_8859_1_pt = [64]uint32{ - 0x206120, 0x20636F, 0x206461, 0x206465, 0x20646F, 0x206520, 0x206573, 0x206D61, 0x206E6F, 0x206F20, 0x207061, 0x20706F, 0x207072, 0x207175, 0x207265, 0x207365, - 0x20756D, 0x612061, 0x612063, 0x612064, 0x612070, 0x616465, 0x61646F, 0x616C20, 0x617220, 0x617261, 0x617320, 0x636F6D, 0x636F6E, 0x646120, 0x646520, 0x646F20, - 0x646F73, 0x652061, 0x652064, 0x656D20, 0x656E74, 0x657320, 0x657374, 0x696120, 0x696361, 0x6D656E, 0x6E7465, 0x6E746F, 0x6F2061, 0x6F2063, 0x6F2064, 0x6F2065, - 0x6F2070, 0x6F7320, 0x706172, 0x717565, 0x726120, 0x726573, 0x732061, 0x732064, 0x732065, 0x732070, 0x737461, 0x746520, 0x746F20, 0x756520, 0xE36F20, 0xE7E36F, -} - -var ngrams_8859_1_sv = [64]uint32{ - 0x206174, 0x206176, 0x206465, 0x20656E, 0x2066F6, 0x206861, 0x206920, 0x20696E, 0x206B6F, 0x206D65, 0x206F63, 0x2070E5, 0x20736B, 0x20736F, 0x207374, 0x207469, - 0x207661, 0x207669, 0x20E472, 0x616465, 0x616E20, 0x616E64, 0x617220, 0x617474, 0x636820, 0x646520, 0x64656E, 0x646572, 0x646574, 0x656420, 0x656E20, 0x657220, - 0x657420, 0x66F672, 0x67656E, 0x696C6C, 0x696E67, 0x6B6120, 0x6C6C20, 0x6D6564, 0x6E2073, 0x6E6120, 0x6E6465, 0x6E6720, 0x6E6765, 0x6E696E, 0x6F6368, 0x6F6D20, - 0x6F6E20, 0x70E520, 0x722061, 0x722073, 0x726120, 0x736B61, 0x736F6D, 0x742073, 0x746120, 0x746520, 0x746572, 0x74696C, 0x747420, 0x766172, 0xE47220, 0xF67220, -} - -func newRecognizer_8859_1(language string, ngram *[64]uint32) *recognizerSingleByte { - return &recognizerSingleByte{ - charset: "ISO-8859-1", - hasC1ByteCharset: "windows-1252", - language: language, - charMap: &charMap_8859_1, - ngram: ngram, - } -} - -func newRecognizer_8859_1_en() *recognizerSingleByte { - return newRecognizer_8859_1("en", &ngrams_8859_1_en) -} -func newRecognizer_8859_1_da() *recognizerSingleByte { - return newRecognizer_8859_1("da", &ngrams_8859_1_da) -} -func newRecognizer_8859_1_de() *recognizerSingleByte { - return newRecognizer_8859_1("de", &ngrams_8859_1_de) -} -func newRecognizer_8859_1_es() *recognizerSingleByte { - return newRecognizer_8859_1("es", &ngrams_8859_1_es) -} -func newRecognizer_8859_1_fr() *recognizerSingleByte { - return newRecognizer_8859_1("fr", &ngrams_8859_1_fr) -} -func newRecognizer_8859_1_it() *recognizerSingleByte { - return newRecognizer_8859_1("it", &ngrams_8859_1_it) -} -func newRecognizer_8859_1_nl() *recognizerSingleByte { - return newRecognizer_8859_1("nl", &ngrams_8859_1_nl) -} -func newRecognizer_8859_1_no() *recognizerSingleByte { - return newRecognizer_8859_1("no", &ngrams_8859_1_no) -} -func newRecognizer_8859_1_pt() *recognizerSingleByte { - return newRecognizer_8859_1("pt", &ngrams_8859_1_pt) -} -func newRecognizer_8859_1_sv() *recognizerSingleByte { - return newRecognizer_8859_1("sv", &ngrams_8859_1_sv) -} - -var charMap_8859_2 = [256]byte{ - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, - 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, - 0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, - 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, - 0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0xB1, 0x20, 0xB3, 0x20, 0xB5, 0xB6, 0x20, - 0x20, 0xB9, 0xBA, 0xBB, 0xBC, 0x20, 0xBE, 0xBF, - 0x20, 0xB1, 0x20, 0xB3, 0x20, 0xB5, 0xB6, 0xB7, - 0x20, 0xB9, 0xBA, 0xBB, 0xBC, 0x20, 0xBE, 0xBF, - 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, - 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, - 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0x20, - 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xDF, - 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, - 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, - 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0x20, - 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0x20, -} - -var ngrams_8859_2_cs = [64]uint32{ - 0x206120, 0x206279, 0x20646F, 0x206A65, 0x206E61, 0x206E65, 0x206F20, 0x206F64, 0x20706F, 0x207072, 0x2070F8, 0x20726F, 0x207365, 0x20736F, 0x207374, 0x20746F, - 0x207620, 0x207679, 0x207A61, 0x612070, 0x636520, 0x636820, 0x652070, 0x652073, 0x652076, 0x656D20, 0x656EED, 0x686F20, 0x686F64, 0x697374, 0x6A6520, 0x6B7465, - 0x6C6520, 0x6C6920, 0x6E6120, 0x6EE920, 0x6EEC20, 0x6EED20, 0x6F2070, 0x6F646E, 0x6F6A69, 0x6F7374, 0x6F7520, 0x6F7661, 0x706F64, 0x706F6A, 0x70726F, 0x70F865, - 0x736520, 0x736F75, 0x737461, 0x737469, 0x73746E, 0x746572, 0x746EED, 0x746F20, 0x752070, 0xBE6520, 0xE16EED, 0xE9686F, 0xED2070, 0xED2073, 0xED6D20, 0xF86564, -} - -var ngrams_8859_2_hu = [64]uint32{ - 0x206120, 0x20617A, 0x206265, 0x206567, 0x20656C, 0x206665, 0x206861, 0x20686F, 0x206973, 0x206B65, 0x206B69, 0x206BF6, 0x206C65, 0x206D61, 0x206D65, 0x206D69, - 0x206E65, 0x20737A, 0x207465, 0x20E973, 0x612061, 0x61206B, 0x61206D, 0x612073, 0x616B20, 0x616E20, 0x617A20, 0x62616E, 0x62656E, 0x656779, 0x656B20, 0x656C20, - 0x656C65, 0x656D20, 0x656E20, 0x657265, 0x657420, 0x657465, 0x657474, 0x677920, 0x686F67, 0x696E74, 0x697320, 0x6B2061, 0x6BF67A, 0x6D6567, 0x6D696E, 0x6E2061, - 0x6E616B, 0x6E656B, 0x6E656D, 0x6E7420, 0x6F6779, 0x732061, 0x737A65, 0x737A74, 0x737AE1, 0x73E967, 0x742061, 0x747420, 0x74E173, 0x7A6572, 0xE16E20, 0xE97320, -} - -var ngrams_8859_2_pl = [64]uint32{ - 0x20637A, 0x20646F, 0x206920, 0x206A65, 0x206B6F, 0x206D61, 0x206D69, 0x206E61, 0x206E69, 0x206F64, 0x20706F, 0x207072, 0x207369, 0x207720, 0x207769, 0x207779, - 0x207A20, 0x207A61, 0x612070, 0x612077, 0x616E69, 0x636820, 0x637A65, 0x637A79, 0x646F20, 0x647A69, 0x652070, 0x652073, 0x652077, 0x65207A, 0x65676F, 0x656A20, - 0x656D20, 0x656E69, 0x676F20, 0x696120, 0x696520, 0x69656A, 0x6B6120, 0x6B6920, 0x6B6965, 0x6D6965, 0x6E6120, 0x6E6961, 0x6E6965, 0x6F2070, 0x6F7761, 0x6F7769, - 0x706F6C, 0x707261, 0x70726F, 0x70727A, 0x727A65, 0x727A79, 0x7369EA, 0x736B69, 0x737461, 0x776965, 0x796368, 0x796D20, 0x7A6520, 0x7A6965, 0x7A7920, 0xF37720, -} - -var ngrams_8859_2_ro = [64]uint32{ - 0x206120, 0x206163, 0x206361, 0x206365, 0x20636F, 0x206375, 0x206465, 0x206469, 0x206C61, 0x206D61, 0x207065, 0x207072, 0x207365, 0x2073E3, 0x20756E, 0x20BA69, - 0x20EE6E, 0x612063, 0x612064, 0x617265, 0x617420, 0x617465, 0x617520, 0x636172, 0x636F6E, 0x637520, 0x63E320, 0x646520, 0x652061, 0x652063, 0x652064, 0x652070, - 0x652073, 0x656120, 0x656920, 0x656C65, 0x656E74, 0x657374, 0x692061, 0x692063, 0x692064, 0x692070, 0x696520, 0x696920, 0x696E20, 0x6C6120, 0x6C6520, 0x6C6F72, - 0x6C7569, 0x6E6520, 0x6E7472, 0x6F7220, 0x70656E, 0x726520, 0x726561, 0x727520, 0x73E320, 0x746520, 0x747275, 0x74E320, 0x756920, 0x756C20, 0xBA6920, 0xEE6E20, -} - -func newRecognizer_8859_2(language string, ngram *[64]uint32) *recognizerSingleByte { - return &recognizerSingleByte{ - charset: "ISO-8859-2", - hasC1ByteCharset: "windows-1250", - language: language, - charMap: &charMap_8859_2, - ngram: ngram, - } -} - -func newRecognizer_8859_2_cs() *recognizerSingleByte { - return newRecognizer_8859_2("cs", &ngrams_8859_2_cs) -} -func newRecognizer_8859_2_hu() *recognizerSingleByte { - return newRecognizer_8859_2("hu", &ngrams_8859_2_hu) -} -func newRecognizer_8859_2_pl() *recognizerSingleByte { - return newRecognizer_8859_2("pl", &ngrams_8859_2_pl) -} -func newRecognizer_8859_2_ro() *recognizerSingleByte { - return newRecognizer_8859_2("ro", &ngrams_8859_2_ro) -} - -var charMap_8859_5 = [256]byte{ - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, - 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, - 0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, - 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, - 0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, - 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0x20, 0xFE, 0xFF, - 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, - 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, - 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, - 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, - 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, - 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, - 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, - 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, - 0x20, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, - 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0x20, 0xFE, 0xFF, -} - -var ngrams_8859_5_ru = [64]uint32{ - 0x20D220, 0x20D2DE, 0x20D4DE, 0x20D7D0, 0x20D820, 0x20DAD0, 0x20DADE, 0x20DDD0, 0x20DDD5, 0x20DED1, 0x20DFDE, 0x20DFE0, 0x20E0D0, 0x20E1DE, 0x20E1E2, 0x20E2DE, - 0x20E7E2, 0x20EDE2, 0xD0DDD8, 0xD0E2EC, 0xD3DE20, 0xD5DBEC, 0xD5DDD8, 0xD5E1E2, 0xD5E220, 0xD820DF, 0xD8D520, 0xD8D820, 0xD8EF20, 0xDBD5DD, 0xDBD820, 0xDBECDD, - 0xDDD020, 0xDDD520, 0xDDD8D5, 0xDDD8EF, 0xDDDE20, 0xDDDED2, 0xDE20D2, 0xDE20DF, 0xDE20E1, 0xDED220, 0xDED2D0, 0xDED3DE, 0xDED920, 0xDEDBEC, 0xDEDC20, 0xDEE1E2, - 0xDFDEDB, 0xDFE0D5, 0xDFE0D8, 0xDFE0DE, 0xE0D0D2, 0xE0D5D4, 0xE1E2D0, 0xE1E2D2, 0xE1E2D8, 0xE1EF20, 0xE2D5DB, 0xE2DE20, 0xE2DEE0, 0xE2EC20, 0xE7E2DE, 0xEBE520, -} - -func newRecognizer_8859_5(language string, ngram *[64]uint32) *recognizerSingleByte { - return &recognizerSingleByte{ - charset: "ISO-8859-5", - language: language, - charMap: &charMap_8859_5, - ngram: ngram, - } -} - -func newRecognizer_8859_5_ru() *recognizerSingleByte { - return newRecognizer_8859_5("ru", &ngrams_8859_5_ru) -} - -var charMap_8859_6 = [256]byte{ - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, - 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, - 0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, - 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, - 0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, - 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, - 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, - 0xD8, 0xD9, 0xDA, 0x20, 0x20, 0x20, 0x20, 0x20, - 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, - 0xE8, 0xE9, 0xEA, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, -} - -var ngrams_8859_6_ar = [64]uint32{ - 0x20C7E4, 0x20C7E6, 0x20C8C7, 0x20D9E4, 0x20E1EA, 0x20E4E4, 0x20E5E6, 0x20E8C7, 0xC720C7, 0xC7C120, 0xC7CA20, 0xC7D120, 0xC7E420, 0xC7E4C3, 0xC7E4C7, 0xC7E4C8, - 0xC7E4CA, 0xC7E4CC, 0xC7E4CD, 0xC7E4CF, 0xC7E4D3, 0xC7E4D9, 0xC7E4E2, 0xC7E4E5, 0xC7E4E8, 0xC7E4EA, 0xC7E520, 0xC7E620, 0xC7E6CA, 0xC820C7, 0xC920C7, 0xC920E1, - 0xC920E4, 0xC920E5, 0xC920E8, 0xCA20C7, 0xCF20C7, 0xCFC920, 0xD120C7, 0xD1C920, 0xD320C7, 0xD920C7, 0xD9E4E9, 0xE1EA20, 0xE420C7, 0xE4C920, 0xE4E920, 0xE4EA20, - 0xE520C7, 0xE5C720, 0xE5C920, 0xE5E620, 0xE620C7, 0xE720C7, 0xE7C720, 0xE8C7E4, 0xE8E620, 0xE920C7, 0xEA20C7, 0xEA20E5, 0xEA20E8, 0xEAC920, 0xEAD120, 0xEAE620, -} - -func newRecognizer_8859_6(language string, ngram *[64]uint32) *recognizerSingleByte { - return &recognizerSingleByte{ - charset: "ISO-8859-6", - language: language, - charMap: &charMap_8859_6, - ngram: ngram, - } -} - -func newRecognizer_8859_6_ar() *recognizerSingleByte { - return newRecognizer_8859_6("ar", &ngrams_8859_6_ar) -} - -var charMap_8859_7 = [256]byte{ - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, - 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, - 0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, - 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, - 0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0xA1, 0xA2, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0xDC, 0x20, - 0xDD, 0xDE, 0xDF, 0x20, 0xFC, 0x20, 0xFD, 0xFE, - 0xC0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, - 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, - 0xF0, 0xF1, 0x20, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, - 0xF8, 0xF9, 0xFA, 0xFB, 0xDC, 0xDD, 0xDE, 0xDF, - 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, - 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, - 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, - 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0x20, -} - -var ngrams_8859_7_el = [64]uint32{ - 0x20E1ED, 0x20E1F0, 0x20E3E9, 0x20E4E9, 0x20E5F0, 0x20E720, 0x20EAE1, 0x20ECE5, 0x20EDE1, 0x20EF20, 0x20F0E1, 0x20F0EF, 0x20F0F1, 0x20F3F4, 0x20F3F5, 0x20F4E7, - 0x20F4EF, 0xDFE120, 0xE120E1, 0xE120F4, 0xE1E920, 0xE1ED20, 0xE1F0FC, 0xE1F220, 0xE3E9E1, 0xE5E920, 0xE5F220, 0xE720F4, 0xE7ED20, 0xE7F220, 0xE920F4, 0xE9E120, - 0xE9EADE, 0xE9F220, 0xEAE1E9, 0xEAE1F4, 0xECE520, 0xED20E1, 0xED20E5, 0xED20F0, 0xEDE120, 0xEFF220, 0xEFF520, 0xF0EFF5, 0xF0F1EF, 0xF0FC20, 0xF220E1, 0xF220E5, - 0xF220EA, 0xF220F0, 0xF220F4, 0xF3E520, 0xF3E720, 0xF3F4EF, 0xF4E120, 0xF4E1E9, 0xF4E7ED, 0xF4E7F2, 0xF4E9EA, 0xF4EF20, 0xF4EFF5, 0xF4F9ED, 0xF9ED20, 0xFEED20, -} - -func newRecognizer_8859_7(language string, ngram *[64]uint32) *recognizerSingleByte { - return &recognizerSingleByte{ - charset: "ISO-8859-7", - hasC1ByteCharset: "windows-1253", - language: language, - charMap: &charMap_8859_7, - ngram: ngram, - } -} - -func newRecognizer_8859_7_el() *recognizerSingleByte { - return newRecognizer_8859_7("el", &ngrams_8859_7_el) -} - -var charMap_8859_8 = [256]byte{ - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, - 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, - 0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, - 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, - 0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0xB5, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, - 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, - 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, - 0xF8, 0xF9, 0xFA, 0x20, 0x20, 0x20, 0x20, 0x20, -} - -var ngrams_8859_8_I_he = [64]uint32{ - 0x20E0E5, 0x20E0E7, 0x20E0E9, 0x20E0FA, 0x20E1E9, 0x20E1EE, 0x20E4E0, 0x20E4E5, 0x20E4E9, 0x20E4EE, 0x20E4F2, 0x20E4F9, 0x20E4FA, 0x20ECE0, 0x20ECE4, 0x20EEE0, - 0x20F2EC, 0x20F9EC, 0xE0FA20, 0xE420E0, 0xE420E1, 0xE420E4, 0xE420EC, 0xE420EE, 0xE420F9, 0xE4E5E0, 0xE5E020, 0xE5ED20, 0xE5EF20, 0xE5F820, 0xE5FA20, 0xE920E4, - 0xE9E420, 0xE9E5FA, 0xE9E9ED, 0xE9ED20, 0xE9EF20, 0xE9F820, 0xE9FA20, 0xEC20E0, 0xEC20E4, 0xECE020, 0xECE420, 0xED20E0, 0xED20E1, 0xED20E4, 0xED20EC, 0xED20EE, - 0xED20F9, 0xEEE420, 0xEF20E4, 0xF0E420, 0xF0E920, 0xF0E9ED, 0xF2EC20, 0xF820E4, 0xF8E9ED, 0xF9EC20, 0xFA20E0, 0xFA20E1, 0xFA20E4, 0xFA20EC, 0xFA20EE, 0xFA20F9, -} - -var ngrams_8859_8_he = [64]uint32{ - 0x20E0E5, 0x20E0EC, 0x20E4E9, 0x20E4EC, 0x20E4EE, 0x20E4F0, 0x20E9F0, 0x20ECF2, 0x20ECF9, 0x20EDE5, 0x20EDE9, 0x20EFE5, 0x20EFE9, 0x20F8E5, 0x20F8E9, 0x20FAE0, - 0x20FAE5, 0x20FAE9, 0xE020E4, 0xE020EC, 0xE020ED, 0xE020FA, 0xE0E420, 0xE0E5E4, 0xE0EC20, 0xE0EE20, 0xE120E4, 0xE120ED, 0xE120FA, 0xE420E4, 0xE420E9, 0xE420EC, - 0xE420ED, 0xE420EF, 0xE420F8, 0xE420FA, 0xE4EC20, 0xE5E020, 0xE5E420, 0xE7E020, 0xE9E020, 0xE9E120, 0xE9E420, 0xEC20E4, 0xEC20ED, 0xEC20FA, 0xECF220, 0xECF920, - 0xEDE9E9, 0xEDE9F0, 0xEDE9F8, 0xEE20E4, 0xEE20ED, 0xEE20FA, 0xEEE120, 0xEEE420, 0xF2E420, 0xF920E4, 0xF920ED, 0xF920FA, 0xF9E420, 0xFAE020, 0xFAE420, 0xFAE5E9, -} - -func newRecognizer_8859_8(language string, ngram *[64]uint32) *recognizerSingleByte { - return &recognizerSingleByte{ - charset: "ISO-8859-8", - hasC1ByteCharset: "windows-1255", - language: language, - charMap: &charMap_8859_8, - ngram: ngram, - } -} - -func newRecognizer_8859_8_I_he() *recognizerSingleByte { - r := newRecognizer_8859_8("he", &ngrams_8859_8_I_he) - r.charset = "ISO-8859-8-I" - return r -} - -func newRecognizer_8859_8_he() *recognizerSingleByte { - return newRecognizer_8859_8("he", &ngrams_8859_8_he) -} - -var charMap_8859_9 = [256]byte{ - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, - 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, - 0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, - 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, - 0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0xAA, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0xB5, 0x20, 0x20, - 0x20, 0x20, 0xBA, 0x20, 0x20, 0x20, 0x20, 0x20, - 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, - 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, - 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0x20, - 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0x69, 0xFE, 0xDF, - 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, - 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, - 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0x20, - 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF, -} - -var ngrams_8859_9_tr = [64]uint32{ - 0x206261, 0x206269, 0x206275, 0x206461, 0x206465, 0x206765, 0x206861, 0x20696C, 0x206B61, 0x206B6F, 0x206D61, 0x206F6C, 0x207361, 0x207461, 0x207665, 0x207961, - 0x612062, 0x616B20, 0x616C61, 0x616D61, 0x616E20, 0x616EFD, 0x617220, 0x617261, 0x6172FD, 0x6173FD, 0x617961, 0x626972, 0x646120, 0x646520, 0x646920, 0x652062, - 0x65206B, 0x656469, 0x656E20, 0x657220, 0x657269, 0x657369, 0x696C65, 0x696E20, 0x696E69, 0x697220, 0x6C616E, 0x6C6172, 0x6C6520, 0x6C6572, 0x6E2061, 0x6E2062, - 0x6E206B, 0x6E6461, 0x6E6465, 0x6E6520, 0x6E6920, 0x6E696E, 0x6EFD20, 0x72696E, 0x72FD6E, 0x766520, 0x796120, 0x796F72, 0xFD6E20, 0xFD6E64, 0xFD6EFD, 0xFDF0FD, -} - -func newRecognizer_8859_9(language string, ngram *[64]uint32) *recognizerSingleByte { - return &recognizerSingleByte{ - charset: "ISO-8859-9", - hasC1ByteCharset: "windows-1254", - language: language, - charMap: &charMap_8859_9, - ngram: ngram, - } -} - -func newRecognizer_8859_9_tr() *recognizerSingleByte { - return newRecognizer_8859_9("tr", &ngrams_8859_9_tr) -} - -var charMap_windows_1256 = [256]byte{ - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, - 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, - 0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, - 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, - 0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x81, 0x20, 0x83, 0x20, 0x20, 0x20, 0x20, - 0x88, 0x20, 0x8A, 0x20, 0x9C, 0x8D, 0x8E, 0x8F, - 0x90, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x98, 0x20, 0x9A, 0x20, 0x9C, 0x20, 0x20, 0x9F, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0xAA, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0xB5, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, - 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, - 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0x20, - 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, - 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, - 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, - 0x20, 0x20, 0x20, 0x20, 0xF4, 0x20, 0x20, 0x20, - 0x20, 0xF9, 0x20, 0xFB, 0xFC, 0x20, 0x20, 0xFF, -} - -var ngrams_windows_1256 = [64]uint32{ - 0x20C7E1, 0x20C7E4, 0x20C8C7, 0x20DAE1, 0x20DDED, 0x20E1E1, 0x20E3E4, 0x20E6C7, 0xC720C7, 0xC7C120, 0xC7CA20, 0xC7D120, 0xC7E120, 0xC7E1C3, 0xC7E1C7, 0xC7E1C8, - 0xC7E1CA, 0xC7E1CC, 0xC7E1CD, 0xC7E1CF, 0xC7E1D3, 0xC7E1DA, 0xC7E1DE, 0xC7E1E3, 0xC7E1E6, 0xC7E1ED, 0xC7E320, 0xC7E420, 0xC7E4CA, 0xC820C7, 0xC920C7, 0xC920DD, - 0xC920E1, 0xC920E3, 0xC920E6, 0xCA20C7, 0xCF20C7, 0xCFC920, 0xD120C7, 0xD1C920, 0xD320C7, 0xDA20C7, 0xDAE1EC, 0xDDED20, 0xE120C7, 0xE1C920, 0xE1EC20, 0xE1ED20, - 0xE320C7, 0xE3C720, 0xE3C920, 0xE3E420, 0xE420C7, 0xE520C7, 0xE5C720, 0xE6C7E1, 0xE6E420, 0xEC20C7, 0xED20C7, 0xED20E3, 0xED20E6, 0xEDC920, 0xEDD120, 0xEDE420, -} - -func newRecognizer_windows_1256() *recognizerSingleByte { - return &recognizerSingleByte{ - charset: "windows-1256", - language: "ar", - charMap: &charMap_windows_1256, - ngram: &ngrams_windows_1256, - } -} - -var charMap_windows_1251 = [256]byte{ - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, - 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, - 0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, - 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, - 0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x90, 0x83, 0x20, 0x83, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x9A, 0x20, 0x9C, 0x9D, 0x9E, 0x9F, - 0x90, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x9A, 0x20, 0x9C, 0x9D, 0x9E, 0x9F, - 0x20, 0xA2, 0xA2, 0xBC, 0x20, 0xB4, 0x20, 0x20, - 0xB8, 0x20, 0xBA, 0x20, 0x20, 0x20, 0x20, 0xBF, - 0x20, 0x20, 0xB3, 0xB3, 0xB4, 0xB5, 0x20, 0x20, - 0xB8, 0x20, 0xBA, 0x20, 0xBC, 0xBE, 0xBE, 0xBF, - 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, - 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, - 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, - 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF, - 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, - 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, - 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, - 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF, -} - -var ngrams_windows_1251 = [64]uint32{ - 0x20E220, 0x20E2EE, 0x20E4EE, 0x20E7E0, 0x20E820, 0x20EAE0, 0x20EAEE, 0x20EDE0, 0x20EDE5, 0x20EEE1, 0x20EFEE, 0x20EFF0, 0x20F0E0, 0x20F1EE, 0x20F1F2, 0x20F2EE, - 0x20F7F2, 0x20FDF2, 0xE0EDE8, 0xE0F2FC, 0xE3EE20, 0xE5EBFC, 0xE5EDE8, 0xE5F1F2, 0xE5F220, 0xE820EF, 0xE8E520, 0xE8E820, 0xE8FF20, 0xEBE5ED, 0xEBE820, 0xEBFCED, - 0xEDE020, 0xEDE520, 0xEDE8E5, 0xEDE8FF, 0xEDEE20, 0xEDEEE2, 0xEE20E2, 0xEE20EF, 0xEE20F1, 0xEEE220, 0xEEE2E0, 0xEEE3EE, 0xEEE920, 0xEEEBFC, 0xEEEC20, 0xEEF1F2, - 0xEFEEEB, 0xEFF0E5, 0xEFF0E8, 0xEFF0EE, 0xF0E0E2, 0xF0E5E4, 0xF1F2E0, 0xF1F2E2, 0xF1F2E8, 0xF1FF20, 0xF2E5EB, 0xF2EE20, 0xF2EEF0, 0xF2FC20, 0xF7F2EE, 0xFBF520, -} - -func newRecognizer_windows_1251() *recognizerSingleByte { - return &recognizerSingleByte{ - charset: "windows-1251", - language: "ar", - charMap: &charMap_windows_1251, - ngram: &ngrams_windows_1251, - } -} - -var charMap_KOI8_R = [256]byte{ - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, - 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, - 0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, - 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, - 0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0xA3, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0xA3, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, - 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, - 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, - 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, - 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, - 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, - 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, - 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, -} - -var ngrams_KOI8_R = [64]uint32{ - 0x20C4CF, 0x20C920, 0x20CBC1, 0x20CBCF, 0x20CEC1, 0x20CEC5, 0x20CFC2, 0x20D0CF, 0x20D0D2, 0x20D2C1, 0x20D3CF, 0x20D3D4, 0x20D4CF, 0x20D720, 0x20D7CF, 0x20DAC1, - 0x20DCD4, 0x20DED4, 0xC1CEC9, 0xC1D4D8, 0xC5CCD8, 0xC5CEC9, 0xC5D3D4, 0xC5D420, 0xC7CF20, 0xC920D0, 0xC9C520, 0xC9C920, 0xC9D120, 0xCCC5CE, 0xCCC920, 0xCCD8CE, - 0xCEC120, 0xCEC520, 0xCEC9C5, 0xCEC9D1, 0xCECF20, 0xCECFD7, 0xCF20D0, 0xCF20D3, 0xCF20D7, 0xCFC7CF, 0xCFCA20, 0xCFCCD8, 0xCFCD20, 0xCFD3D4, 0xCFD720, 0xCFD7C1, - 0xD0CFCC, 0xD0D2C5, 0xD0D2C9, 0xD0D2CF, 0xD2C1D7, 0xD2C5C4, 0xD3D120, 0xD3D4C1, 0xD3D4C9, 0xD3D4D7, 0xD4C5CC, 0xD4CF20, 0xD4CFD2, 0xD4D820, 0xD9C820, 0xDED4CF, -} - -func newRecognizer_KOI8_R() *recognizerSingleByte { - return &recognizerSingleByte{ - charset: "KOI8-R", - language: "ru", - charMap: &charMap_KOI8_R, - ngram: &ngrams_KOI8_R, - } -} - -var charMap_IBM424_he = [256]byte{ - /* -0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -A -B -C -D -E -F */ - /* 0- */ 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, - /* 1- */ 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, - /* 2- */ 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, - /* 3- */ 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, - /* 4- */ 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, - /* 5- */ 0x40, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, - /* 6- */ 0x40, 0x40, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, - /* 7- */ 0x40, 0x71, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, 0x40, 0x40, - /* 8- */ 0x40, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, - /* 9- */ 0x40, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, - /* A- */ 0xA0, 0x40, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, - /* B- */ 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, - /* C- */ 0x40, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, - /* D- */ 0x40, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, - /* E- */ 0x40, 0x40, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, - /* F- */ 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, -} - -var ngrams_IBM424_he_rtl = [64]uint32{ - 0x404146, 0x404148, 0x404151, 0x404171, 0x404251, 0x404256, 0x404541, 0x404546, 0x404551, 0x404556, 0x404562, 0x404569, 0x404571, 0x405441, 0x405445, 0x405641, - 0x406254, 0x406954, 0x417140, 0x454041, 0x454042, 0x454045, 0x454054, 0x454056, 0x454069, 0x454641, 0x464140, 0x465540, 0x465740, 0x466840, 0x467140, 0x514045, - 0x514540, 0x514671, 0x515155, 0x515540, 0x515740, 0x516840, 0x517140, 0x544041, 0x544045, 0x544140, 0x544540, 0x554041, 0x554042, 0x554045, 0x554054, 0x554056, - 0x554069, 0x564540, 0x574045, 0x584540, 0x585140, 0x585155, 0x625440, 0x684045, 0x685155, 0x695440, 0x714041, 0x714042, 0x714045, 0x714054, 0x714056, 0x714069, -} - -var ngrams_IBM424_he_ltr = [64]uint32{ - 0x404146, 0x404154, 0x404551, 0x404554, 0x404556, 0x404558, 0x405158, 0x405462, 0x405469, 0x405546, 0x405551, 0x405746, 0x405751, 0x406846, 0x406851, 0x407141, - 0x407146, 0x407151, 0x414045, 0x414054, 0x414055, 0x414071, 0x414540, 0x414645, 0x415440, 0x415640, 0x424045, 0x424055, 0x424071, 0x454045, 0x454051, 0x454054, - 0x454055, 0x454057, 0x454068, 0x454071, 0x455440, 0x464140, 0x464540, 0x484140, 0x514140, 0x514240, 0x514540, 0x544045, 0x544055, 0x544071, 0x546240, 0x546940, - 0x555151, 0x555158, 0x555168, 0x564045, 0x564055, 0x564071, 0x564240, 0x564540, 0x624540, 0x694045, 0x694055, 0x694071, 0x694540, 0x714140, 0x714540, 0x714651, -} - -func newRecognizer_IBM424_he(charset string, ngram *[64]uint32) *recognizerSingleByte { - return &recognizerSingleByte{ - charset: charset, - language: "he", - charMap: &charMap_IBM424_he, - ngram: ngram, - } -} - -func newRecognizer_IBM424_he_rtl() *recognizerSingleByte { - return newRecognizer_IBM424_he("IBM424_rtl", &ngrams_IBM424_he_rtl) -} - -func newRecognizer_IBM424_he_ltr() *recognizerSingleByte { - return newRecognizer_IBM424_he("IBM424_ltr", &ngrams_IBM424_he_ltr) -} - -var charMap_IBM420_ar = [256]byte{ - /* -0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -A -B -C -D -E -F */ - /* 0- */ 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, - /* 1- */ 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, - /* 2- */ 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, - /* 3- */ 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, - /* 4- */ 0x40, 0x40, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, - /* 5- */ 0x40, 0x51, 0x52, 0x40, 0x40, 0x55, 0x56, 0x57, 0x58, 0x59, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, - /* 6- */ 0x40, 0x40, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, - /* 7- */ 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, - /* 8- */ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, - /* 9- */ 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F, - /* A- */ 0xA0, 0x40, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, - /* B- */ 0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0x40, 0x40, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF, - /* C- */ 0x40, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x40, 0xCB, 0x40, 0xCD, 0x40, 0xCF, - /* D- */ 0x40, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, - /* E- */ 0x40, 0x40, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xEA, 0xEB, 0x40, 0xED, 0xEE, 0xEF, - /* F- */ 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0xFB, 0xFC, 0xFD, 0xFE, 0x40, -} - -var ngrams_IBM420_ar_rtl = [64]uint32{ - 0x4056B1, 0x4056BD, 0x405856, 0x409AB1, 0x40ABDC, 0x40B1B1, 0x40BBBD, 0x40CF56, 0x564056, 0x564640, 0x566340, 0x567540, 0x56B140, 0x56B149, 0x56B156, 0x56B158, - 0x56B163, 0x56B167, 0x56B169, 0x56B173, 0x56B178, 0x56B19A, 0x56B1AD, 0x56B1BB, 0x56B1CF, 0x56B1DC, 0x56BB40, 0x56BD40, 0x56BD63, 0x584056, 0x624056, 0x6240AB, - 0x6240B1, 0x6240BB, 0x6240CF, 0x634056, 0x734056, 0x736240, 0x754056, 0x756240, 0x784056, 0x9A4056, 0x9AB1DA, 0xABDC40, 0xB14056, 0xB16240, 0xB1DA40, 0xB1DC40, - 0xBB4056, 0xBB5640, 0xBB6240, 0xBBBD40, 0xBD4056, 0xBF4056, 0xBF5640, 0xCF56B1, 0xCFBD40, 0xDA4056, 0xDC4056, 0xDC40BB, 0xDC40CF, 0xDC6240, 0xDC7540, 0xDCBD40, -} - -var ngrams_IBM420_ar_ltr = [64]uint32{ - 0x404656, 0x4056BB, 0x4056BF, 0x406273, 0x406275, 0x4062B1, 0x4062BB, 0x4062DC, 0x406356, 0x407556, 0x4075DC, 0x40B156, 0x40BB56, 0x40BD56, 0x40BDBB, 0x40BDCF, - 0x40BDDC, 0x40DAB1, 0x40DCAB, 0x40DCB1, 0x49B156, 0x564056, 0x564058, 0x564062, 0x564063, 0x564073, 0x564075, 0x564078, 0x56409A, 0x5640B1, 0x5640BB, 0x5640BD, - 0x5640BF, 0x5640DA, 0x5640DC, 0x565840, 0x56B156, 0x56CF40, 0x58B156, 0x63B156, 0x63BD56, 0x67B156, 0x69B156, 0x73B156, 0x78B156, 0x9AB156, 0xAB4062, 0xADB156, - 0xB14062, 0xB15640, 0xB156CF, 0xB19A40, 0xB1B140, 0xBB4062, 0xBB40DC, 0xBBB156, 0xBD5640, 0xBDBB40, 0xCF4062, 0xCF40DC, 0xCFB156, 0xDAB19A, 0xDCAB40, 0xDCB156, -} - -func newRecognizer_IBM420_ar(charset string, ngram *[64]uint32) *recognizerSingleByte { - return &recognizerSingleByte{ - charset: charset, - language: "ar", - charMap: &charMap_IBM420_ar, - ngram: ngram, - } -} - -func newRecognizer_IBM420_ar_rtl() *recognizerSingleByte { - return newRecognizer_IBM420_ar("IBM420_rtl", &ngrams_IBM420_ar_rtl) -} - -func newRecognizer_IBM420_ar_ltr() *recognizerSingleByte { - return newRecognizer_IBM420_ar("IBM420_ltr", &ngrams_IBM420_ar_ltr) -} diff --git a/vendor/github.com/gogits/chardet/unicode.go b/vendor/github.com/gogits/chardet/unicode.go deleted file mode 100644 index 6f9fa9e6..00000000 --- a/vendor/github.com/gogits/chardet/unicode.go +++ /dev/null @@ -1,103 +0,0 @@ -package chardet - -import ( - "bytes" -) - -var ( - utf16beBom = []byte{0xFE, 0xFF} - utf16leBom = []byte{0xFF, 0xFE} - utf32beBom = []byte{0x00, 0x00, 0xFE, 0xFF} - utf32leBom = []byte{0xFF, 0xFE, 0x00, 0x00} -) - -type recognizerUtf16be struct { -} - -func newRecognizer_utf16be() *recognizerUtf16be { - return &recognizerUtf16be{} -} - -func (*recognizerUtf16be) Match(input *recognizerInput) (output recognizerOutput) { - output = recognizerOutput{ - Charset: "UTF-16BE", - } - if bytes.HasPrefix(input.raw, utf16beBom) { - output.Confidence = 100 - } - return -} - -type recognizerUtf16le struct { -} - -func newRecognizer_utf16le() *recognizerUtf16le { - return &recognizerUtf16le{} -} - -func (*recognizerUtf16le) Match(input *recognizerInput) (output recognizerOutput) { - output = recognizerOutput{ - Charset: "UTF-16LE", - } - if bytes.HasPrefix(input.raw, utf16leBom) && !bytes.HasPrefix(input.raw, utf32leBom) { - output.Confidence = 100 - } - return -} - -type recognizerUtf32 struct { - name string - bom []byte - decodeChar func(input []byte) uint32 -} - -func decodeUtf32be(input []byte) uint32 { - return uint32(input[0])<<24 | uint32(input[1])<<16 | uint32(input[2])<<8 | uint32(input[3]) -} - -func decodeUtf32le(input []byte) uint32 { - return uint32(input[3])<<24 | uint32(input[2])<<16 | uint32(input[1])<<8 | uint32(input[0]) -} - -func newRecognizer_utf32be() *recognizerUtf32 { - return &recognizerUtf32{ - "UTF-32BE", - utf32beBom, - decodeUtf32be, - } -} - -func newRecognizer_utf32le() *recognizerUtf32 { - return &recognizerUtf32{ - "UTF-32LE", - utf32leBom, - decodeUtf32le, - } -} - -func (r *recognizerUtf32) Match(input *recognizerInput) (output recognizerOutput) { - output = recognizerOutput{ - Charset: r.name, - } - hasBom := bytes.HasPrefix(input.raw, r.bom) - var numValid, numInvalid uint32 - for b := input.raw; len(b) >= 4; b = b[4:] { - if c := r.decodeChar(b); c >= 0x10FFFF || (c >= 0xD800 && c <= 0xDFFF) { - numInvalid++ - } else { - numValid++ - } - } - if hasBom && numInvalid == 0 { - output.Confidence = 100 - } else if hasBom && numValid > numInvalid*10 { - output.Confidence = 80 - } else if numValid > 3 && numInvalid == 0 { - output.Confidence = 100 - } else if numValid > 0 && numInvalid == 0 { - output.Confidence = 80 - } else if numValid > numInvalid*10 { - output.Confidence = 25 - } - return -} diff --git a/vendor/github.com/gogits/chardet/utf8.go b/vendor/github.com/gogits/chardet/utf8.go deleted file mode 100644 index ae036ad9..00000000 --- a/vendor/github.com/gogits/chardet/utf8.go +++ /dev/null @@ -1,71 +0,0 @@ -package chardet - -import ( - "bytes" -) - -var utf8Bom = []byte{0xEF, 0xBB, 0xBF} - -type recognizerUtf8 struct { -} - -func newRecognizer_utf8() *recognizerUtf8 { - return &recognizerUtf8{} -} - -func (*recognizerUtf8) Match(input *recognizerInput) (output recognizerOutput) { - output = recognizerOutput{ - Charset: "UTF-8", - } - hasBom := bytes.HasPrefix(input.raw, utf8Bom) - inputLen := len(input.raw) - var numValid, numInvalid uint32 - var trailBytes uint8 - for i := 0; i < inputLen; i++ { - c := input.raw[i] - if c&0x80 == 0 { - continue - } - if c&0xE0 == 0xC0 { - trailBytes = 1 - } else if c&0xF0 == 0xE0 { - trailBytes = 2 - } else if c&0xF8 == 0xF0 { - trailBytes = 3 - } else { - numInvalid++ - if numInvalid > 5 { - break - } - trailBytes = 0 - } - - for i++; i < inputLen; i++ { - c = input.raw[i] - if c&0xC0 != 0x80 { - numInvalid++ - break - } - if trailBytes--; trailBytes == 0 { - numValid++ - break - } - } - } - - if hasBom && numInvalid == 0 { - output.Confidence = 100 - } else if hasBom && numValid > numInvalid*10 { - output.Confidence = 80 - } else if numValid > 3 && numInvalid == 0 { - output.Confidence = 100 - } else if numValid > 0 && numInvalid == 0 { - output.Confidence = 80 - } else if numValid == 0 && numInvalid == 0 { - // Plain ASCII - output.Confidence = 10 - } else if numValid > numInvalid*10 { - output.Confidence = 25 - } - return -} diff --git a/vendor/github.com/gogits/cron/LICENSE b/vendor/github.com/gogits/cron/LICENSE deleted file mode 100644 index 3a0f627f..00000000 --- a/vendor/github.com/gogits/cron/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -Copyright (C) 2012 Rob Figueiredo -All Rights Reserved. - -MIT LICENSE - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/vendor/github.com/gogits/cron/README.md b/vendor/github.com/gogits/cron/README.md deleted file mode 100644 index 157ed082..00000000 --- a/vendor/github.com/gogits/cron/README.md +++ /dev/null @@ -1,2 +0,0 @@ -[![GoDoc](http://godoc.org/github.com/robfig/cron?status.png)](http://godoc.org/github.com/robfig/cron) -[![Build Status](https://travis-ci.org/robfig/cron.svg?branch=master)](https://travis-ci.org/robfig/cron) diff --git a/vendor/github.com/gogits/cron/constantdelay.go b/vendor/github.com/gogits/cron/constantdelay.go deleted file mode 100644 index cd6e7b1b..00000000 --- a/vendor/github.com/gogits/cron/constantdelay.go +++ /dev/null @@ -1,27 +0,0 @@ -package cron - -import "time" - -// ConstantDelaySchedule represents a simple recurring duty cycle, e.g. "Every 5 minutes". -// It does not support jobs more frequent than once a second. -type ConstantDelaySchedule struct { - Delay time.Duration -} - -// Every returns a crontab Schedule that activates once every duration. -// Delays of less than a second are not supported (will round up to 1 second). -// Any fields less than a Second are truncated. -func Every(duration time.Duration) ConstantDelaySchedule { - if duration < time.Second { - duration = time.Second - } - return ConstantDelaySchedule{ - Delay: duration - time.Duration(duration.Nanoseconds())%time.Second, - } -} - -// Next returns the next time this should be run. -// This rounds so that the next activation time will be on the second. -func (schedule ConstantDelaySchedule) Next(t time.Time) time.Time { - return t.Add(schedule.Delay - time.Duration(t.Nanosecond())*time.Nanosecond) -} diff --git a/vendor/github.com/gogits/cron/cron.go b/vendor/github.com/gogits/cron/cron.go deleted file mode 100644 index ed6ad21c..00000000 --- a/vendor/github.com/gogits/cron/cron.go +++ /dev/null @@ -1,243 +0,0 @@ -// This library implements a cron spec parser and runner. See the README for -// more details. -package cron - -import ( - "log" - "runtime" - "sort" - "time" -) - -// Cron keeps track of any number of entries, invoking the associated func as -// specified by the schedule. It may be started, stopped, and the entries may -// be inspected while running. -type Cron struct { - entries []*Entry - stop chan struct{} - add chan *Entry - snapshot chan []*Entry - running bool - ErrorLog *log.Logger -} - -// Job is an interface for submitted cron jobs. -type Job interface { - Run() -} - -// The Schedule describes a job's duty cycle. -type Schedule interface { - // Return the next activation time, later than the given time. - // Next is invoked initially, and then each time the job is run. - Next(time.Time) time.Time -} - -// Entry consists of a schedule and the func to execute on that schedule. -type Entry struct { - Description string - Spec string - - // The schedule on which this job should be run. - Schedule Schedule - - // The next time the job will run. This is the zero time if Cron has not been - // started or this entry's schedule is unsatisfiable - Next time.Time - - // The last time this job was run. This is the zero time if the job has never - // been run. - Prev time.Time - - // The Job to run. - Job Job - - ExecTimes int // Execute times count. -} - -// byTime is a wrapper for sorting the entry array by time -// (with zero time at the end). -type byTime []*Entry - -func (s byTime) Len() int { return len(s) } -func (s byTime) Swap(i, j int) { s[i], s[j] = s[j], s[i] } -func (s byTime) Less(i, j int) bool { - // Two zero times should return false. - // Otherwise, zero is "greater" than any other time. - // (To sort it at the end of the list.) - if s[i].Next.IsZero() { - return false - } - if s[j].Next.IsZero() { - return true - } - return s[i].Next.Before(s[j].Next) -} - -// New returns a new Cron job runner. -func New() *Cron { - return &Cron{ - entries: nil, - add: make(chan *Entry), - stop: make(chan struct{}), - snapshot: make(chan []*Entry), - running: false, - ErrorLog: nil, - } -} - -// A wrapper that turns a func() into a cron.Job -type FuncJob func() - -func (f FuncJob) Run() { f() } - -// AddFunc adds a func to the Cron to be run on the given schedule. -func (c *Cron) AddFunc(desc, spec string, cmd func()) (*Entry, error) { - return c.AddJob(desc, spec, FuncJob(cmd)) -} - -// AddJob adds a Job to the Cron to be run on the given schedule. -func (c *Cron) AddJob(desc, spec string, cmd Job) (*Entry, error) { - schedule, err := Parse(spec) - if err != nil { - return nil, err - } - return c.Schedule(desc, spec, schedule, cmd), nil -} - -// Schedule adds a Job to the Cron to be run on the given schedule. -func (c *Cron) Schedule(desc, spec string, schedule Schedule, cmd Job) *Entry { - entry := &Entry{ - Description: desc, - Spec: spec, - Schedule: schedule, - Job: cmd, - } - if c.running { - c.add <- entry - } else { - c.entries = append(c.entries, entry) - } - return entry -} - -// Entries returns a snapshot of the cron entries. -func (c *Cron) Entries() []*Entry { - if c.running { - c.snapshot <- nil - x := <-c.snapshot - return x - } - return c.entrySnapshot() -} - -// Start the cron scheduler in its own go-routine, or no-op if already started. -func (c *Cron) Start() { - if c.running { - return - } - c.running = true - go c.run() -} - -func (c *Cron) runWithRecovery(j Job) { - defer func() { - if r := recover(); r != nil { - const size = 64 << 10 - buf := make([]byte, size) - buf = buf[:runtime.Stack(buf, false)] - c.logf("cron: panic running job: %v\n%s", r, buf) - } - }() - j.Run() -} - -// Run the scheduler.. this is private just due to the need to synchronize -// access to the 'running' state variable. -func (c *Cron) run() { - // Figure out the next activation times for each entry. - now := time.Now().Local() - for _, entry := range c.entries { - entry.Next = entry.Schedule.Next(now) - } - - for { - // Determine the next entry to run. - sort.Sort(byTime(c.entries)) - - var effective time.Time - if len(c.entries) == 0 || c.entries[0].Next.IsZero() { - // If there are no entries yet, just sleep - it still handles new entries - // and stop requests. - effective = now.AddDate(10, 0, 0) - } else { - effective = c.entries[0].Next - } - - timer := time.NewTimer(effective.Sub(now)) - select { - case now = <-timer.C: - // Run every entry whose next time was this effective time. - for _, e := range c.entries { - if e.Next != effective { - break - } - go c.runWithRecovery(e.Job) - e.ExecTimes++ - e.Prev = e.Next - e.Next = e.Schedule.Next(now) - } - continue - - case newEntry := <-c.add: - c.entries = append(c.entries, newEntry) - newEntry.Next = newEntry.Schedule.Next(time.Now().Local()) - - case <-c.snapshot: - c.snapshot <- c.entrySnapshot() - - case <-c.stop: - timer.Stop() - return - } - - // 'now' should be updated after newEntry and snapshot cases. - now = time.Now().Local() - timer.Stop() - } -} - -// Logs an error to stderr or to the configured error log -func (c *Cron) logf(format string, args ...interface{}) { - if c.ErrorLog != nil { - c.ErrorLog.Printf(format, args...) - } else { - log.Printf(format, args...) - } -} - -// Stop stops the cron scheduler if it is running; otherwise it does nothing. -func (c *Cron) Stop() { - if !c.running { - return - } - c.stop <- struct{}{} - c.running = false -} - -// entrySnapshot returns a copy of the current cron entry list. -func (c *Cron) entrySnapshot() []*Entry { - entries := []*Entry{} - for _, e := range c.entries { - entries = append(entries, &Entry{ - Description: e.Description, - Spec: e.Spec, - Schedule: e.Schedule, - Next: e.Next, - Prev: e.Prev, - Job: e.Job, - ExecTimes: e.ExecTimes, - }) - } - return entries -} diff --git a/vendor/github.com/gogits/cron/doc.go b/vendor/github.com/gogits/cron/doc.go deleted file mode 100644 index dbdf5012..00000000 --- a/vendor/github.com/gogits/cron/doc.go +++ /dev/null @@ -1,129 +0,0 @@ -/* -Package cron implements a cron spec parser and job runner. - -Usage - -Callers may register Funcs to be invoked on a given schedule. Cron will run -them in their own goroutines. - - c := cron.New() - c.AddFunc("0 30 * * * *", func() { fmt.Println("Every hour on the half hour") }) - c.AddFunc("@hourly", func() { fmt.Println("Every hour") }) - c.AddFunc("@every 1h30m", func() { fmt.Println("Every hour thirty") }) - c.Start() - .. - // Funcs are invoked in their own goroutine, asynchronously. - ... - // Funcs may also be added to a running Cron - c.AddFunc("@daily", func() { fmt.Println("Every day") }) - .. - // Inspect the cron job entries' next and previous run times. - inspect(c.Entries()) - .. - c.Stop() // Stop the scheduler (does not stop any jobs already running). - -CRON Expression Format - -A cron expression represents a set of times, using 6 space-separated fields. - - Field name | Mandatory? | Allowed values | Allowed special characters - ---------- | ---------- | -------------- | -------------------------- - Seconds | Yes | 0-59 | * / , - - Minutes | Yes | 0-59 | * / , - - Hours | Yes | 0-23 | * / , - - Day of month | Yes | 1-31 | * / , - ? - Month | Yes | 1-12 or JAN-DEC | * / , - - Day of week | Yes | 0-6 or SUN-SAT | * / , - ? - -Note: Month and Day-of-week field values are case insensitive. "SUN", "Sun", -and "sun" are equally accepted. - -Special Characters - -Asterisk ( * ) - -The asterisk indicates that the cron expression will match for all values of the -field; e.g., using an asterisk in the 5th field (month) would indicate every -month. - -Slash ( / ) - -Slashes are used to describe increments of ranges. For example 3-59/15 in the -1st field (minutes) would indicate the 3rd minute of the hour and every 15 -minutes thereafter. The form "*\/..." is equivalent to the form "first-last/...", -that is, an increment over the largest possible range of the field. The form -"N/..." is accepted as meaning "N-MAX/...", that is, starting at N, use the -increment until the end of that specific range. It does not wrap around. - -Comma ( , ) - -Commas are used to separate items of a list. For example, using "MON,WED,FRI" in -the 5th field (day of week) would mean Mondays, Wednesdays and Fridays. - -Hyphen ( - ) - -Hyphens are used to define ranges. For example, 9-17 would indicate every -hour between 9am and 5pm inclusive. - -Question mark ( ? ) - -Question mark may be used instead of '*' for leaving either day-of-month or -day-of-week blank. - -Predefined schedules - -You may use one of several pre-defined schedules in place of a cron expression. - - Entry | Description | Equivalent To - ----- | ----------- | ------------- - @yearly (or @annually) | Run once a year, midnight, Jan. 1st | 0 0 0 1 1 * - @monthly | Run once a month, midnight, first of month | 0 0 0 1 * * - @weekly | Run once a week, midnight on Sunday | 0 0 0 * * 0 - @daily (or @midnight) | Run once a day, midnight | 0 0 0 * * * - @hourly | Run once an hour, beginning of hour | 0 0 * * * * - -Intervals - -You may also schedule a job to execute at fixed intervals. This is supported by -formatting the cron spec like this: - - @every - -where "duration" is a string accepted by time.ParseDuration -(http://golang.org/pkg/time/#ParseDuration). - -For example, "@every 1h30m10s" would indicate a schedule that activates every -1 hour, 30 minutes, 10 seconds. - -Note: The interval does not take the job runtime into account. For example, -if a job takes 3 minutes to run, and it is scheduled to run every 5 minutes, -it will have only 2 minutes of idle time between each run. - -Time zones - -All interpretation and scheduling is done in the machine's local time zone (as -provided by the Go time package (http://www.golang.org/pkg/time). - -Be aware that jobs scheduled during daylight-savings leap-ahead transitions will -not be run! - -Thread safety - -Since the Cron service runs concurrently with the calling code, some amount of -care must be taken to ensure proper synchronization. - -All cron methods are designed to be correctly synchronized as long as the caller -ensures that invocations have a clear happens-before ordering between them. - -Implementation - -Cron entries are stored in an array, sorted by their next activation time. Cron -sleeps until the next job is due to be run. - -Upon waking: - - it runs each entry that is active on that second - - it calculates the next run times for the jobs that were run - - it re-sorts the array of entries by next activation time. - - it goes to sleep until the soonest job. -*/ -package cron diff --git a/vendor/github.com/gogits/cron/parser.go b/vendor/github.com/gogits/cron/parser.go deleted file mode 100644 index fd217c92..00000000 --- a/vendor/github.com/gogits/cron/parser.go +++ /dev/null @@ -1,234 +0,0 @@ -package cron - -import ( - "fmt" - "log" - "math" - "strconv" - "strings" - "time" -) - -// Parse returns a new crontab schedule representing the given spec. -// It returns a descriptive error if the spec is not valid. -// -// It accepts -// - Full crontab specs, e.g. "* * * * * ?" -// - Descriptors, e.g. "@midnight", "@every 1h30m" -func Parse(spec string) (_ Schedule, err error) { - // Convert panics into errors - defer func() { - if recovered := recover(); recovered != nil { - err = fmt.Errorf("%v", recovered) - } - }() - - if spec[0] == '@' { - return parseDescriptor(spec), nil - } - - // Split on whitespace. We require 5 or 6 fields. - // (second) (minute) (hour) (day of month) (month) (day of week, optional) - fields := strings.Fields(spec) - if len(fields) != 5 && len(fields) != 6 { - log.Panicf("Expected 5 or 6 fields, found %d: %s", len(fields), spec) - } - - // If a sixth field is not provided (DayOfWeek), then it is equivalent to star. - if len(fields) == 5 { - fields = append(fields, "*") - } - - schedule := &SpecSchedule{ - Second: getField(fields[0], seconds), - Minute: getField(fields[1], minutes), - Hour: getField(fields[2], hours), - Dom: getField(fields[3], dom), - Month: getField(fields[4], months), - Dow: getField(fields[5], dow), - } - - return schedule, nil -} - -// getField returns an Int with the bits set representing all of the times that -// the field represents. A "field" is a comma-separated list of "ranges". -func getField(field string, r bounds) uint64 { - // list = range {"," range} - var bits uint64 - ranges := strings.FieldsFunc(field, func(r rune) bool { return r == ',' }) - for _, expr := range ranges { - bits |= getRange(expr, r) - } - return bits -} - -// getRange returns the bits indicated by the given expression: -// number | number "-" number [ "/" number ] -func getRange(expr string, r bounds) uint64 { - - var ( - start, end, step uint - rangeAndStep = strings.Split(expr, "/") - lowAndHigh = strings.Split(rangeAndStep[0], "-") - singleDigit = len(lowAndHigh) == 1 - ) - - var extra_star uint64 - if lowAndHigh[0] == "*" || lowAndHigh[0] == "?" { - start = r.min - end = r.max - extra_star = starBit - } else { - start = parseIntOrName(lowAndHigh[0], r.names) - switch len(lowAndHigh) { - case 1: - end = start - case 2: - end = parseIntOrName(lowAndHigh[1], r.names) - default: - log.Panicf("Too many hyphens: %s", expr) - } - } - - switch len(rangeAndStep) { - case 1: - step = 1 - case 2: - step = mustParseInt(rangeAndStep[1]) - - // Special handling: "N/step" means "N-max/step". - if singleDigit { - end = r.max - } - default: - log.Panicf("Too many slashes: %s", expr) - } - - if start < r.min { - log.Panicf("Beginning of range (%d) below minimum (%d): %s", start, r.min, expr) - } - if end > r.max { - log.Panicf("End of range (%d) above maximum (%d): %s", end, r.max, expr) - } - if start > end { - log.Panicf("Beginning of range (%d) beyond end of range (%d): %s", start, end, expr) - } - if step == 0 { - log.Panicf("Step of range should be a positive number: %s", expr) - } - - return getBits(start, end, step) | extra_star -} - -// parseIntOrName returns the (possibly-named) integer contained in expr. -func parseIntOrName(expr string, names map[string]uint) uint { - if names != nil { - if namedInt, ok := names[strings.ToLower(expr)]; ok { - return namedInt - } - } - return mustParseInt(expr) -} - -// mustParseInt parses the given expression as an int or panics. -func mustParseInt(expr string) uint { - num, err := strconv.Atoi(expr) - if err != nil { - log.Panicf("Failed to parse int from %s: %s", expr, err) - } - if num < 0 { - log.Panicf("Negative number (%d) not allowed: %s", num, expr) - } - - return uint(num) -} - -// getBits sets all bits in the range [min, max], modulo the given step size. -func getBits(min, max, step uint) uint64 { - var bits uint64 - - // If step is 1, use shifts. - if step == 1 { - return ^(math.MaxUint64 << (max + 1)) & (math.MaxUint64 << min) - } - - // Else, use a simple loop. - for i := min; i <= max; i += step { - bits |= 1 << i - } - return bits -} - -// all returns all bits within the given bounds. (plus the star bit) -func all(r bounds) uint64 { - return getBits(r.min, r.max, 1) | starBit -} - -// parseDescriptor returns a pre-defined schedule for the expression, or panics -// if none matches. -func parseDescriptor(spec string) Schedule { - switch spec { - case "@yearly", "@annually": - return &SpecSchedule{ - Second: 1 << seconds.min, - Minute: 1 << minutes.min, - Hour: 1 << hours.min, - Dom: 1 << dom.min, - Month: 1 << months.min, - Dow: all(dow), - } - - case "@monthly": - return &SpecSchedule{ - Second: 1 << seconds.min, - Minute: 1 << minutes.min, - Hour: 1 << hours.min, - Dom: 1 << dom.min, - Month: all(months), - Dow: all(dow), - } - - case "@weekly": - return &SpecSchedule{ - Second: 1 << seconds.min, - Minute: 1 << minutes.min, - Hour: 1 << hours.min, - Dom: all(dom), - Month: all(months), - Dow: 1 << dow.min, - } - - case "@daily", "@midnight": - return &SpecSchedule{ - Second: 1 << seconds.min, - Minute: 1 << minutes.min, - Hour: 1 << hours.min, - Dom: all(dom), - Month: all(months), - Dow: all(dow), - } - - case "@hourly": - return &SpecSchedule{ - Second: 1 << seconds.min, - Minute: 1 << minutes.min, - Hour: all(hours), - Dom: all(dom), - Month: all(months), - Dow: all(dow), - } - } - - const every = "@every " - if strings.HasPrefix(spec, every) { - duration, err := time.ParseDuration(spec[len(every):]) - if err != nil { - log.Panicf("Failed to parse duration %s: %s", spec, err) - } - return Every(duration) - } - - log.Panicf("Unrecognized descriptor: %s", spec) - return nil -} diff --git a/vendor/github.com/gogits/cron/spec.go b/vendor/github.com/gogits/cron/spec.go deleted file mode 100644 index 2b541269..00000000 --- a/vendor/github.com/gogits/cron/spec.go +++ /dev/null @@ -1,159 +0,0 @@ -package cron - -import "time" - -// SpecSchedule specifies a duty cycle (to the second granularity), based on a -// traditional crontab specification. It is computed initially and stored as bit sets. -type SpecSchedule struct { - Second, Minute, Hour, Dom, Month, Dow uint64 -} - -// bounds provides a range of acceptable values (plus a map of name to value). -type bounds struct { - min, max uint - names map[string]uint -} - -// The bounds for each field. -var ( - seconds = bounds{0, 59, nil} - minutes = bounds{0, 59, nil} - hours = bounds{0, 23, nil} - dom = bounds{1, 31, nil} - months = bounds{1, 12, map[string]uint{ - "jan": 1, - "feb": 2, - "mar": 3, - "apr": 4, - "may": 5, - "jun": 6, - "jul": 7, - "aug": 8, - "sep": 9, - "oct": 10, - "nov": 11, - "dec": 12, - }} - dow = bounds{0, 6, map[string]uint{ - "sun": 0, - "mon": 1, - "tue": 2, - "wed": 3, - "thu": 4, - "fri": 5, - "sat": 6, - }} -) - -const ( - // Set the top bit if a star was included in the expression. - starBit = 1 << 63 -) - -// Next returns the next time this schedule is activated, greater than the given -// time. If no time can be found to satisfy the schedule, return the zero time. -func (s *SpecSchedule) Next(t time.Time) time.Time { - // General approach: - // For Month, Day, Hour, Minute, Second: - // Check if the time value matches. If yes, continue to the next field. - // If the field doesn't match the schedule, then increment the field until it matches. - // While incrementing the field, a wrap-around brings it back to the beginning - // of the field list (since it is necessary to re-verify previous field - // values) - - // Start at the earliest possible time (the upcoming second). - t = t.Add(1*time.Second - time.Duration(t.Nanosecond())*time.Nanosecond) - - // This flag indicates whether a field has been incremented. - added := false - - // If no time is found within five years, return zero. - yearLimit := t.Year() + 5 - -WRAP: - if t.Year() > yearLimit { - return time.Time{} - } - - // Find the first applicable month. - // If it's this month, then do nothing. - for 1< 0 - dowMatch bool = 1< 0 - ) - - if s.Dom&starBit > 0 || s.Dow&starBit > 0 { - return domMatch && dowMatch - } - return domMatch || dowMatch -} diff --git a/vendor/github.com/gogits/git-module/LICENSE b/vendor/github.com/gogits/git-module/LICENSE deleted file mode 100644 index 176d8dfe..00000000 --- a/vendor/github.com/gogits/git-module/LICENSE +++ /dev/null @@ -1,19 +0,0 @@ -Copyright (c) 2015 All Gogs Contributors - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. \ No newline at end of file diff --git a/vendor/github.com/gogits/git-module/README.md b/vendor/github.com/gogits/git-module/README.md deleted file mode 100644 index f9569ceb..00000000 --- a/vendor/github.com/gogits/git-module/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# Git Module [![Build Status](https://travis-ci.org/gogits/git-module.svg?branch=master)](https://travis-ci.org/gogits/git-module) - -Package git-module is a Go module for Git access through shell commands. - -## Limitations - -- Go version must be at least **1.4**. -- Git version must be no less than **1.7.1**, and greater than or equal to **1.8.3** is recommended. -- For Windows users, try use as new a version as possible. - -## License - -This project is under the MIT License. See the [LICENSE](LICENSE) file for the full license text. diff --git a/vendor/github.com/gogits/git-module/blob.go b/vendor/github.com/gogits/git-module/blob.go deleted file mode 100644 index 7731226d..00000000 --- a/vendor/github.com/gogits/git-module/blob.go +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2015 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package git - -import ( - "bytes" - "io" -) - -// Blob represents a Git object. -type Blob struct { - repo *Repository - *TreeEntry -} - -// Data gets content of blob all at once and wrap it as io.Reader. -// This can be very slow and memory consuming for huge content. -func (b *Blob) Data() (io.Reader, error) { - stdout := new(bytes.Buffer) - stderr := new(bytes.Buffer) - - // Preallocate memory to save ~50% memory usage on big files. - stdout.Grow(int(b.Size() + 2048)) - - if err := b.DataPipeline(stdout, stderr); err != nil { - return nil, concatenateError(err, stderr.String()) - } - return stdout, nil -} - -func (b *Blob) DataPipeline(stdout, stderr io.Writer) error { - return NewCommand("show", b.ID.String()).RunInDirPipeline(b.repo.Path, stdout, stderr) -} diff --git a/vendor/github.com/gogits/git-module/command.go b/vendor/github.com/gogits/git-module/command.go deleted file mode 100644 index 80caea08..00000000 --- a/vendor/github.com/gogits/git-module/command.go +++ /dev/null @@ -1,150 +0,0 @@ -// Copyright 2015 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package git - -import ( - "bytes" - "fmt" - "io" - "os" - "os/exec" - "strings" - "time" -) - -// Command represents a command with its subcommands or arguments. -type Command struct { - name string - args []string - envs []string -} - -func (c *Command) String() string { - if len(c.args) == 0 { - return c.name - } - return fmt.Sprintf("%s %s", c.name, strings.Join(c.args, " ")) -} - -// NewCommand creates and returns a new Git Command based on given command and arguments. -func NewCommand(args ...string) *Command { - return &Command{ - name: "git", - args: args, - } -} - -// AddArguments adds new argument(s) to the command. -func (c *Command) AddArguments(args ...string) *Command { - c.args = append(c.args, args...) - return c -} - -// AddEnvs adds new environment variables to the command. -func (c *Command) AddEnvs(envs ...string) *Command { - c.envs = append(c.envs, envs...) - return c -} - -const DEFAULT_TIMEOUT = 60 * time.Second - -// RunInDirTimeoutPipeline executes the command in given directory with given timeout, -// it pipes stdout and stderr to given io.Writer. -func (c *Command) RunInDirTimeoutPipeline(timeout time.Duration, dir string, stdout, stderr io.Writer) error { - if timeout == -1 { - timeout = DEFAULT_TIMEOUT - } - - if len(dir) == 0 { - log(c.String()) - } else { - log("%s: %v", dir, c) - } - - cmd := exec.Command(c.name, c.args...) - if c.envs != nil { - cmd.Env = append(os.Environ(), c.envs...) - } - cmd.Dir = dir - cmd.Stdout = stdout - cmd.Stderr = stderr - if err := cmd.Start(); err != nil { - return err - } - - done := make(chan error) - go func() { - done <- cmd.Wait() - }() - - var err error - select { - case <-time.After(timeout): - if cmd.Process != nil && cmd.ProcessState != nil && !cmd.ProcessState.Exited() { - if err := cmd.Process.Kill(); err != nil { - return fmt.Errorf("fail to kill process: %v", err) - } - } - - <-done - return ErrExecTimeout{timeout} - case err = <-done: - } - - return err -} - -// RunInDirTimeout executes the command in given directory with given timeout, -// and returns stdout in []byte and error (combined with stderr). -func (c *Command) RunInDirTimeout(timeout time.Duration, dir string) ([]byte, error) { - stdout := new(bytes.Buffer) - stderr := new(bytes.Buffer) - if err := c.RunInDirTimeoutPipeline(timeout, dir, stdout, stderr); err != nil { - return nil, concatenateError(err, stderr.String()) - } - - if stdout.Len() > 0 { - log("stdout:\n%s", stdout.Bytes()[:1024]) - } - return stdout.Bytes(), nil -} - -// RunInDirPipeline executes the command in given directory, -// it pipes stdout and stderr to given io.Writer. -func (c *Command) RunInDirPipeline(dir string, stdout, stderr io.Writer) error { - return c.RunInDirTimeoutPipeline(-1, dir, stdout, stderr) -} - -// RunInDir executes the command in given directory -// and returns stdout in []byte and error (combined with stderr). -func (c *Command) RunInDirBytes(dir string) ([]byte, error) { - return c.RunInDirTimeout(-1, dir) -} - -// RunInDir executes the command in given directory -// and returns stdout in string and error (combined with stderr). -func (c *Command) RunInDir(dir string) (string, error) { - stdout, err := c.RunInDirTimeout(-1, dir) - if err != nil { - return "", err - } - return string(stdout), nil -} - -// RunTimeout executes the command in defualt working directory with given timeout, -// and returns stdout in string and error (combined with stderr). -func (c *Command) RunTimeout(timeout time.Duration) (string, error) { - stdout, err := c.RunInDirTimeout(timeout, "") - if err != nil { - return "", err - } - return string(stdout), nil -} - -// Run executes the command in defualt working directory -// and returns stdout in string and error (combined with stderr). -func (c *Command) Run() (string, error) { - return c.RunTimeout(-1) -} diff --git a/vendor/github.com/gogits/git-module/commit.go b/vendor/github.com/gogits/git-module/commit.go deleted file mode 100644 index 64831d7f..00000000 --- a/vendor/github.com/gogits/git-module/commit.go +++ /dev/null @@ -1,310 +0,0 @@ -// Copyright 2015 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package git - -import ( - "bufio" - "bytes" - "container/list" - "fmt" - "io" - "net/http" - "strconv" - "strings" - - "github.com/mcuadros/go-version" -) - -// Commit represents a git commit. -type Commit struct { - Tree - ID sha1 // The ID of this commit object - Author *Signature - Committer *Signature - CommitMessage string - - parents []sha1 // SHA1 strings - submoduleCache *objectCache -} - -// Message returns the commit message. Same as retrieving CommitMessage directly. -func (c *Commit) Message() string { - return c.CommitMessage -} - -// Summary returns first line of commit message. -func (c *Commit) Summary() string { - return strings.Split(c.CommitMessage, "\n")[0] -} - -// ParentID returns oid of n-th parent (0-based index). -// It returns nil if no such parent exists. -func (c *Commit) ParentID(n int) (sha1, error) { - if n >= len(c.parents) { - return sha1{}, ErrNotExist{"", ""} - } - return c.parents[n], nil -} - -// Parent returns n-th parent (0-based index) of the commit. -func (c *Commit) Parent(n int) (*Commit, error) { - id, err := c.ParentID(n) - if err != nil { - return nil, err - } - parent, err := c.repo.getCommit(id) - if err != nil { - return nil, err - } - return parent, nil -} - -// ParentCount returns number of parents of the commit. -// 0 if this is the root commit, otherwise 1,2, etc. -func (c *Commit) ParentCount() int { - return len(c.parents) -} - -func isImageFile(data []byte) (string, bool) { - contentType := http.DetectContentType(data) - if strings.Index(contentType, "image/") != -1 { - return contentType, true - } - return contentType, false -} - -func (c *Commit) IsImageFile(name string) bool { - blob, err := c.GetBlobByPath(name) - if err != nil { - return false - } - - dataRc, err := blob.Data() - if err != nil { - return false - } - buf := make([]byte, 1024) - n, _ := dataRc.Read(buf) - buf = buf[:n] - _, isImage := isImageFile(buf) - return isImage -} - -// GetCommitByPath return the commit of relative path object. -func (c *Commit) GetCommitByPath(relpath string) (*Commit, error) { - return c.repo.getCommitByPathWithID(c.ID, relpath) -} - -// AddAllChanges marks local changes to be ready for commit. -func AddChanges(repoPath string, all bool, files ...string) error { - cmd := NewCommand("add") - if all { - cmd.AddArguments("--all") - } - _, err := cmd.AddArguments(files...).RunInDir(repoPath) - return err -} - -type CommitChangesOptions struct { - Committer *Signature - Author *Signature - Message string -} - -// CommitChanges commits local changes with given committer, author and message. -// If author is nil, it will be the same as committer. -func CommitChanges(repoPath string, opts CommitChangesOptions) error { - cmd := NewCommand() - if opts.Committer != nil { - cmd.AddEnvs("GIT_COMMITTER_NAME="+opts.Committer.Name, "GIT_COMMITTER_EMAIL="+opts.Committer.Email) - } - cmd.AddArguments("commit") - - if opts.Author == nil { - opts.Author = opts.Committer - } - if opts.Author != nil { - cmd.AddArguments(fmt.Sprintf("--author='%s <%s>'", opts.Author.Name, opts.Author.Email)) - } - cmd.AddArguments("-m", opts.Message) - - _, err := cmd.RunInDir(repoPath) - // No stderr but exit status 1 means nothing to commit. - if err != nil && err.Error() == "exit status 1" { - return nil - } - return err -} - -func commitsCount(repoPath, revision, relpath string) (int64, error) { - var cmd *Command - isFallback := false - if version.Compare(gitVersion, "1.8.0", "<") { - isFallback = true - cmd = NewCommand("log", "--pretty=format:''") - } else { - cmd = NewCommand("rev-list", "--count") - } - cmd.AddArguments(revision) - if len(relpath) > 0 { - cmd.AddArguments("--", relpath) - } - - stdout, err := cmd.RunInDir(repoPath) - if err != nil { - return 0, err - } - - if isFallback { - return int64(strings.Count(stdout, "\n")) + 1, nil - } - return strconv.ParseInt(strings.TrimSpace(stdout), 10, 64) -} - -// CommitsCount returns number of total commits of until given revision. -func CommitsCount(repoPath, revision string) (int64, error) { - return commitsCount(repoPath, revision, "") -} - -func (c *Commit) CommitsCount() (int64, error) { - return CommitsCount(c.repo.Path, c.ID.String()) -} - -func (c *Commit) CommitsByRangeSize(page, size int) (*list.List, error) { - return c.repo.CommitsByRangeSize(c.ID.String(), page, size) -} - -func (c *Commit) CommitsByRange(page int) (*list.List, error) { - return c.repo.CommitsByRange(c.ID.String(), page) -} - -func (c *Commit) CommitsBefore() (*list.List, error) { - return c.repo.getCommitsBefore(c.ID) -} - -func (c *Commit) CommitsBeforeLimit(num int) (*list.List, error) { - return c.repo.getCommitsBeforeLimit(c.ID, num) -} - -func (c *Commit) CommitsBeforeUntil(commitID string) (*list.List, error) { - endCommit, err := c.repo.GetCommit(commitID) - if err != nil { - return nil, err - } - return c.repo.CommitsBetween(c, endCommit) -} - -func (c *Commit) SearchCommits(keyword string) (*list.List, error) { - return c.repo.searchCommits(c.ID, keyword) -} - -func (c *Commit) GetFilesChangedSinceCommit(pastCommit string) ([]string, error) { - return c.repo.getFilesChanged(pastCommit, c.ID.String()) -} - -func (c *Commit) GetSubModules() (*objectCache, error) { - if c.submoduleCache != nil { - return c.submoduleCache, nil - } - - entry, err := c.GetTreeEntryByPath(".gitmodules") - if err != nil { - return nil, err - } - rd, err := entry.Blob().Data() - if err != nil { - return nil, err - } - - scanner := bufio.NewScanner(rd) - c.submoduleCache = newObjectCache() - var ismodule bool - var path string - for scanner.Scan() { - if strings.HasPrefix(scanner.Text(), "[submodule") { - ismodule = true - continue - } - if ismodule { - fields := strings.Split(scanner.Text(), "=") - k := strings.TrimSpace(fields[0]) - if k == "path" { - path = strings.TrimSpace(fields[1]) - } else if k == "url" { - c.submoduleCache.Set(path, &SubModule{path, strings.TrimSpace(fields[1])}) - ismodule = false - } - } - } - - return c.submoduleCache, nil -} - -func (c *Commit) GetSubModule(entryname string) (*SubModule, error) { - modules, err := c.GetSubModules() - if err != nil { - return nil, err - } - - module, has := modules.Get(entryname) - if has { - return module.(*SubModule), nil - } - return nil, nil -} - -// CommitFileStatus represents status of files in a commit. -type CommitFileStatus struct { - Added []string - Removed []string - Modified []string -} - -func NewCommitFileStatus() *CommitFileStatus { - return &CommitFileStatus{ - []string{}, []string{}, []string{}, - } -} - -// GetCommitFileStatus returns file status of commit in given repository. -func GetCommitFileStatus(repoPath, commitID string) (*CommitFileStatus, error) { - stdout, w := io.Pipe() - done := make(chan struct{}) - fileStatus := NewCommitFileStatus() - go func() { - scanner := bufio.NewScanner(stdout) - for scanner.Scan() { - fields := strings.Fields(scanner.Text()) - if len(fields) < 2 { - continue - } - - switch fields[0][0] { - case 'A': - fileStatus.Added = append(fileStatus.Added, fields[1]) - case 'D': - fileStatus.Removed = append(fileStatus.Removed, fields[1]) - case 'M': - fileStatus.Modified = append(fileStatus.Modified, fields[1]) - } - } - done <- struct{}{} - }() - - stderr := new(bytes.Buffer) - err := NewCommand("log", "-1", "--name-status", "--pretty=format:''", commitID).RunInDirPipeline(repoPath, w, stderr) - w.Close() // Close writer to exit parsing goroutine - if err != nil { - return nil, concatenateError(err, stderr.String()) - } - - <-done - return fileStatus, nil -} - -// FileStatus returns file status of commit. -func (c *Commit) FileStatus() (*CommitFileStatus, error) { - return GetCommitFileStatus(c.repo.Path, c.ID.String()) -} diff --git a/vendor/github.com/gogits/git-module/commit_archive.go b/vendor/github.com/gogits/git-module/commit_archive.go deleted file mode 100644 index 1066ba69..00000000 --- a/vendor/github.com/gogits/git-module/commit_archive.go +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2015 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package git - -import ( - "fmt" - "path/filepath" - "strings" -) - -type ArchiveType int - -const ( - ZIP ArchiveType = iota + 1 - TARGZ -) - -func (c *Commit) CreateArchive(target string, archiveType ArchiveType) error { - var format string - switch archiveType { - case ZIP: - format = "zip" - case TARGZ: - format = "tar.gz" - default: - return fmt.Errorf("unknown format: %v", archiveType) - } - - _, err := NewCommand("archive", "--prefix="+filepath.Base(strings.TrimSuffix(c.repo.Path, ".git"))+"/", "--format="+format, "-o", target, c.ID.String()).RunInDir(c.repo.Path) - return err -} diff --git a/vendor/github.com/gogits/git-module/error.go b/vendor/github.com/gogits/git-module/error.go deleted file mode 100644 index 2fefaa1e..00000000 --- a/vendor/github.com/gogits/git-module/error.go +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright 2015 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package git - -import ( - "fmt" - "time" -) - -type ErrExecTimeout struct { - Duration time.Duration -} - -func IsErrExecTimeout(err error) bool { - _, ok := err.(ErrExecTimeout) - return ok -} - -func (err ErrExecTimeout) Error() string { - return fmt.Sprintf("execution is timeout [duration: %v]", err.Duration) -} - -type ErrNotExist struct { - ID string - RelPath string -} - -func IsErrNotExist(err error) bool { - _, ok := err.(ErrNotExist) - return ok -} - -func (err ErrNotExist) Error() string { - return fmt.Sprintf("object does not exist [id: %s, rel_path: %s]", err.ID, err.RelPath) -} - -type ErrUnsupportedVersion struct { - Required string -} - -func IsErrUnsupportedVersion(err error) bool { - _, ok := err.(ErrUnsupportedVersion) - return ok -} - -func (err ErrUnsupportedVersion) Error() string { - return fmt.Sprintf("Operation requires higher version [required: %s]", err.Required) -} - -type ErrNoMergeBase struct{} - -func IsErrNoMergeBase(err error) bool { - _, ok := err.(ErrNoMergeBase) - return ok -} - -func (err ErrNoMergeBase) Error() string { - return "no merge based found" -} diff --git a/vendor/github.com/gogits/git-module/git.go b/vendor/github.com/gogits/git-module/git.go deleted file mode 100644 index 414d67cd..00000000 --- a/vendor/github.com/gogits/git-module/git.go +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2015 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package git - -import ( - "fmt" - "strings" - "time" -) - -const _VERSION = "0.6.4" - -func Version() string { - return _VERSION -} - -var ( - // Debug enables verbose logging on everything. - // This should be false in case Gogs starts in SSH mode. - Debug = false - Prefix = "[git-module] " -) - -func log(format string, args ...interface{}) { - if !Debug { - return - } - - fmt.Print(Prefix) - if len(args) == 0 { - fmt.Println(format) - } else { - fmt.Printf(format+"\n", args...) - } -} - -var gitVersion string - -// Version returns current Git version from shell. -func BinVersion() (string, error) { - if len(gitVersion) > 0 { - return gitVersion, nil - } - - stdout, err := NewCommand("version").Run() - if err != nil { - return "", err - } - - fields := strings.Fields(stdout) - if len(fields) < 3 { - return "", fmt.Errorf("not enough output: %s", stdout) - } - - // Handle special case on Windows. - i := strings.Index(fields[2], "windows") - if i >= 1 { - gitVersion = fields[2][:i-1] - return gitVersion, nil - } - - gitVersion = fields[2] - return gitVersion, nil -} - -func init() { - BinVersion() -} - -// Fsck verifies the connectivity and validity of the objects in the database -func Fsck(repoPath string, timeout time.Duration, args ...string) error { - // Make sure timeout makes sense. - if timeout <= 0 { - timeout = -1 - } - _, err := NewCommand("fsck").AddArguments(args...).RunInDirTimeout(timeout, repoPath) - return err -} diff --git a/vendor/github.com/gogits/git-module/hook.go b/vendor/github.com/gogits/git-module/hook.go deleted file mode 100644 index a0d0b16b..00000000 --- a/vendor/github.com/gogits/git-module/hook.go +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright 2015 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package git - -import ( - "errors" - "io/ioutil" - "os" - "path" - "strings" -) - -var ( - // Direcotry of hook and sample files. Can be changed to "custom_hooks" for very purpose. - HookDir = "hooks" - HookSampleDir = HookDir - // HookNames is a list of Git server hooks' name that are supported. - HookNames = []string{ - "pre-receive", - "update", - "post-receive", - } -) - -var ( - ErrNotValidHook = errors.New("not a valid Git hook") -) - -// IsValidHookName returns true if given name is a valid Git hook. -func IsValidHookName(name string) bool { - for _, hn := range HookNames { - if hn == name { - return true - } - } - return false -} - -// Hook represents a Git hook. -type Hook struct { - name string - IsActive bool // Indicates whether repository has this hook. - Content string // Content of hook if it's active. - Sample string // Sample content from Git. - path string // Hook file path. -} - -// GetHook returns a Git hook by given name and repository. -func GetHook(repoPath, name string) (*Hook, error) { - if !IsValidHookName(name) { - return nil, ErrNotValidHook - } - h := &Hook{ - name: name, - path: path.Join(repoPath, HookDir, name), - } - if isFile(h.path) { - data, err := ioutil.ReadFile(h.path) - if err != nil { - return nil, err - } - h.IsActive = true - h.Content = string(data) - return h, nil - } - - // Check sample file - samplePath := path.Join(repoPath, HookSampleDir, h.name) + ".sample" - if isFile(samplePath) { - data, err := ioutil.ReadFile(samplePath) - if err != nil { - return nil, err - } - h.Sample = string(data) - } - return h, nil -} - -func (h *Hook) Name() string { - return h.name -} - -// Update updates content hook file. -func (h *Hook) Update() error { - if len(strings.TrimSpace(h.Content)) == 0 { - if isExist(h.path) { - return os.Remove(h.path) - } - return nil - } - os.MkdirAll(path.Dir(h.path), os.ModePerm) - return ioutil.WriteFile(h.path, []byte(strings.Replace(h.Content, "\r", "", -1)), os.ModePerm) -} - -// ListHooks returns a list of Git hooks of given repository. -func ListHooks(repoPath string) (_ []*Hook, err error) { - if !isDir(path.Join(repoPath, "hooks")) { - return nil, errors.New("hooks path does not exist") - } - - hooks := make([]*Hook, len(HookNames)) - for i, name := range HookNames { - hooks[i], err = GetHook(repoPath, name) - if err != nil { - return nil, err - } - } - return hooks, nil -} diff --git a/vendor/github.com/gogits/git-module/repo.go b/vendor/github.com/gogits/git-module/repo.go deleted file mode 100644 index ca4805f5..00000000 --- a/vendor/github.com/gogits/git-module/repo.go +++ /dev/null @@ -1,295 +0,0 @@ -// Copyright 2015 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package git - -import ( - "bytes" - "container/list" - "errors" - "os" - "path" - "path/filepath" - "strings" - "time" - - "github.com/Unknwon/com" -) - -// Repository represents a Git repository. -type Repository struct { - Path string - - commitCache *objectCache - tagCache *objectCache -} - -const _PRETTY_LOG_FORMAT = `--pretty=format:%H` - -func (repo *Repository) parsePrettyFormatLogToList(logs []byte) (*list.List, error) { - l := list.New() - if len(logs) == 0 { - return l, nil - } - - parts := bytes.Split(logs, []byte{'\n'}) - - for _, commitId := range parts { - commit, err := repo.GetCommit(string(commitId)) - if err != nil { - return nil, err - } - l.PushBack(commit) - } - - return l, nil -} - -type NetworkOptions struct { - URL string - Timeout time.Duration -} - -// IsRepoURLAccessible checks if given repository URL is accessible. -func IsRepoURLAccessible(opts NetworkOptions) bool { - cmd := NewCommand("ls-remote", "-q", "-h", opts.URL, "HEAD") - if opts.Timeout <= 0 { - opts.Timeout = -1 - } - _, err := cmd.RunTimeout(opts.Timeout) - if err != nil { - return false - } - return true -} - -// InitRepository initializes a new Git repository. -func InitRepository(repoPath string, bare bool) error { - os.MkdirAll(repoPath, os.ModePerm) - - cmd := NewCommand("init") - if bare { - cmd.AddArguments("--bare") - } - _, err := cmd.RunInDir(repoPath) - return err -} - -// OpenRepository opens the repository at the given path. -func OpenRepository(repoPath string) (*Repository, error) { - repoPath, err := filepath.Abs(repoPath) - if err != nil { - return nil, err - } else if !isDir(repoPath) { - return nil, errors.New("no such file or directory") - } - - return &Repository{ - Path: repoPath, - commitCache: newObjectCache(), - tagCache: newObjectCache(), - }, nil -} - -type CloneRepoOptions struct { - Mirror bool - Bare bool - Quiet bool - Branch string - Timeout time.Duration -} - -// Clone clones original repository to target path. -func Clone(from, to string, opts CloneRepoOptions) (err error) { - toDir := path.Dir(to) - if err = os.MkdirAll(toDir, os.ModePerm); err != nil { - return err - } - - cmd := NewCommand("clone") - if opts.Mirror { - cmd.AddArguments("--mirror") - } - if opts.Bare { - cmd.AddArguments("--bare") - } - if opts.Quiet { - cmd.AddArguments("--quiet") - } - if len(opts.Branch) > 0 { - cmd.AddArguments("-b", opts.Branch) - } - cmd.AddArguments(from, to) - - if opts.Timeout <= 0 { - opts.Timeout = -1 - } - _, err = cmd.RunTimeout(opts.Timeout) - return err -} - -type FetchRemoteOptions struct { - Prune bool - Timeout time.Duration -} - -// Fetch fetches changes from remotes without merging. -func Fetch(repoPath string, opts FetchRemoteOptions) error { - cmd := NewCommand("fetch") - if opts.Prune { - cmd.AddArguments("--prune") - } - - if opts.Timeout <= 0 { - opts.Timeout = -1 - } - _, err := cmd.RunInDirTimeout(opts.Timeout, repoPath) - return err -} - -type PullRemoteOptions struct { - All bool - Rebase bool - Remote string - Branch string - Timeout time.Duration -} - -// Pull pulls changes from remotes. -func Pull(repoPath string, opts PullRemoteOptions) error { - cmd := NewCommand("pull") - if opts.Rebase { - cmd.AddArguments("--rebase") - } - if opts.All { - cmd.AddArguments("--all") - } else { - cmd.AddArguments(opts.Remote) - cmd.AddArguments(opts.Branch) - } - - if opts.Timeout <= 0 { - opts.Timeout = -1 - } - _, err := cmd.RunInDirTimeout(opts.Timeout, repoPath) - return err -} - -// Push pushs local commits to given remote branch. -func Push(repoPath, remote, branch string) error { - _, err := NewCommand("push", remote, branch).RunInDir(repoPath) - return err -} - -type CheckoutOptions struct { - Branch string - OldBranch string - Timeout time.Duration -} - -// Checkout checkouts a branch -func Checkout(repoPath string, opts CheckoutOptions) error { - cmd := NewCommand("checkout") - if len(opts.OldBranch) > 0 { - cmd.AddArguments("-b") - } - - cmd.AddArguments(opts.Branch) - - if len(opts.OldBranch) > 0 { - cmd.AddArguments(opts.OldBranch) - } - if opts.Timeout <= 0 { - opts.Timeout = -1 - } - _, err := cmd.RunInDirTimeout(opts.Timeout, repoPath) - return err -} - -// ResetHEAD resets HEAD to given revision or head of branch. -func ResetHEAD(repoPath string, hard bool, revision string) error { - cmd := NewCommand("reset") - if hard { - cmd.AddArguments("--hard") - } - _, err := cmd.AddArguments(revision).RunInDir(repoPath) - return err -} - -// MoveFile moves a file to another file or directory. -func MoveFile(repoPath, oldTreeName, newTreeName string) error { - _, err := NewCommand("mv").AddArguments(oldTreeName, newTreeName).RunInDir(repoPath) - return err -} - -// CountObject represents disk usage report of Git repository. -type CountObject struct { - Count int64 - Size int64 - InPack int64 - Packs int64 - SizePack int64 - PrunePackable int64 - Garbage int64 - SizeGarbage int64 -} - -const ( - _STAT_COUNT = "count: " - _STAT_SIZE = "size: " - _STAT_IN_PACK = "in-pack: " - _STAT_PACKS = "packs: " - _STAT_SIZE_PACK = "size-pack: " - _STAT_PRUNE_PACKABLE = "prune-packable: " - _STAT_GARBAGE = "garbage: " - _STAT_SIZE_GARBAGE = "size-garbage: " -) - -// GetRepoSize returns disk usage report of repository in given path. -func GetRepoSize(repoPath string) (*CountObject, error) { - cmd := NewCommand("count-objects", "-v") - stdout, err := cmd.RunInDir(repoPath) - if err != nil { - return nil, err - } - - countObject := new(CountObject) - for _, line := range strings.Split(stdout, "\n") { - switch { - case strings.HasPrefix(line, _STAT_COUNT): - countObject.Count = com.StrTo(line[7:]).MustInt64() - case strings.HasPrefix(line, _STAT_SIZE): - countObject.Size = com.StrTo(line[6:]).MustInt64() * 1024 - case strings.HasPrefix(line, _STAT_IN_PACK): - countObject.InPack = com.StrTo(line[9:]).MustInt64() - case strings.HasPrefix(line, _STAT_PACKS): - countObject.Packs = com.StrTo(line[7:]).MustInt64() - case strings.HasPrefix(line, _STAT_SIZE_PACK): - countObject.SizePack = com.StrTo(line[11:]).MustInt64() * 1024 - case strings.HasPrefix(line, _STAT_PRUNE_PACKABLE): - countObject.PrunePackable = com.StrTo(line[16:]).MustInt64() - case strings.HasPrefix(line, _STAT_GARBAGE): - countObject.Garbage = com.StrTo(line[9:]).MustInt64() - case strings.HasPrefix(line, _STAT_SIZE_GARBAGE): - countObject.SizeGarbage = com.StrTo(line[14:]).MustInt64() * 1024 - } - } - - return countObject, nil -} - -// GetLatestCommitDate returns the date of latest commit of repository. -// If branch is empty, it returns the latest commit across all branches. -func GetLatestCommitDate(repoPath, branch string) (time.Time, error) { - cmd := NewCommand("for-each-ref", "--count=1", "--sort=-committerdate", "--format=%(committerdate:iso8601)") - if len(branch) > 0 { - cmd.AddArguments("refs/heads/" + branch) - } - stdout, err := cmd.RunInDir(repoPath) - if err != nil { - return time.Time{}, err - } - - return time.Parse("2006-01-02 15:04:05 -0700", strings.TrimSpace(stdout)) -} diff --git a/vendor/github.com/gogits/git-module/repo_branch.go b/vendor/github.com/gogits/git-module/repo_branch.go deleted file mode 100644 index de3f6ca1..00000000 --- a/vendor/github.com/gogits/git-module/repo_branch.go +++ /dev/null @@ -1,126 +0,0 @@ -// Copyright 2015 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package git - -import ( - "fmt" - "strings" - - "github.com/mcuadros/go-version" -) - -const BRANCH_PREFIX = "refs/heads/" - -// IsReferenceExist returns true if given reference exists in the repository. -func IsReferenceExist(repoPath, name string) bool { - _, err := NewCommand("show-ref", "--verify", name).RunInDir(repoPath) - return err == nil -} - -// IsBranchExist returns true if given branch exists in the repository. -func IsBranchExist(repoPath, name string) bool { - return IsReferenceExist(repoPath, BRANCH_PREFIX+name) -} - -func (repo *Repository) IsBranchExist(name string) bool { - return IsBranchExist(repo.Path, name) -} - -// Branch represents a Git branch. -type Branch struct { - Name string - Path string -} - -// GetHEADBranch returns corresponding branch of HEAD. -func (repo *Repository) GetHEADBranch() (*Branch, error) { - stdout, err := NewCommand("symbolic-ref", "HEAD").RunInDir(repo.Path) - if err != nil { - return nil, err - } - stdout = strings.TrimSpace(stdout) - - if !strings.HasPrefix(stdout, BRANCH_PREFIX) { - return nil, fmt.Errorf("invalid HEAD branch: %v", stdout) - } - - return &Branch{ - Name: stdout[len(BRANCH_PREFIX):], - Path: stdout, - }, nil -} - -// SetDefaultBranch sets default branch of repository. -func (repo *Repository) SetDefaultBranch(name string) error { - if version.Compare(gitVersion, "1.7.10", "<") { - return ErrUnsupportedVersion{"1.7.10"} - } - - _, err := NewCommand("symbolic-ref", "HEAD", BRANCH_PREFIX+name).RunInDir(repo.Path) - return err -} - -// GetBranches returns all branches of the repository. -func (repo *Repository) GetBranches() ([]string, error) { - stdout, err := NewCommand("show-ref", "--heads").RunInDir(repo.Path) - if err != nil { - return nil, err - } - - infos := strings.Split(stdout, "\n") - branches := make([]string, len(infos)-1) - for i, info := range infos[:len(infos)-1] { - fields := strings.Fields(info) - if len(fields) != 2 { - continue // NOTE: I should believe git will not give me wrong string. - } - branches[i] = strings.TrimPrefix(fields[1], BRANCH_PREFIX) - } - return branches, nil -} - -// Option(s) for delete branch -type DeleteBranchOptions struct { - Force bool -} - -// DeleteBranch deletes a branch from given repository path. -func DeleteBranch(repoPath, name string, opts DeleteBranchOptions) error { - cmd := NewCommand("branch") - - if opts.Force { - cmd.AddArguments("-D") - } else { - cmd.AddArguments("-d") - } - - cmd.AddArguments(name) - _, err := cmd.RunInDir(repoPath) - - return err -} - -// DeleteBranch deletes a branch from repository. -func (repo *Repository) DeleteBranch(name string, opts DeleteBranchOptions) error { - return DeleteBranch(repo.Path, name, opts) -} - -// AddRemote adds a new remote to repository. -func (repo *Repository) AddRemote(name, url string, fetch bool) error { - cmd := NewCommand("remote", "add") - if fetch { - cmd.AddArguments("-f") - } - cmd.AddArguments(name, url) - - _, err := cmd.RunInDir(repo.Path) - return err -} - -// RemoveRemote removes a remote from repository. -func (repo *Repository) RemoveRemote(name string) error { - _, err := NewCommand("remote", "remove", name).RunInDir(repo.Path) - return err -} diff --git a/vendor/github.com/gogits/git-module/repo_commit.go b/vendor/github.com/gogits/git-module/repo_commit.go deleted file mode 100644 index 6b629d4d..00000000 --- a/vendor/github.com/gogits/git-module/repo_commit.go +++ /dev/null @@ -1,381 +0,0 @@ -// Copyright 2015 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package git - -import ( - "bytes" - "container/list" - "fmt" - "strconv" - "strings" - - "github.com/mcuadros/go-version" -) - -const REMOTE_PREFIX = "refs/remotes/" - -// getRefCommitID returns the last commit ID string of given reference (branch or tag). -func (repo *Repository) getRefCommitID(name string) (string, error) { - stdout, err := NewCommand("show-ref", "--verify", name).RunInDir(repo.Path) - if err != nil { - if strings.Contains(err.Error(), "not a valid ref") { - return "", ErrNotExist{name, ""} - } - return "", err - } - return strings.Split(stdout, " ")[0], nil -} - -// GetBranchCommitID returns last commit ID string of given branch. -func (repo *Repository) GetBranchCommitID(name string) (string, error) { - return repo.getRefCommitID(BRANCH_PREFIX + name) -} - -// GetTagCommitID returns last commit ID string of given tag. -func (repo *Repository) GetTagCommitID(name string) (string, error) { - return repo.getRefCommitID(TAG_PREFIX + name) -} - -// GetRemoteBranchCommitID returns last commit ID string of given remote branch. -func (repo *Repository) GetRemoteBranchCommitID(name string) (string, error) { - return repo.getRefCommitID(REMOTE_PREFIX + name) -} - -// parseCommitData parses commit information from the (uncompressed) raw -// data from the commit object. -// \n\n separate headers from message -func parseCommitData(data []byte) (*Commit, error) { - commit := new(Commit) - commit.parents = make([]sha1, 0, 1) - // we now have the contents of the commit object. Let's investigate... - nextline := 0 -l: - for { - eol := bytes.IndexByte(data[nextline:], '\n') - switch { - case eol > 0: - line := data[nextline : nextline+eol] - spacepos := bytes.IndexByte(line, ' ') - reftype := line[:spacepos] - switch string(reftype) { - case "tree", "object": - id, err := NewIDFromString(string(line[spacepos+1:])) - if err != nil { - return nil, err - } - commit.Tree.ID = id - case "parent": - // A commit can have one or more parents - oid, err := NewIDFromString(string(line[spacepos+1:])) - if err != nil { - return nil, err - } - commit.parents = append(commit.parents, oid) - case "author", "tagger": - sig, err := newSignatureFromCommitline(line[spacepos+1:]) - if err != nil { - return nil, err - } - commit.Author = sig - case "committer": - sig, err := newSignatureFromCommitline(line[spacepos+1:]) - if err != nil { - return nil, err - } - commit.Committer = sig - } - nextline += eol + 1 - case eol == 0: - commit.CommitMessage = string(data[nextline+1:]) - break l - default: - break l - } - } - return commit, nil -} - -func (repo *Repository) getCommit(id sha1) (*Commit, error) { - c, ok := repo.commitCache.Get(id.String()) - if ok { - log("Hit cache: %s", id) - return c.(*Commit), nil - } - - data, err := NewCommand("cat-file", "commit", id.String()).RunInDirBytes(repo.Path) - if err != nil { - if strings.Contains(err.Error(), "exit status 128") { - return nil, ErrNotExist{id.String(), ""} - } - return nil, err - } - - commit, err := parseCommitData(data) - if err != nil { - return nil, err - } - commit.repo = repo - commit.ID = id - - repo.commitCache.Set(id.String(), commit) - return commit, nil -} - -// GetCommit returns commit object of by ID string. -func (repo *Repository) GetCommit(commitID string) (*Commit, error) { - if len(commitID) != 40 { - var err error - commitID, err = NewCommand("rev-parse", commitID).RunInDir(repo.Path) - if err != nil { - if strings.Contains(err.Error(), "exit status 128") { - return nil, ErrNotExist{commitID, ""} - } - return nil, err - } - } - id, err := NewIDFromString(commitID) - if err != nil { - return nil, err - } - - return repo.getCommit(id) -} - -// GetBranchCommit returns the last commit of given branch. -func (repo *Repository) GetBranchCommit(name string) (*Commit, error) { - commitID, err := repo.GetBranchCommitID(name) - if err != nil { - return nil, err - } - return repo.GetCommit(commitID) -} - -// GetTagCommit returns the commit of given tag. -func (repo *Repository) GetTagCommit(name string) (*Commit, error) { - commitID, err := repo.GetTagCommitID(name) - if err != nil { - return nil, err - } - return repo.GetCommit(commitID) -} - -// GetRemoteBranchCommit returns the last commit of given remote branch. -func (repo *Repository) GetRemoteBranchCommit(name string) (*Commit, error) { - commitID, err := repo.GetRemoteBranchCommitID(name) - if err != nil { - return nil, err - } - return repo.GetCommit(commitID) -} - -func (repo *Repository) getCommitByPathWithID(id sha1, relpath string) (*Commit, error) { - // File name starts with ':' must be escaped. - if relpath[0] == ':' { - relpath = `\` + relpath - } - - stdout, err := NewCommand("log", "-1", _PRETTY_LOG_FORMAT, id.String(), "--", relpath).RunInDir(repo.Path) - if err != nil { - return nil, err - } - - id, err = NewIDFromString(stdout) - if err != nil { - return nil, err - } - - return repo.getCommit(id) -} - -// GetCommitByPath returns the last commit of relative path. -func (repo *Repository) GetCommitByPath(relpath string) (*Commit, error) { - stdout, err := NewCommand("log", "-1", _PRETTY_LOG_FORMAT, "--", relpath).RunInDirBytes(repo.Path) - if err != nil { - return nil, err - } - - commits, err := repo.parsePrettyFormatLogToList(stdout) - if err != nil { - return nil, err - } - return commits.Front().Value.(*Commit), nil -} - -func (repo *Repository) CommitsByRangeSize(revision string, page, size int) (*list.List, error) { - stdout, err := NewCommand("log", revision, "--skip="+strconv.Itoa((page-1)*size), - "--max-count="+strconv.Itoa(size), _PRETTY_LOG_FORMAT).RunInDirBytes(repo.Path) - if err != nil { - return nil, err - } - return repo.parsePrettyFormatLogToList(stdout) -} - -var DefaultCommitsPageSize = 30 - -func (repo *Repository) CommitsByRange(revision string, page int) (*list.List, error) { - return repo.CommitsByRangeSize(revision, page, DefaultCommitsPageSize) -} - -func (repo *Repository) searchCommits(id sha1, keyword string) (*list.List, error) { - stdout, err := NewCommand("log", id.String(), "-100", "-i", "--grep="+keyword, _PRETTY_LOG_FORMAT).RunInDirBytes(repo.Path) - if err != nil { - return nil, err - } - return repo.parsePrettyFormatLogToList(stdout) -} - -func (repo *Repository) getFilesChanged(id1 string, id2 string) ([]string, error) { - stdout, err := NewCommand("diff", "--name-only", id1, id2).RunInDirBytes(repo.Path) - if err != nil { - return nil, err - } - return strings.Split(string(stdout), "\n"), nil -} - -func (repo *Repository) FileCommitsCount(revision, file string) (int64, error) { - return commitsCount(repo.Path, revision, file) -} - -func (repo *Repository) CommitsByFileAndRangeSize(revision, file string, page, size int) (*list.List, error) { - stdout, err := NewCommand("log", revision, "--skip="+strconv.Itoa((page-1)*size), - "--max-count="+strconv.Itoa(size), _PRETTY_LOG_FORMAT, "--", file).RunInDirBytes(repo.Path) - if err != nil { - return nil, err - } - return repo.parsePrettyFormatLogToList(stdout) -} - -func (repo *Repository) CommitsByFileAndRange(revision, file string, page int) (*list.List, error) { - return repo.CommitsByFileAndRangeSize(revision, file, page, DefaultCommitsPageSize) -} - -func (repo *Repository) FilesCountBetween(startCommitID, endCommitID string) (int, error) { - stdout, err := NewCommand("diff", "--name-only", startCommitID+"..."+endCommitID).RunInDir(repo.Path) - if err != nil { - return 0, err - } - return len(strings.Split(stdout, "\n")) - 1, nil -} - -// CommitsBetween returns a list that contains commits between [last, before). -func (repo *Repository) CommitsBetween(last *Commit, before *Commit) (*list.List, error) { - if version.Compare(gitVersion, "1.8.0", ">=") { - stdout, err := NewCommand("rev-list", before.ID.String()+"..."+last.ID.String()).RunInDirBytes(repo.Path) - if err != nil { - return nil, err - } - return repo.parsePrettyFormatLogToList(bytes.TrimSpace(stdout)) - } - - // Fallback to stupid solution, which iterates all commits of the repository - // if before is not an ancestor of last. - l := list.New() - if last == nil || last.ParentCount() == 0 { - return l, nil - } - - var err error - cur := last - for { - if cur.ID.Equal(before.ID) { - break - } - l.PushBack(cur) - if cur.ParentCount() == 0 { - break - } - cur, err = cur.Parent(0) - if err != nil { - return nil, err - } - } - return l, nil -} - -func (repo *Repository) CommitsBetweenIDs(last, before string) (*list.List, error) { - lastCommit, err := repo.GetCommit(last) - if err != nil { - return nil, err - } - beforeCommit, err := repo.GetCommit(before) - if err != nil { - return nil, err - } - return repo.CommitsBetween(lastCommit, beforeCommit) -} - -func (repo *Repository) CommitsCountBetween(start, end string) (int64, error) { - return commitsCount(repo.Path, start+"..."+end, "") -} - -// The limit is depth, not total number of returned commits. -func (repo *Repository) commitsBefore(l *list.List, parent *list.Element, id sha1, current, limit int) error { - // Reach the limit - if limit > 0 && current > limit { - return nil - } - - commit, err := repo.getCommit(id) - if err != nil { - return fmt.Errorf("getCommit: %v", err) - } - - var e *list.Element - if parent == nil { - e = l.PushBack(commit) - } else { - var in = parent - for { - if in == nil { - break - } else if in.Value.(*Commit).ID.Equal(commit.ID) { - return nil - } else if in.Next() == nil { - break - } - - if in.Value.(*Commit).Committer.When.Equal(commit.Committer.When) { - break - } - - if in.Value.(*Commit).Committer.When.After(commit.Committer.When) && - in.Next().Value.(*Commit).Committer.When.Before(commit.Committer.When) { - break - } - - in = in.Next() - } - - e = l.InsertAfter(commit, in) - } - - pr := parent - if commit.ParentCount() > 1 { - pr = e - } - - for i := 0; i < commit.ParentCount(); i++ { - id, err := commit.ParentID(i) - if err != nil { - return err - } - err = repo.commitsBefore(l, pr, id, current+1, limit) - if err != nil { - return err - } - } - - return nil -} - -func (repo *Repository) getCommitsBefore(id sha1) (*list.List, error) { - l := list.New() - return l, repo.commitsBefore(l, nil, id, 1, 0) -} - -func (repo *Repository) getCommitsBeforeLimit(id sha1, num int) (*list.List, error) { - l := list.New() - return l, repo.commitsBefore(l, nil, id, 1, num) -} diff --git a/vendor/github.com/gogits/git-module/repo_diff.go b/vendor/github.com/gogits/git-module/repo_diff.go deleted file mode 100644 index 258a166f..00000000 --- a/vendor/github.com/gogits/git-module/repo_diff.go +++ /dev/null @@ -1,400 +0,0 @@ -// Copyright 2017 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package git - -import ( - "bufio" - "bytes" - "fmt" - "io" - "io/ioutil" - "strconv" - "strings" - "time" -) - -// DiffLineType represents the type of a line in diff. -type DiffLineType uint8 - -const ( - DIFF_LINE_PLAIN DiffLineType = iota + 1 - DIFF_LINE_ADD - DIFF_LINE_DEL - DIFF_LINE_SECTION -) - -// DiffFileType represents the file status in diff. -type DiffFileType uint8 - -const ( - DIFF_FILE_ADD DiffFileType = iota + 1 - DIFF_FILE_CHANGE - DIFF_FILE_DEL - DIFF_FILE_RENAME -) - -// DiffLine represents a line in diff. -type DiffLine struct { - LeftIdx int - RightIdx int - Type DiffLineType - Content string -} - -func (d *DiffLine) GetType() int { - return int(d.Type) -} - -// DiffSection represents a section in diff. -type DiffSection struct { - Name string - Lines []*DiffLine -} - -// Line returns a specific line by type (add or del) and file line number from a section. -func (diffSection *DiffSection) Line(lineType DiffLineType, idx int) *DiffLine { - var ( - difference = 0 - addCount = 0 - delCount = 0 - matchDiffLine *DiffLine - ) - -LOOP: - for _, diffLine := range diffSection.Lines { - switch diffLine.Type { - case DIFF_LINE_ADD: - addCount++ - case DIFF_LINE_DEL: - delCount++ - default: - if matchDiffLine != nil { - break LOOP - } - difference = diffLine.RightIdx - diffLine.LeftIdx - addCount = 0 - delCount = 0 - } - - switch lineType { - case DIFF_LINE_DEL: - if diffLine.RightIdx == 0 && diffLine.LeftIdx == idx-difference { - matchDiffLine = diffLine - } - case DIFF_LINE_ADD: - if diffLine.LeftIdx == 0 && diffLine.RightIdx == idx+difference { - matchDiffLine = diffLine - } - } - } - - if addCount == delCount { - return matchDiffLine - } - return nil -} - -// DiffFile represents a file in diff. -type DiffFile struct { - Name string - OldName string - Index string // 40-byte SHA, Changed/New: new SHA; Deleted: old SHA - Addition, Deletion int - Type DiffFileType - IsCreated bool - IsDeleted bool - IsBin bool - IsRenamed bool - IsSubmodule bool - Sections []*DiffSection - IsIncomplete bool -} - -func (diffFile *DiffFile) GetType() int { - return int(diffFile.Type) -} - -func (diffFile *DiffFile) NumSections() int { - return len(diffFile.Sections) -} - -// Diff contains all information of a specific diff output. -type Diff struct { - TotalAddition, TotalDeletion int - Files []*DiffFile - IsIncomplete bool -} - -func (diff *Diff) NumFiles() int { - return len(diff.Files) -} - -const _DIFF_HEAD = "diff --git " - -// ParsePatch takes a reader and parses everything it receives in diff format. -func ParsePatch(done chan<- error, maxLines, maxLineCharacteres, maxFiles int, reader io.Reader) *Diff { - var ( - diff = &Diff{Files: make([]*DiffFile, 0)} - - curFile *DiffFile - curSection = &DiffSection{ - Lines: make([]*DiffLine, 0, 10), - } - - leftLine, rightLine int - lineCount int - curFileLinesCount int - ) - input := bufio.NewReader(reader) - isEOF := false - for !isEOF { - // TODO: would input.ReadBytes be more memory-efficient? - line, err := input.ReadString('\n') - if err != nil { - if err == io.EOF { - isEOF = true - } else { - done <- fmt.Errorf("ReadString: %v", err) - return nil - } - } - - if len(line) > 0 && line[len(line)-1] == '\n' { - // Remove line break. - line = line[:len(line)-1] - } - - if strings.HasPrefix(line, "+++ ") || strings.HasPrefix(line, "--- ") || len(line) == 0 { - continue - } - - curFileLinesCount++ - lineCount++ - - // Diff data too large, we only show the first about maxlines lines - if curFileLinesCount >= maxLines || len(line) >= maxLineCharacteres { - curFile.IsIncomplete = true - } - - switch { - case line[0] == ' ': - diffLine := &DiffLine{Type: DIFF_LINE_PLAIN, Content: line, LeftIdx: leftLine, RightIdx: rightLine} - leftLine++ - rightLine++ - curSection.Lines = append(curSection.Lines, diffLine) - continue - case line[0] == '@': - curSection = &DiffSection{} - curFile.Sections = append(curFile.Sections, curSection) - ss := strings.Split(line, "@@") - diffLine := &DiffLine{Type: DIFF_LINE_SECTION, Content: line} - curSection.Lines = append(curSection.Lines, diffLine) - - // Parse line number. - ranges := strings.Split(ss[1][1:], " ") - leftLine, _ = strconv.Atoi(strings.Split(ranges[0], ",")[0][1:]) - if len(ranges) > 1 { - rightLine, _ = strconv.Atoi(strings.Split(ranges[1], ",")[0]) - } else { - rightLine = leftLine - } - continue - case line[0] == '+': - curFile.Addition++ - diff.TotalAddition++ - diffLine := &DiffLine{Type: DIFF_LINE_ADD, Content: line, RightIdx: rightLine} - rightLine++ - curSection.Lines = append(curSection.Lines, diffLine) - continue - case line[0] == '-': - curFile.Deletion++ - diff.TotalDeletion++ - diffLine := &DiffLine{Type: DIFF_LINE_DEL, Content: line, LeftIdx: leftLine} - if leftLine > 0 { - leftLine++ - } - curSection.Lines = append(curSection.Lines, diffLine) - case strings.HasPrefix(line, "Binary"): - curFile.IsBin = true - continue - } - - // Get new file. - if strings.HasPrefix(line, _DIFF_HEAD) { - middle := -1 - - // Note: In case file name is surrounded by double quotes (it happens only in git-shell). - // e.g. diff --git "a/xxx" "b/xxx" - hasQuote := line[len(_DIFF_HEAD)] == '"' - if hasQuote { - middle = strings.Index(line, ` "b/`) - } else { - middle = strings.Index(line, " b/") - } - - beg := len(_DIFF_HEAD) - a := line[beg+2 : middle] - b := line[middle+3:] - if hasQuote { - a = string(UnescapeChars([]byte(a[1 : len(a)-1]))) - b = string(UnescapeChars([]byte(b[1 : len(b)-1]))) - } - - curFile = &DiffFile{ - Name: a, - Type: DIFF_FILE_CHANGE, - Sections: make([]*DiffSection, 0, 10), - } - diff.Files = append(diff.Files, curFile) - if len(diff.Files) >= maxFiles { - diff.IsIncomplete = true - io.Copy(ioutil.Discard, reader) - break - } - curFileLinesCount = 0 - - // Check file diff type and submodule. - CHECK_TYPE: - for { - line, err := input.ReadString('\n') - if err != nil { - if err == io.EOF { - isEOF = true - } else { - done <- fmt.Errorf("ReadString: %v", err) - return nil - } - } - - switch { - case strings.HasPrefix(line, "new file"): - curFile.Type = DIFF_FILE_ADD - curFile.IsCreated = true - curFile.IsSubmodule = strings.HasSuffix(line, " 160000\n") - case strings.HasPrefix(line, "deleted"): - curFile.Type = DIFF_FILE_DEL - curFile.IsDeleted = true - curFile.IsSubmodule = strings.HasSuffix(line, " 160000\n") - case strings.HasPrefix(line, "index"): - if curFile.IsDeleted { - curFile.Index = line[6:46] - } else if len(line) >= 88 { - curFile.Index = line[49:88] - } else { - curFile.Index = curFile.Name - } - break CHECK_TYPE - case strings.HasPrefix(line, "similarity index 100%"): - curFile.Type = DIFF_FILE_RENAME - curFile.IsRenamed = true - curFile.OldName = curFile.Name - curFile.Name = b - curFile.Index = b - break CHECK_TYPE - case strings.HasPrefix(line, "old mode"): - break CHECK_TYPE - } - } - } - } - - done <- nil - return diff -} - -// GetDiffRange returns a parsed diff object between given commits. -func GetDiffRange(repoPath, beforeCommitID, afterCommitID string, maxLines, maxLineCharacteres, maxFiles int) (*Diff, error) { - repo, err := OpenRepository(repoPath) - if err != nil { - return nil, err - } - - commit, err := repo.GetCommit(afterCommitID) - if err != nil { - return nil, err - } - - cmd := NewCommand() - if len(beforeCommitID) == 0 { - // First commit of repository - if commit.ParentCount() == 0 { - cmd.AddArguments("show", "--full-index", afterCommitID) - } else { - c, _ := commit.Parent(0) - cmd.AddArguments("diff", "--full-index", "-M", c.ID.String(), afterCommitID) - } - } else { - cmd.AddArguments("diff", "--full-index", "-M", beforeCommitID, afterCommitID) - } - - stdout, w := io.Pipe() - done := make(chan error) - var diff *Diff - go func() { - diff = ParsePatch(done, maxLines, maxLineCharacteres, maxFiles, stdout) - }() - - stderr := new(bytes.Buffer) - err = cmd.RunInDirTimeoutPipeline(2*time.Minute, repoPath, w, stderr) - w.Close() // Close writer to exit parsing goroutine - if err != nil { - return nil, concatenateError(err, stderr.String()) - } - - return diff, <-done -} - -// RawDiffType represents the type of raw diff format. -type RawDiffType string - -const ( - RAW_DIFF_NORMAL RawDiffType = "diff" - RAW_DIFF_PATCH RawDiffType = "patch" -) - -// GetRawDiff dumps diff results of repository in given commit ID to io.Writer. -func GetRawDiff(repoPath, commitID string, diffType RawDiffType, writer io.Writer) error { - repo, err := OpenRepository(repoPath) - if err != nil { - return fmt.Errorf("OpenRepository: %v", err) - } - - commit, err := repo.GetCommit(commitID) - if err != nil { - return err - } - - cmd := NewCommand() - switch diffType { - case RAW_DIFF_NORMAL: - if commit.ParentCount() == 0 { - cmd.AddArguments("show", commitID) - } else { - c, _ := commit.Parent(0) - cmd.AddArguments("diff", "-M", c.ID.String(), commitID) - } - case RAW_DIFF_PATCH: - if commit.ParentCount() == 0 { - cmd.AddArguments("format-patch", "--no-signature", "--stdout", "--root", commitID) - } else { - c, _ := commit.Parent(0) - query := fmt.Sprintf("%s...%s", commitID, c.ID.String()) - cmd.AddArguments("format-patch", "--no-signature", "--stdout", query) - } - default: - return fmt.Errorf("invalid diffType: %s", diffType) - } - - stderr := new(bytes.Buffer) - if err = cmd.RunInDirPipeline(repoPath, writer, stderr); err != nil { - return concatenateError(err, stderr.String()) - } - return nil -} - -// GetDiffCommit returns a parsed diff object of given commit. -func GetDiffCommit(repoPath, commitID string, maxLines, maxLineCharacteres, maxFiles int) (*Diff, error) { - return GetDiffRange(repoPath, "", commitID, maxLines, maxLineCharacteres, maxFiles) -} diff --git a/vendor/github.com/gogits/git-module/repo_hook.go b/vendor/github.com/gogits/git-module/repo_hook.go deleted file mode 100644 index 7b49647e..00000000 --- a/vendor/github.com/gogits/git-module/repo_hook.go +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2015 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package git - -func (repo *Repository) GetHook(name string) (*Hook, error) { - return GetHook(repo.Path, name) -} - -func (repo *Repository) Hooks() ([]*Hook, error) { - return ListHooks(repo.Path) -} diff --git a/vendor/github.com/gogits/git-module/repo_object.go b/vendor/github.com/gogits/git-module/repo_object.go deleted file mode 100644 index 416ee459..00000000 --- a/vendor/github.com/gogits/git-module/repo_object.go +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright 2014 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package git - -type ObjectType string - -const ( - OBJECT_COMMIT ObjectType = "commit" - OBJECT_TREE ObjectType = "tree" - OBJECT_BLOB ObjectType = "blob" - OBJECT_TAG ObjectType = "tag" -) diff --git a/vendor/github.com/gogits/git-module/repo_pull.go b/vendor/github.com/gogits/git-module/repo_pull.go deleted file mode 100644 index 22ccb269..00000000 --- a/vendor/github.com/gogits/git-module/repo_pull.go +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright 2015 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package git - -import ( - "container/list" - "fmt" - "strconv" - "strings" - "time" -) - -// PullRequestInfo represents needed information for a pull request. -type PullRequestInfo struct { - MergeBase string - Commits *list.List - NumFiles int -} - -// GetMergeBase checks and returns merge base of two branches. -func (repo *Repository) GetMergeBase(base, head string) (string, error) { - stdout, err := NewCommand("merge-base", base, head).RunInDir(repo.Path) - if err != nil { - if strings.Contains(err.Error(), "exit status 1") { - return "", ErrNoMergeBase{} - } - return "", err - } - return strings.TrimSpace(stdout), nil -} - -// GetPullRequestInfo generates and returns pull request information -// between base and head branches of repositories. -func (repo *Repository) GetPullRequestInfo(basePath, baseBranch, headBranch string) (_ *PullRequestInfo, err error) { - var remoteBranch string - - // We don't need a temporary remote for same repository. - if repo.Path != basePath { - // Add a temporary remote - tmpRemote := strconv.FormatInt(time.Now().UnixNano(), 10) - if err = repo.AddRemote(tmpRemote, basePath, true); err != nil { - return nil, fmt.Errorf("AddRemote: %v", err) - } - defer repo.RemoveRemote(tmpRemote) - - remoteBranch = "remotes/" + tmpRemote + "/" + baseBranch - } else { - remoteBranch = baseBranch - } - - prInfo := new(PullRequestInfo) - prInfo.MergeBase, err = repo.GetMergeBase(remoteBranch, headBranch) - if err != nil { - return nil, err - } - - logs, err := NewCommand("log", prInfo.MergeBase+"..."+headBranch, _PRETTY_LOG_FORMAT).RunInDirBytes(repo.Path) - if err != nil { - return nil, err - } - prInfo.Commits, err = repo.parsePrettyFormatLogToList(logs) - if err != nil { - return nil, fmt.Errorf("parsePrettyFormatLogToList: %v", err) - } - - // Count number of changed files. - stdout, err := NewCommand("diff", "--name-only", remoteBranch+"..."+headBranch).RunInDir(repo.Path) - if err != nil { - return nil, err - } - prInfo.NumFiles = len(strings.Split(stdout, "\n")) - 1 - - return prInfo, nil -} - -// GetPatch generates and returns patch data between given revisions. -func (repo *Repository) GetPatch(base, head string) ([]byte, error) { - return NewCommand("diff", "-p", "--binary", base, head).RunInDirBytes(repo.Path) -} diff --git a/vendor/github.com/gogits/git-module/repo_tag.go b/vendor/github.com/gogits/git-module/repo_tag.go deleted file mode 100644 index 4cef496b..00000000 --- a/vendor/github.com/gogits/git-module/repo_tag.go +++ /dev/null @@ -1,209 +0,0 @@ -// Copyright 2015 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package git - -import ( - "fmt" - "strings" - - "github.com/mcuadros/go-version" -) - -const TAG_PREFIX = "refs/tags/" - -// IsTagExist returns true if given tag exists in the repository. -func IsTagExist(repoPath, name string) bool { - return IsReferenceExist(repoPath, TAG_PREFIX+name) -} - -func (repo *Repository) IsTagExist(name string) bool { - return IsTagExist(repo.Path, name) -} - -func (repo *Repository) CreateTag(name, revision string) error { - _, err := NewCommand("tag", name, revision).RunInDir(repo.Path) - return err -} - -func (repo *Repository) getTag(id sha1) (*Tag, error) { - t, ok := repo.tagCache.Get(id.String()) - if ok { - log("Hit cache: %s", id) - return t.(*Tag), nil - } - - // Get tag type - tp, err := NewCommand("cat-file", "-t", id.String()).RunInDir(repo.Path) - if err != nil { - return nil, err - } - tp = strings.TrimSpace(tp) - - // Tag is a commit. - if ObjectType(tp) == OBJECT_COMMIT { - tag := &Tag{ - ID: id, - Object: id, - Type: string(OBJECT_COMMIT), - repo: repo, - } - - repo.tagCache.Set(id.String(), tag) - return tag, nil - } - - // Tag with message. - data, err := NewCommand("cat-file", "-p", id.String()).RunInDirBytes(repo.Path) - if err != nil { - return nil, err - } - - tag, err := parseTagData(data) - if err != nil { - return nil, err - } - - tag.ID = id - tag.repo = repo - - repo.tagCache.Set(id.String(), tag) - return tag, nil -} - -// GetTag returns a Git tag by given name. -func (repo *Repository) GetTag(name string) (*Tag, error) { - stdout, err := NewCommand("show-ref", "--tags", name).RunInDir(repo.Path) - if err != nil { - return nil, err - } - - id, err := NewIDFromString(strings.Split(stdout, " ")[0]) - if err != nil { - return nil, err - } - - tag, err := repo.getTag(id) - if err != nil { - return nil, err - } - tag.Name = name - return tag, nil -} - -// GetTags returns all tags of the repository. -func (repo *Repository) GetTags() ([]string, error) { - cmd := NewCommand("tag", "-l") - if version.Compare(gitVersion, "2.0.0", ">=") { - cmd.AddArguments("--sort=-v:refname") - } - - stdout, err := cmd.RunInDir(repo.Path) - if err != nil { - return nil, err - } - - tags := strings.Split(stdout, "\n") - tags = tags[:len(tags)-1] - - if version.Compare(gitVersion, "2.0.0", "<") { - version.Sort(tags) - - // Reverse order - for i := 0; i < len(tags)/2; i++ { - j := len(tags) - i - 1 - tags[i], tags[j] = tags[j], tags[i] - } - } - - return tags, nil -} - -type TagsResult struct { - // Indicates whether results include the latest tag. - HasLatest bool - // If results do not include the latest tag, a indicator 'after' to go back. - PreviousAfter string - // Indicates whether results include the oldest tag. - ReachEnd bool - // List of returned tags. - Tags []string -} - -// GetTagsAfter returns list of tags 'after' (exlusive) given tag. -func (repo *Repository) GetTagsAfter(after string, limit int) (*TagsResult, error) { - allTags, err := repo.GetTags() - if err != nil { - return nil, fmt.Errorf("GetTags: %v", err) - } - - if limit < 0 { - limit = 0 - } - - numAllTags := len(allTags) - if len(after) == 0 && limit == 0 { - return &TagsResult{ - HasLatest: true, - ReachEnd: true, - Tags: allTags, - }, nil - } else if len(after) == 0 && limit > 0 { - endIdx := limit - if limit >= numAllTags { - endIdx = numAllTags - } - return &TagsResult{ - HasLatest: true, - ReachEnd: limit >= numAllTags, - Tags: allTags[:endIdx], - }, nil - } - - previousAfter := "" - hasMatch := false - tags := make([]string, 0, len(allTags)) - for i := range allTags { - if hasMatch { - tags = allTags[i:] - break - } - if allTags[i] == after { - hasMatch = true - if limit > 0 && i-limit >= 0 { - previousAfter = allTags[i-limit] - } - continue - } - } - - if !hasMatch { - tags = allTags - } - - // If all tags after match is equal to the limit, it reaches the oldest tag as well. - if limit == 0 || len(tags) <= limit { - return &TagsResult{ - HasLatest: !hasMatch, - PreviousAfter: previousAfter, - ReachEnd: true, - Tags: tags, - }, nil - } - return &TagsResult{ - HasLatest: !hasMatch, - PreviousAfter: previousAfter, - Tags: tags[:limit], - }, nil -} - -// DeleteTag deletes a tag from the repository -func (repo *Repository) DeleteTag(name string) error { - cmd := NewCommand("tag", "-d") - - cmd.AddArguments(name) - _, err := cmd.RunInDir(repo.Path) - - return err -} diff --git a/vendor/github.com/gogits/git-module/repo_tree.go b/vendor/github.com/gogits/git-module/repo_tree.go deleted file mode 100644 index baebb251..00000000 --- a/vendor/github.com/gogits/git-module/repo_tree.go +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2015 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package git - -func (repo *Repository) getTree(id sha1) (*Tree, error) { - treePath := filepathFromSHA1(repo.Path, id.String()) - if isFile(treePath) { - _, err := NewCommand("ls-tree", id.String()).RunInDir(repo.Path) - if err != nil { - return nil, ErrNotExist{id.String(), ""} - } - } - - return NewTree(repo, id), nil -} - -// Find the tree object in the repository. -func (repo *Repository) GetTree(idStr string) (*Tree, error) { - id, err := NewIDFromString(idStr) - if err != nil { - return nil, err - } - return repo.getTree(id) -} diff --git a/vendor/github.com/gogits/git-module/sha1.go b/vendor/github.com/gogits/git-module/sha1.go deleted file mode 100644 index 7744275d..00000000 --- a/vendor/github.com/gogits/git-module/sha1.go +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright 2015 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package git - -import ( - "encoding/hex" - "fmt" - "strings" -) - -const EMPTY_SHA = "0000000000000000000000000000000000000000" - -type sha1 [20]byte - -// Equal returns true if s has the same sha1 as caller. -// Support 40-length-string, []byte, sha1. -func (id sha1) Equal(s2 interface{}) bool { - switch v := s2.(type) { - case string: - if len(v) != 40 { - return false - } - return v == id.String() - case []byte: - if len(v) != 20 { - return false - } - for i, v := range v { - if id[i] != v { - return false - } - } - case sha1: - for i, v := range v { - if id[i] != v { - return false - } - } - default: - return false - } - return true -} - -// String returns string (hex) representation of the Oid. -func (s sha1) String() string { - result := make([]byte, 0, 40) - hexvalues := []byte("0123456789abcdef") - for i := 0; i < 20; i++ { - result = append(result, hexvalues[s[i]>>4]) - result = append(result, hexvalues[s[i]&0xf]) - } - return string(result) -} - -// MustID always creates a new sha1 from a [20]byte array with no validation of input. -func MustID(b []byte) sha1 { - var id sha1 - for i := 0; i < 20; i++ { - id[i] = b[i] - } - return id -} - -// NewID creates a new sha1 from a [20]byte array. -func NewID(b []byte) (sha1, error) { - if len(b) != 20 { - return sha1{}, fmt.Errorf("Length must be 20: %v", b) - } - return MustID(b), nil -} - -// MustIDFromString always creates a new sha from a ID with no validation of input. -func MustIDFromString(s string) sha1 { - b, _ := hex.DecodeString(s) - return MustID(b) -} - -// NewIDFromString creates a new sha1 from a ID string of length 40. -func NewIDFromString(s string) (sha1, error) { - var id sha1 - s = strings.TrimSpace(s) - if len(s) != 40 { - return id, fmt.Errorf("Length must be 40: %s", s) - } - b, err := hex.DecodeString(s) - if err != nil { - return id, err - } - return NewID(b) -} diff --git a/vendor/github.com/gogits/git-module/signature.go b/vendor/github.com/gogits/git-module/signature.go deleted file mode 100644 index 95eb1bbe..00000000 --- a/vendor/github.com/gogits/git-module/signature.go +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2015 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package git - -import ( - "bytes" - "strconv" - "time" -) - -// Signature represents the Author or Committer information. -type Signature struct { - Email string - Name string - When time.Time -} - -// Helper to get a signature from the commit line, which looks like these: -// author Patrick Gundlach 1378823654 +0200 -// author Patrick Gundlach Thu, 07 Apr 2005 22:13:13 +0200 -// but without the "author " at the beginning (this method should) -// be used for author and committer. -// -// FIXME: include timezone for timestamp! -func newSignatureFromCommitline(line []byte) (_ *Signature, err error) { - sig := new(Signature) - emailStart := bytes.IndexByte(line, '<') - sig.Name = string(line[:emailStart-1]) - emailEnd := bytes.IndexByte(line, '>') - sig.Email = string(line[emailStart+1 : emailEnd]) - - // Check date format. - firstChar := line[emailEnd+2] - if firstChar >= 48 && firstChar <= 57 { - timestop := bytes.IndexByte(line[emailEnd+2:], ' ') - timestring := string(line[emailEnd+2 : emailEnd+2+timestop]) - seconds, _ := strconv.ParseInt(timestring, 10, 64) - sig.When = time.Unix(seconds, 0) - } else { - sig.When, err = time.Parse("Mon Jan _2 15:04:05 2006 -0700", string(line[emailEnd+2:])) - if err != nil { - return nil, err - } - } - return sig, nil -} diff --git a/vendor/github.com/gogits/git-module/submodule.go b/vendor/github.com/gogits/git-module/submodule.go deleted file mode 100644 index 57773300..00000000 --- a/vendor/github.com/gogits/git-module/submodule.go +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright 2015 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package git - -import "strings" - -type SubModule struct { - Name string - URL string -} - -// SubModuleFile represents a file with submodule type. -type SubModuleFile struct { - *Commit - - refURL string - refID string -} - -func NewSubModuleFile(c *Commit, refURL, refID string) *SubModuleFile { - return &SubModuleFile{ - Commit: c, - refURL: refURL, - refID: refID, - } -} - -// RefURL guesses and returns reference URL. -func (sf *SubModuleFile) RefURL(urlPrefix string, parentPath string) string { - if sf.refURL == "" { - return "" - } - - url := strings.TrimSuffix(sf.refURL, ".git") - - // git://xxx/user/repo - if strings.HasPrefix(url, "git://") { - return "http://" + strings.TrimPrefix(url, "git://") - } - - // http[s]://xxx/user/repo - if strings.HasPrefix(url, "http://") || strings.HasPrefix(url, "https://") { - return url - } - - // Relative url prefix check (according to git submodule documentation) - if strings.HasPrefix(url, "./") || strings.HasPrefix(url, "../") { - // ...construct and return correct submodule url here... - idx := strings.Index(parentPath, "/src/") - if idx == -1 { - return url - } - return strings.TrimSuffix(urlPrefix, "/") + parentPath[:idx] + "/" + url - } - - // sysuser@xxx:user/repo - i := strings.Index(url, "@") - j := strings.LastIndex(url, ":") - - // Only process when i < j because git+ssh://git@git.forwardbias.in/npploader.git - if i > -1 && j > -1 && i < j { - // fix problem with reverse proxy works only with local server - if strings.Contains(urlPrefix, url[i+1:j]) { - return urlPrefix + url[j+1:] - } else { - return "http://" + url[i+1:j] + "/" + url[j+1:] - } - } - - return url -} - -// RefID returns reference ID. -func (sf *SubModuleFile) RefID() string { - return sf.refID -} diff --git a/vendor/github.com/gogits/git-module/tag.go b/vendor/github.com/gogits/git-module/tag.go deleted file mode 100644 index f4bf7792..00000000 --- a/vendor/github.com/gogits/git-module/tag.go +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2015 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package git - -import "bytes" - -// Tag represents a Git tag. -type Tag struct { - Name string - ID sha1 - repo *Repository - Object sha1 // The id of this commit object - Type string - Tagger *Signature - Message string -} - -func (tag *Tag) Commit() (*Commit, error) { - return tag.repo.getCommit(tag.Object) -} - -// Parse commit information from the (uncompressed) raw -// data from the commit object. -// \n\n separate headers from message -func parseTagData(data []byte) (*Tag, error) { - tag := new(Tag) - // we now have the contents of the commit object. Let's investigate... - nextline := 0 -l: - for { - eol := bytes.IndexByte(data[nextline:], '\n') - switch { - case eol > 0: - line := data[nextline : nextline+eol] - spacepos := bytes.IndexByte(line, ' ') - reftype := line[:spacepos] - switch string(reftype) { - case "object": - id, err := NewIDFromString(string(line[spacepos+1:])) - if err != nil { - return nil, err - } - tag.Object = id - case "type": - // A commit can have one or more parents - tag.Type = string(line[spacepos+1:]) - case "tagger": - sig, err := newSignatureFromCommitline(line[spacepos+1:]) - if err != nil { - return nil, err - } - tag.Tagger = sig - } - nextline += eol + 1 - case eol == 0: - tag.Message = string(data[nextline+1:]) - break l - default: - break l - } - } - return tag, nil -} diff --git a/vendor/github.com/gogits/git-module/tree.go b/vendor/github.com/gogits/git-module/tree.go deleted file mode 100644 index 789d4c9b..00000000 --- a/vendor/github.com/gogits/git-module/tree.go +++ /dev/null @@ -1,149 +0,0 @@ -// Copyright 2015 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package git - -import ( - "bytes" - "fmt" - "strings" -) - -// Tree represents a flat directory listing. -type Tree struct { - ID sha1 - repo *Repository - - // parent tree - ptree *Tree - - entries Entries - entriesParsed bool -} - -func NewTree(repo *Repository, id sha1) *Tree { - return &Tree{ - ID: id, - repo: repo, - } -} - -// Predefine []byte variables to avoid runtime allocations. -var ( - escapedSlash = []byte(`\\`) - regularSlash = []byte(`\`) - escapedTab = []byte(`\t`) - regularTab = []byte("\t") -) - -// UnescapeChars reverses escaped characters. -func UnescapeChars(in []byte) []byte { - // LEGACY [Go 1.7]: use more expressive bytes.ContainsAny - if bytes.IndexAny(in, "\\\t") == -1 { - return in - } - - out := bytes.Replace(in, escapedSlash, regularSlash, -1) - out = bytes.Replace(out, escapedTab, regularTab, -1) - return out -} - -// parseTreeData parses tree information from the (uncompressed) raw -// data from the tree object. -func parseTreeData(tree *Tree, data []byte) ([]*TreeEntry, error) { - entries := make([]*TreeEntry, 0, 10) - l := len(data) - pos := 0 - for pos < l { - entry := new(TreeEntry) - entry.ptree = tree - step := 6 - switch string(data[pos : pos+step]) { - case "100644", "100664": - entry.mode = ENTRY_MODE_BLOB - entry.Type = OBJECT_BLOB - case "100755": - entry.mode = ENTRY_MODE_EXEC - entry.Type = OBJECT_BLOB - case "120000": - entry.mode = ENTRY_MODE_SYMLINK - entry.Type = OBJECT_BLOB - case "160000": - entry.mode = ENTRY_MODE_COMMIT - entry.Type = OBJECT_COMMIT - - step = 8 - case "040000": - entry.mode = ENTRY_MODE_TREE - entry.Type = OBJECT_TREE - default: - return nil, fmt.Errorf("unknown type: %v", string(data[pos:pos+step])) - } - pos += step + 6 // Skip string type of entry type. - - step = 40 - id, err := NewIDFromString(string(data[pos : pos+step])) - if err != nil { - return nil, err - } - entry.ID = id - pos += step + 1 // Skip half of sha1. - - step = bytes.IndexByte(data[pos:], '\n') - - // In case entry name is surrounded by double quotes(it happens only in git-shell). - if data[pos] == '"' { - entry.name = string(UnescapeChars(data[pos+1 : pos+step-1])) - } else { - entry.name = string(data[pos : pos+step]) - } - - pos += step + 1 - entries = append(entries, entry) - } - return entries, nil -} - -func (t *Tree) SubTree(rpath string) (*Tree, error) { - if len(rpath) == 0 { - return t, nil - } - - paths := strings.Split(rpath, "/") - var ( - err error - g = t - p = t - te *TreeEntry - ) - for _, name := range paths { - te, err = p.GetTreeEntryByPath(name) - if err != nil { - return nil, err - } - - g, err = t.repo.getTree(te.ID) - if err != nil { - return nil, err - } - g.ptree = p - p = g - } - return g, nil -} - -// ListEntries returns all entries of current tree. -func (t *Tree) ListEntries() (Entries, error) { - if t.entriesParsed { - return t.entries, nil - } - t.entriesParsed = true - - stdout, err := NewCommand("ls-tree", t.ID.String()).RunInDirBytes(t.repo.Path) - if err != nil { - return nil, err - } - t.entries, err = parseTreeData(t, stdout) - return t.entries, err -} diff --git a/vendor/github.com/gogits/git-module/tree_blob.go b/vendor/github.com/gogits/git-module/tree_blob.go deleted file mode 100644 index e2e70152..00000000 --- a/vendor/github.com/gogits/git-module/tree_blob.go +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2015 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package git - -import ( - "path" - "strings" -) - -func (t *Tree) GetTreeEntryByPath(relpath string) (*TreeEntry, error) { - if len(relpath) == 0 { - return &TreeEntry{ - ID: t.ID, - Type: OBJECT_TREE, - mode: ENTRY_MODE_TREE, - }, nil - } - - relpath = path.Clean(relpath) - parts := strings.Split(relpath, "/") - var err error - tree := t - for i, name := range parts { - if i == len(parts)-1 { - entries, err := tree.ListEntries() - if err != nil { - return nil, err - } - for _, v := range entries { - if v.name == name { - return v, nil - } - } - } else { - tree, err = tree.SubTree(name) - if err != nil { - return nil, err - } - } - } - return nil, ErrNotExist{"", relpath} -} - -func (t *Tree) GetBlobByPath(relpath string) (*Blob, error) { - entry, err := t.GetTreeEntryByPath(relpath) - if err != nil { - return nil, err - } - - if !entry.IsDir() { - return entry.Blob(), nil - } - - return nil, ErrNotExist{"", relpath} -} diff --git a/vendor/github.com/gogits/git-module/tree_entry.go b/vendor/github.com/gogits/git-module/tree_entry.go deleted file mode 100644 index 54574035..00000000 --- a/vendor/github.com/gogits/git-module/tree_entry.go +++ /dev/null @@ -1,226 +0,0 @@ -// Copyright 2015 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package git - -import ( - "fmt" - "path" - "path/filepath" - "runtime" - "sort" - "strconv" - "strings" -) - -type EntryMode int - -// There are only a few file modes in Git. They look like unix file modes, but they can only be -// one of these. -const ( - ENTRY_MODE_BLOB EntryMode = 0100644 - ENTRY_MODE_EXEC EntryMode = 0100755 - ENTRY_MODE_SYMLINK EntryMode = 0120000 - ENTRY_MODE_COMMIT EntryMode = 0160000 - ENTRY_MODE_TREE EntryMode = 0040000 -) - -type TreeEntry struct { - ID sha1 - Type ObjectType - - mode EntryMode - name string - - ptree *Tree - - commited bool - - size int64 - sized bool -} - -func (te *TreeEntry) Name() string { - return te.name -} - -func (te *TreeEntry) Size() int64 { - if te.IsDir() { - return 0 - } else if te.sized { - return te.size - } - - stdout, err := NewCommand("cat-file", "-s", te.ID.String()).RunInDir(te.ptree.repo.Path) - if err != nil { - return 0 - } - - te.sized = true - te.size, _ = strconv.ParseInt(strings.TrimSpace(stdout), 10, 64) - return te.size -} - -func (te *TreeEntry) IsSubModule() bool { - return te.mode == ENTRY_MODE_COMMIT -} - -func (te *TreeEntry) IsDir() bool { - return te.mode == ENTRY_MODE_TREE -} - -func (te *TreeEntry) IsLink() bool { - return te.mode == ENTRY_MODE_SYMLINK -} - -func (te *TreeEntry) Blob() *Blob { - return &Blob{ - repo: te.ptree.repo, - TreeEntry: te, - } -} - -type Entries []*TreeEntry - -var sorter = []func(t1, t2 *TreeEntry) bool{ - func(t1, t2 *TreeEntry) bool { - return (t1.IsDir() || t1.IsSubModule()) && !t2.IsDir() && !t2.IsSubModule() - }, - func(t1, t2 *TreeEntry) bool { - return t1.name < t2.name - }, -} - -func (tes Entries) Len() int { return len(tes) } -func (tes Entries) Swap(i, j int) { tes[i], tes[j] = tes[j], tes[i] } -func (tes Entries) Less(i, j int) bool { - t1, t2 := tes[i], tes[j] - var k int - for k = 0; k < len(sorter)-1; k++ { - sort := sorter[k] - switch { - case sort(t1, t2): - return true - case sort(t2, t1): - return false - } - } - return sorter[k](t1, t2) -} - -func (tes Entries) Sort() { - sort.Sort(tes) -} - -var defaultConcurrency = runtime.NumCPU() - -type commitInfo struct { - entryName string - infos []interface{} - err error -} - -// GetCommitsInfo takes advantages of concurrency to speed up getting information -// of all commits that are corresponding to these entries. This method will automatically -// choose the right number of goroutine (concurrency) to use related of the host CPU. -func (tes Entries) GetCommitsInfo(commit *Commit, treePath string) ([][]interface{}, error) { - return tes.GetCommitsInfoWithCustomConcurrency(commit, treePath, 0) -} - -// GetCommitsInfoWithCustomConcurrency takes advantages of concurrency to speed up getting information -// of all commits that are corresponding to these entries. If the given maxConcurrency is negative or -// equal to zero: the right number of goroutine (concurrency) to use will be choosen related of the -// host CPU. -func (tes Entries) GetCommitsInfoWithCustomConcurrency(commit *Commit, treePath string, maxConcurrency int) ([][]interface{}, error) { - if len(tes) == 0 { - return nil, nil - } - - if maxConcurrency <= 0 { - maxConcurrency = defaultConcurrency - } - - // Length of taskChan determines how many goroutines (subprocesses) can run at the same time. - // The length of revChan should be same as taskChan so goroutines whoever finished job can - // exit as early as possible, only store data inside channel. - taskChan := make(chan bool, maxConcurrency) - revChan := make(chan commitInfo, maxConcurrency) - doneChan := make(chan error) - - // Receive loop will exit when it collects same number of data pieces as tree entries. - // It notifies doneChan before exits or notify early with possible error. - infoMap := make(map[string][]interface{}, len(tes)) - go func() { - i := 0 - for info := range revChan { - if info.err != nil { - doneChan <- info.err - return - } - - infoMap[info.entryName] = info.infos - i++ - if i == len(tes) { - break - } - } - doneChan <- nil - }() - - for i := range tes { - // When taskChan is idle (or has empty slots), put operation will not block. - // However when taskChan is full, code will block and wait any running goroutines to finish. - taskChan <- true - - if tes[i].Type != OBJECT_COMMIT { - go func(i int) { - cinfo := commitInfo{entryName: tes[i].Name()} - c, err := commit.GetCommitByPath(filepath.Join(treePath, tes[i].Name())) - if err != nil { - cinfo.err = fmt.Errorf("GetCommitByPath (%s/%s): %v", treePath, tes[i].Name(), err) - } else { - cinfo.infos = []interface{}{tes[i], c} - } - revChan <- cinfo - <-taskChan // Clear one slot from taskChan to allow new goroutines to start. - }(i) - continue - } - - // Handle submodule - go func(i int) { - cinfo := commitInfo{entryName: tes[i].Name()} - sm, err := commit.GetSubModule(path.Join(treePath, tes[i].Name())) - if err != nil && !IsErrNotExist(err) { - cinfo.err = fmt.Errorf("GetSubModule (%s/%s): %v", treePath, tes[i].Name(), err) - revChan <- cinfo - return - } - - smURL := "" - if sm != nil { - smURL = sm.URL - } - - c, err := commit.GetCommitByPath(filepath.Join(treePath, tes[i].Name())) - if err != nil { - cinfo.err = fmt.Errorf("GetCommitByPath (%s/%s): %v", treePath, tes[i].Name(), err) - } else { - cinfo.infos = []interface{}{tes[i], NewSubModuleFile(c, smURL, tes[i].ID.String())} - } - revChan <- cinfo - <-taskChan - }(i) - } - - if err := <-doneChan; err != nil { - return nil, err - } - - commitsInfo := make([][]interface{}, len(tes)) - for i := 0; i < len(tes); i++ { - commitsInfo[i] = infoMap[tes[i].Name()] - } - return commitsInfo, nil -} diff --git a/vendor/github.com/gogits/git-module/utils.go b/vendor/github.com/gogits/git-module/utils.go deleted file mode 100644 index da8c5817..00000000 --- a/vendor/github.com/gogits/git-module/utils.go +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright 2015 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package git - -import ( - "fmt" - "os" - "path/filepath" - "strings" - "sync" -) - -// objectCache provides thread-safe cache opeations. -type objectCache struct { - lock sync.RWMutex - cache map[string]interface{} -} - -func newObjectCache() *objectCache { - return &objectCache{ - cache: make(map[string]interface{}, 10), - } -} - -func (oc *objectCache) Set(id string, obj interface{}) { - oc.lock.Lock() - defer oc.lock.Unlock() - - oc.cache[id] = obj -} - -func (oc *objectCache) Get(id string) (interface{}, bool) { - oc.lock.RLock() - defer oc.lock.RUnlock() - - obj, has := oc.cache[id] - return obj, has -} - -// isDir returns true if given path is a directory, -// or returns false when it's a file or does not exist. -func isDir(dir string) bool { - f, e := os.Stat(dir) - if e != nil { - return false - } - return f.IsDir() -} - -// isFile returns true if given path is a file, -// or returns false when it's a directory or does not exist. -func isFile(filePath string) bool { - f, e := os.Stat(filePath) - if e != nil { - return false - } - return !f.IsDir() -} - -// isExist checks whether a file or directory exists. -// It returns false when the file or directory does not exist. -func isExist(path string) bool { - _, err := os.Stat(path) - return err == nil || os.IsExist(err) -} - -func concatenateError(err error, stderr string) error { - if len(stderr) == 0 { - return err - } - return fmt.Errorf("%v - %s", err, stderr) -} - -// If the object is stored in its own file (i.e not in a pack file), -// this function returns the full path to the object file. -// It does not test if the file exists. -func filepathFromSHA1(rootdir, sha1 string) string { - return filepath.Join(rootdir, "objects", sha1[:2], sha1[2:]) -} - -func RefEndName(refStr string) string { - if strings.HasPrefix(refStr, BRANCH_PREFIX) { - return refStr[len(BRANCH_PREFIX):] - } - - if strings.HasPrefix(refStr, TAG_PREFIX) { - return refStr[len(TAG_PREFIX):] - } - - return refStr -} diff --git a/vendor/github.com/gogits/go-gogs-client/LICENSE b/vendor/github.com/gogits/go-gogs-client/LICENSE deleted file mode 100644 index 18b264d6..00000000 --- a/vendor/github.com/gogits/go-gogs-client/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2014 Go Git Service - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - diff --git a/vendor/github.com/gogits/go-gogs-client/README.md b/vendor/github.com/gogits/go-gogs-client/README.md deleted file mode 100644 index ae33bc06..00000000 --- a/vendor/github.com/gogits/go-gogs-client/README.md +++ /dev/null @@ -1,8 +0,0 @@ -Gogs API client in Go -===================== - -This package is still in experiment, see [Wiki](https://github.com/gogits/go-gogs-client/wiki) for documentation. - -## License - -This project is under the MIT License. See the [LICENSE](https://github.com/gogits/gogs/blob/master/LICENSE) file for the full license text. \ No newline at end of file diff --git a/vendor/github.com/gogits/go-gogs-client/admin_org.go b/vendor/github.com/gogits/go-gogs-client/admin_org.go deleted file mode 100644 index be140625..00000000 --- a/vendor/github.com/gogits/go-gogs-client/admin_org.go +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2015 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package gogs - -import ( - "bytes" - "encoding/json" - "fmt" -) - -func (c *Client) AdminCreateOrg(user string, opt CreateOrgOption) (*Organization, error) { - body, err := json.Marshal(&opt) - if err != nil { - return nil, err - } - org := new(Organization) - return org, c.getParsedResponse("POST", fmt.Sprintf("/admin/users/%s/orgs", user), - jsonHeader, bytes.NewReader(body), org) -} diff --git a/vendor/github.com/gogits/go-gogs-client/admin_repo.go b/vendor/github.com/gogits/go-gogs-client/admin_repo.go deleted file mode 100644 index 50ba2be4..00000000 --- a/vendor/github.com/gogits/go-gogs-client/admin_repo.go +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2015 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package gogs - -import ( - "bytes" - "encoding/json" - "fmt" -) - -func (c *Client) AdminCreateRepo(user string, opt CreateRepoOption) (*Repository, error) { - body, err := json.Marshal(&opt) - if err != nil { - return nil, err - } - repo := new(Repository) - return repo, c.getParsedResponse("POST", fmt.Sprintf("/admin/users/%s/repos", user), - jsonHeader, bytes.NewReader(body), repo) -} diff --git a/vendor/github.com/gogits/go-gogs-client/admin_user.go b/vendor/github.com/gogits/go-gogs-client/admin_user.go deleted file mode 100644 index 459031d7..00000000 --- a/vendor/github.com/gogits/go-gogs-client/admin_user.go +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright 2015 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package gogs - -import ( - "bytes" - "encoding/json" - "fmt" -) - -type CreateUserOption struct { - SourceID int64 `json:"source_id"` - LoginName string `json:"login_name"` - Username string `json:"username" binding:"Required;AlphaDashDot;MaxSize(35)"` - FullName string `json:"full_name" binding:"MaxSize(100)"` - Email string `json:"email" binding:"Required;Email;MaxSize(254)"` - Password string `json:"password" binding:"MaxSize(255)"` - SendNotify bool `json:"send_notify"` -} - -func (c *Client) AdminCreateUser(opt CreateUserOption) (*User, error) { - body, err := json.Marshal(&opt) - if err != nil { - return nil, err - } - user := new(User) - return user, c.getParsedResponse("POST", "/admin/users", jsonHeader, bytes.NewReader(body), user) -} - -type EditUserOption struct { - SourceID int64 `json:"source_id"` - LoginName string `json:"login_name"` - FullName string `json:"full_name" binding:"MaxSize(100)"` - Email string `json:"email" binding:"Required;Email;MaxSize(254)"` - Password string `json:"password" binding:"MaxSize(255)"` - Website string `json:"website" binding:"MaxSize(50)"` - Location string `json:"location" binding:"MaxSize(50)"` - Active *bool `json:"active"` - Admin *bool `json:"admin"` - AllowGitHook *bool `json:"allow_git_hook"` - AllowImportLocal *bool `json:"allow_import_local"` - MaxRepoCreation *int `json:"max_repo_creation"` -} - -func (c *Client) AdminEditUser(user string, opt EditUserOption) error { - body, err := json.Marshal(&opt) - if err != nil { - return err - } - _, err = c.getResponse("PATCH", fmt.Sprintf("/admin/users/%s", user), jsonHeader, bytes.NewReader(body)) - return err -} - -func (c *Client) AdminDeleteUser(user string) error { - _, err := c.getResponse("DELETE", fmt.Sprintf("/admin/users/%s", user), nil, nil) - return err -} - -func (c *Client) AdminCreateUserPublicKey(user string, opt CreateKeyOption) (*PublicKey, error) { - body, err := json.Marshal(&opt) - if err != nil { - return nil, err - } - key := new(PublicKey) - return key, c.getParsedResponse("POST", fmt.Sprintf("/admin/users/%s/keys", user), jsonHeader, bytes.NewReader(body), key) -} diff --git a/vendor/github.com/gogits/go-gogs-client/gogs.go b/vendor/github.com/gogits/go-gogs-client/gogs.go deleted file mode 100644 index 1c81d16f..00000000 --- a/vendor/github.com/gogits/go-gogs-client/gogs.go +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright 2014 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package gogs - -import ( - "encoding/json" - "errors" - "io" - "io/ioutil" - "net/http" - "strings" -) - -func Version() string { - return "0.12.12" -} - -// Client represents a Gogs API client. -type Client struct { - url string - accessToken string - client *http.Client -} - -// NewClient initializes and returns a API client. -func NewClient(url, token string) *Client { - return &Client{ - url: strings.TrimSuffix(url, "/"), - accessToken: token, - client: &http.Client{}, - } -} - -// SetHTTPClient replaces default http.Client with user given one. -func (c *Client) SetHTTPClient(client *http.Client) { - c.client = client -} - -func (c *Client) doRequest(method, path string, header http.Header, body io.Reader) (*http.Response, error) { - req, err := http.NewRequest(method, c.url+"/api/v1"+path, body) - if err != nil { - return nil, err - } - req.Header.Set("Authorization", "token "+c.accessToken) - for k, v := range header { - req.Header[k] = v - } - - return c.client.Do(req) -} - -func (c *Client) getResponse(method, path string, header http.Header, body io.Reader) ([]byte, error) { - resp, err := c.doRequest(method, path, header, body) - if err != nil { - return nil, err - } - defer resp.Body.Close() - - data, err := ioutil.ReadAll(resp.Body) - if err != nil { - return nil, err - } - - switch resp.StatusCode { - case 403: - return nil, errors.New("403 Forbidden") - case 404: - return nil, errors.New("404 Not Found") - } - - if resp.StatusCode/100 != 2 { - errMap := make(map[string]interface{}) - if err = json.Unmarshal(data, &errMap); err != nil { - return nil, err - } - return nil, errors.New(errMap["message"].(string)) - } - - return data, nil -} - -func (c *Client) getParsedResponse(method, path string, header http.Header, body io.Reader, obj interface{}) error { - data, err := c.getResponse(method, path, header, body) - if err != nil { - return err - } - return json.Unmarshal(data, obj) -} diff --git a/vendor/github.com/gogits/go-gogs-client/issue.go b/vendor/github.com/gogits/go-gogs-client/issue.go deleted file mode 100644 index aa2f0d8e..00000000 --- a/vendor/github.com/gogits/go-gogs-client/issue.go +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright 2016 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package gogs - -import ( - "bytes" - "encoding/json" - "fmt" - "time" -) - -type StateType string - -const ( - STATE_OPEN StateType = "open" - STATE_CLOSED StateType = "closed" -) - -type PullRequestMeta struct { - HasMerged bool `json:"merged"` - Merged *time.Time `json:"merged_at"` -} - -type Issue struct { - ID int64 `json:"id"` - Index int64 `json:"number"` - Poster *User `json:"user"` - Title string `json:"title"` - Body string `json:"body"` - Labels []*Label `json:"labels"` - Milestone *Milestone `json:"milestone"` - Assignee *User `json:"assignee"` - State StateType `json:"state"` - Comments int `json:"comments"` - Created time.Time `json:"created_at"` - Updated time.Time `json:"updated_at"` - - PullRequest *PullRequestMeta `json:"pull_request"` -} - -type ListIssueOption struct { - Page int - State string -} - -func (c *Client) ListIssues(opt ListIssueOption) ([]*Issue, error) { - issues := make([]*Issue, 0, 10) - return issues, c.getParsedResponse("GET", fmt.Sprintf("/issues?page=%d", opt.Page), nil, nil, &issues) -} - -func (c *Client) ListUserIssues(opt ListIssueOption) ([]*Issue, error) { - issues := make([]*Issue, 0, 10) - return issues, c.getParsedResponse("GET", fmt.Sprintf("/user/issues?page=%d", opt.Page), nil, nil, &issues) -} - -func (c *Client) ListRepoIssues(owner, repo string, opt ListIssueOption) ([]*Issue, error) { - issues := make([]*Issue, 0, 10) - return issues, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues?page=%d", owner, repo, opt.Page), nil, nil, &issues) -} - -func (c *Client) GetIssue(owner, repo string, index int64) (*Issue, error) { - issue := new(Issue) - return issue, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d", owner, repo, index), nil, nil, issue) -} - -type CreateIssueOption struct { - Title string `json:"title" binding:"Required"` - Body string `json:"body"` - Assignee string `json:"assignee"` - Milestone int64 `json:"milestone"` - Labels []int64 `json:"labels"` - Closed bool `json:"closed"` -} - -func (c *Client) CreateIssue(owner, repo string, opt CreateIssueOption) (*Issue, error) { - body, err := json.Marshal(&opt) - if err != nil { - return nil, err - } - issue := new(Issue) - return issue, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues", owner, repo), - jsonHeader, bytes.NewReader(body), issue) -} - -type EditIssueOption struct { - Title string `json:"title"` - Body *string `json:"body"` - Assignee *string `json:"assignee"` - Milestone *int64 `json:"milestone"` - State *string `json:"state"` -} - -func (c *Client) EditIssue(owner, repo string, index int64, opt EditIssueOption) (*Issue, error) { - body, err := json.Marshal(&opt) - if err != nil { - return nil, err - } - issue := new(Issue) - return issue, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/issues/%d", owner, repo, index), - jsonHeader, bytes.NewReader(body), issue) -} diff --git a/vendor/github.com/gogits/go-gogs-client/issue_comment.go b/vendor/github.com/gogits/go-gogs-client/issue_comment.go deleted file mode 100644 index 246af0d9..00000000 --- a/vendor/github.com/gogits/go-gogs-client/issue_comment.go +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright 2016 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package gogs - -import ( - "bytes" - "encoding/json" - "fmt" - "time" -) - -// Comment represents a comment in commit and issue page. -type Comment struct { - ID int64 `json:"id"` - HTMLURL string `json:"html_url"` - Poster *User `json:"user"` - Body string `json:"body"` - Created time.Time `json:"created_at"` - Updated time.Time `json:"updated_at"` -} - -// ListIssueComments list comments on an issue. -func (c *Client) ListIssueComments(owner, repo string, index int64) ([]*Comment, error) { - comments := make([]*Comment, 0, 10) - return comments, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/comments", owner, repo, index), nil, nil, &comments) -} - -// ListRepoIssueComments list comments for a given repo. -func (c *Client) ListRepoIssueComments(owner, repo string) ([]*Comment, error) { - comments := make([]*Comment, 0, 10) - return comments, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/comments", owner, repo), nil, nil, &comments) -} - -// CreateIssueCommentOption is option when creating an issue comment. -type CreateIssueCommentOption struct { - Body string `json:"body" binding:"Required"` -} - -// CreateIssueComment create comment on an issue. -func (c *Client) CreateIssueComment(owner, repo string, index int64, opt CreateIssueCommentOption) (*Comment, error) { - body, err := json.Marshal(&opt) - if err != nil { - return nil, err - } - comment := new(Comment) - return comment, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues/%d/comments", owner, repo, index), jsonHeader, bytes.NewReader(body), comment) -} - -// EditIssueCommentOption is option when editing an issue comment. -type EditIssueCommentOption struct { - Body string `json:"body" binding:"Required"` -} - -// EditIssueComment edits an issue comment. -func (c *Client) EditIssueComment(owner, repo string, index, commentID int64, opt EditIssueCommentOption) (*Comment, error) { - body, err := json.Marshal(&opt) - if err != nil { - return nil, err - } - comment := new(Comment) - return comment, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/issues/%d/comments/%d", owner, repo, index, commentID), jsonHeader, bytes.NewReader(body), comment) -} - -// DeleteIssueComment deletes an issue comment. -func (c *Client) DeleteIssueComment(owner, repo string, index, commentID int64) error { - _, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/comments/%d", owner, repo, index, commentID), nil, nil) - return err -} diff --git a/vendor/github.com/gogits/go-gogs-client/issue_label.go b/vendor/github.com/gogits/go-gogs-client/issue_label.go deleted file mode 100644 index b8ff3009..00000000 --- a/vendor/github.com/gogits/go-gogs-client/issue_label.go +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright 2016 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package gogs - -import ( - "bytes" - "encoding/json" - "fmt" -) - -type Label struct { - ID int64 `json:"id"` - Name string `json:"name"` - Color string `json:"color"` - URL string `json:"url"` -} - -func (c *Client) ListRepoLabels(owner, repo string) ([]*Label, error) { - labels := make([]*Label, 0, 10) - return labels, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/labels", owner, repo), nil, nil, &labels) -} - -func (c *Client) GetRepoLabel(owner, repo string, id int64) (*Label, error) { - label := new(Label) - return label, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/labels/%d", owner, repo, id), nil, nil, label) -} - -type CreateLabelOption struct { - Name string `json:"name" binding:"Required"` - Color string `json:"color" binding:"Required;Size(7)"` -} - -func (c *Client) CreateLabel(owner, repo string, opt CreateLabelOption) (*Label, error) { - body, err := json.Marshal(&opt) - if err != nil { - return nil, err - } - label := new(Label) - return label, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/labels", owner, repo), - jsonHeader, bytes.NewReader(body), label) -} - -type EditLabelOption struct { - Name *string `json:"name"` - Color *string `json:"color"` -} - -func (c *Client) EditLabel(owner, repo string, id int64, opt EditLabelOption) (*Label, error) { - body, err := json.Marshal(&opt) - if err != nil { - return nil, err - } - label := new(Label) - return label, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/labels/%d", owner, repo, id), jsonHeader, bytes.NewReader(body), label) -} - -func (c *Client) DeleteLabel(owner, repo string, id int64) error { - _, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/labels/%d", owner, repo, id), nil, nil) - return err -} - -type IssueLabelsOption struct { - Labels []int64 `json:"labels"` -} - -func (c *Client) GetIssueLabels(owner, repo string, index int64) ([]*Label, error) { - labels := make([]*Label, 0, 5) - return labels, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/labels", owner, repo, index), nil, nil, &labels) -} - -func (c *Client) AddIssueLabels(owner, repo string, index int64, opt IssueLabelsOption) ([]*Label, error) { - body, err := json.Marshal(&opt) - if err != nil { - return nil, err - } - labels := make([]*Label, 0) - return labels, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues/%d/labels", owner, repo, index), jsonHeader, bytes.NewReader(body), &labels) -} - -func (c *Client) ReplaceIssueLabels(owner, repo string, index int64, opt IssueLabelsOption) ([]*Label, error) { - body, err := json.Marshal(&opt) - if err != nil { - return nil, err - } - labels := make([]*Label, 0) - return labels, c.getParsedResponse("PUT", fmt.Sprintf("/repos/%s/%s/issues/%d/labels", owner, repo, index), jsonHeader, bytes.NewReader(body), &labels) -} - -func (c *Client) DeleteIssueLabel(owner, repo string, index, label int64) error { - _, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/labels/%d", owner, repo, index, label), nil, nil) - return err -} - -func (c *Client) ClearIssueLabels(owner, repo string, index int64) error { - _, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/labels", owner, repo, index), nil, nil) - return err -} diff --git a/vendor/github.com/gogits/go-gogs-client/issue_milestone.go b/vendor/github.com/gogits/go-gogs-client/issue_milestone.go deleted file mode 100644 index ad27a15e..00000000 --- a/vendor/github.com/gogits/go-gogs-client/issue_milestone.go +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright 2016 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package gogs - -import ( - "bytes" - "encoding/json" - "fmt" - "time" -) - -type Milestone struct { - ID int64 `json:"id"` - Title string `json:"title"` - Description string `json:"description"` - State StateType `json:"state"` - OpenIssues int `json:"open_issues"` - ClosedIssues int `json:"closed_issues"` - Closed *time.Time `json:"closed_at"` - Deadline *time.Time `json:"due_on"` -} - -func (c *Client) ListRepoMilestones(owner, repo string) ([]*Milestone, error) { - milestones := make([]*Milestone, 0, 10) - return milestones, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/milestones", owner, repo), nil, nil, &milestones) -} - -func (c *Client) GetMilestone(owner, repo string, id int64) (*Milestone, error) { - milestone := new(Milestone) - return milestone, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/milestones/%d", owner, repo, id), nil, nil, milestone) -} - -type CreateMilestoneOption struct { - Title string `json:"title"` - Description string `json:"description"` - Deadline *time.Time `json:"due_on"` -} - -func (c *Client) CreateMilestone(owner, repo string, opt CreateMilestoneOption) (*Milestone, error) { - body, err := json.Marshal(&opt) - if err != nil { - return nil, err - } - milestone := new(Milestone) - return milestone, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/milestones", owner, repo), jsonHeader, bytes.NewReader(body), milestone) -} - -type EditMilestoneOption struct { - Title string `json:"title"` - Description *string `json:"description"` - State *string `json:"state"` - Deadline *time.Time `json:"due_on"` -} - -func (c *Client) EditMilestone(owner, repo string, id int64, opt EditMilestoneOption) (*Milestone, error) { - body, err := json.Marshal(&opt) - if err != nil { - return nil, err - } - milestone := new(Milestone) - return milestone, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/milestones/%d", owner, repo, id), jsonHeader, bytes.NewReader(body), milestone) -} - -func (c *Client) DeleteMilestone(owner, repo string, id int64) error { - _, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/milestones/%d", owner, repo, id), nil, nil) - return err -} diff --git a/vendor/github.com/gogits/go-gogs-client/miscellaneous.go b/vendor/github.com/gogits/go-gogs-client/miscellaneous.go deleted file mode 100644 index fcf362ce..00000000 --- a/vendor/github.com/gogits/go-gogs-client/miscellaneous.go +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright 2015 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package gogs - -type MarkdownOption struct { - Text string - Mode string - Context string -} diff --git a/vendor/github.com/gogits/go-gogs-client/org.go b/vendor/github.com/gogits/go-gogs-client/org.go deleted file mode 100644 index 08d00882..00000000 --- a/vendor/github.com/gogits/go-gogs-client/org.go +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright 2015 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package gogs - -import ( - "bytes" - "encoding/json" - "fmt" -) - -type Organization struct { - ID int64 `json:"id"` - UserName string `json:"username"` - FullName string `json:"full_name"` - AvatarUrl string `json:"avatar_url"` - Description string `json:"description"` - Website string `json:"website"` - Location string `json:"location"` -} - -func (c *Client) ListMyOrgs() ([]*Organization, error) { - orgs := make([]*Organization, 0, 5) - return orgs, c.getParsedResponse("GET", "/user/orgs", nil, nil, &orgs) -} - -func (c *Client) ListUserOrgs(user string) ([]*Organization, error) { - orgs := make([]*Organization, 0, 5) - return orgs, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/orgs", user), nil, nil, &orgs) -} - -func (c *Client) GetOrg(orgname string) (*Organization, error) { - org := new(Organization) - return org, c.getParsedResponse("GET", fmt.Sprintf("/orgs/%s", orgname), nil, nil, org) -} - -type CreateOrgOption struct { - UserName string `json:"username" binding:"Required"` - FullName string `json:"full_name"` - Description string `json:"description"` - Website string `json:"website"` - Location string `json:"location"` -} - -type EditOrgOption struct { - FullName string `json:"full_name"` - Description string `json:"description"` - Website string `json:"website"` - Location string `json:"location"` -} - -func (c *Client) EditOrg(orgname string, opt EditOrgOption) error { - body, err := json.Marshal(&opt) - if err != nil { - return err - } - _, err = c.getResponse("PATCH", fmt.Sprintf("/orgs/%s", orgname), jsonHeader, bytes.NewReader(body)) - return err -} diff --git a/vendor/github.com/gogits/go-gogs-client/org_member.go b/vendor/github.com/gogits/go-gogs-client/org_member.go deleted file mode 100644 index d9cdadab..00000000 --- a/vendor/github.com/gogits/go-gogs-client/org_member.go +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2016 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package gogs - -import ( - "bytes" - "encoding/json" - "fmt" -) - -type AddOrgMembershipOption struct { - Role string `json:"role" binding:"Required"` -} - -func (c *Client) AddOrgMembership(org, user string, opt AddOrgMembershipOption) error { - body, err := json.Marshal(&opt) - if err != nil { - return err - } - _, err = c.getResponse("PUT", fmt.Sprintf("/orgs/%s/membership/%s", org, user), jsonHeader, bytes.NewReader(body)) - return err -} diff --git a/vendor/github.com/gogits/go-gogs-client/org_team.go b/vendor/github.com/gogits/go-gogs-client/org_team.go deleted file mode 100644 index 89f09e3f..00000000 --- a/vendor/github.com/gogits/go-gogs-client/org_team.go +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2016 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package gogs - -type Team struct { - ID int64 `json:"id"` - Name string `json:"name"` - Description string `json:"description"` - Permission string `json:"permission"` -} - -type CreateTeamOption struct { - Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(30)"` - Description string `json:"description" binding:"MaxSize(255)"` - Permission string `json:"permission"` -} diff --git a/vendor/github.com/gogits/go-gogs-client/pull.go b/vendor/github.com/gogits/go-gogs-client/pull.go deleted file mode 100644 index be93b269..00000000 --- a/vendor/github.com/gogits/go-gogs-client/pull.go +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2016 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package gogs - -import ( - "time" -) - -// PullRequest represents a pull reqesut API object. -type PullRequest struct { - // Copied from issue.go - ID int64 `json:"id"` - Index int64 `json:"number"` - Poster *User `json:"user"` - Title string `json:"title"` - Body string `json:"body"` - Labels []*Label `json:"labels"` - Milestone *Milestone `json:"milestone"` - Assignee *User `json:"assignee"` - State StateType `json:"state"` - Comments int `json:"comments"` - - HeadBranch string `json:"head_branch"` - HeadRepo *Repository `json:"head_repo"` - BaseBranch string `json:"base_branch"` - BaseRepo *Repository `json:"base_repo"` - - HTMLURL string `json:"html_url"` - - Mergeable *bool `json:"mergeable"` - HasMerged bool `json:"merged"` - Merged *time.Time `json:"merged_at"` - MergedCommitID *string `json:"merge_commit_sha"` - MergedBy *User `json:"merged_by"` -} diff --git a/vendor/github.com/gogits/go-gogs-client/release.go b/vendor/github.com/gogits/go-gogs-client/release.go deleted file mode 100644 index 69c7f3b9..00000000 --- a/vendor/github.com/gogits/go-gogs-client/release.go +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2017 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package gogs - -import ( - "time" -) - -// Release represents a release API object. -type Release struct { - ID int64 `json:"id"` - TagName string `json:"tag_name"` - TargetCommitish string `json:"target_commitish"` - Name string `json:"name"` - Body string `json:"body"` - Draft bool `json:"draft"` - Prerelease bool `json:"prerelease"` - Author *User `json:"author"` - Created time.Time `json:"created_at"` -} diff --git a/vendor/github.com/gogits/go-gogs-client/repo.go b/vendor/github.com/gogits/go-gogs-client/repo.go deleted file mode 100644 index 48ded475..00000000 --- a/vendor/github.com/gogits/go-gogs-client/repo.go +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright 2014 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package gogs - -import ( - "bytes" - "encoding/json" - "fmt" - "time" -) - -// Permission represents a API permission. -type Permission struct { - Admin bool `json:"admin"` - Push bool `json:"push"` - Pull bool `json:"pull"` -} - -// Repository represents a API repository. -type Repository struct { - ID int64 `json:"id"` - Owner *User `json:"owner"` - Name string `json:"name"` - FullName string `json:"full_name"` - Description string `json:"description"` - Private bool `json:"private"` - Fork bool `json:"fork"` - Parent *Repository `json:"parent"` - Empty bool `json:"empty"` - Mirror bool `json:"mirror"` - Size int64 `json:"size"` - HTMLURL string `json:"html_url"` - SSHURL string `json:"ssh_url"` - CloneURL string `json:"clone_url"` - Website string `json:"website"` - Stars int `json:"stars_count"` - Forks int `json:"forks_count"` - Watchers int `json:"watchers_count"` - OpenIssues int `json:"open_issues_count"` - DefaultBranch string `json:"default_branch"` - Created time.Time `json:"created_at"` - Updated time.Time `json:"updated_at"` - Permissions *Permission `json:"permissions,omitempty"` -} - -// ListMyRepos lists all repositories for the authenticated user that has access to. -func (c *Client) ListMyRepos() ([]*Repository, error) { - repos := make([]*Repository, 0, 10) - return repos, c.getParsedResponse("GET", "/user/repos", nil, nil, &repos) -} - -func (c *Client) ListUserRepos(user string) ([]*Repository, error) { - repos := make([]*Repository, 0, 10) - return repos, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/repos", user), nil, nil, &repos) -} - -func (c *Client) ListOrgRepos(org string) ([]*Repository, error) { - repos := make([]*Repository, 0, 10) - return repos, c.getParsedResponse("GET", fmt.Sprintf("/orgs/%s/repos", org), nil, nil, &repos) -} - -type CreateRepoOption struct { - Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(100)"` - Description string `json:"description" binding:"MaxSize(255)"` - Private bool `json:"private"` - AutoInit bool `json:"auto_init"` - Gitignores string `json:"gitignores"` - License string `json:"license"` - Readme string `json:"readme"` -} - -// CreateRepo creates a repository for authenticated user. -func (c *Client) CreateRepo(opt CreateRepoOption) (*Repository, error) { - body, err := json.Marshal(&opt) - if err != nil { - return nil, err - } - repo := new(Repository) - return repo, c.getParsedResponse("POST", "/user/repos", jsonHeader, bytes.NewReader(body), repo) -} - -// CreateOrgRepo creates an organization repository for authenticated user. -func (c *Client) CreateOrgRepo(org string, opt CreateRepoOption) (*Repository, error) { - body, err := json.Marshal(&opt) - if err != nil { - return nil, err - } - repo := new(Repository) - return repo, c.getParsedResponse("POST", fmt.Sprintf("/org/%s/repos", org), jsonHeader, bytes.NewReader(body), repo) -} - -// GetRepo returns information of a repository of given owner. -func (c *Client) GetRepo(owner, reponame string) (*Repository, error) { - repo := new(Repository) - return repo, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s", owner, reponame), nil, nil, repo) -} - -// DeleteRepo deletes a repository of user or organization. -func (c *Client) DeleteRepo(owner, repo string) error { - _, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s", owner, repo), nil, nil) - return err -} - -type MigrateRepoOption struct { - CloneAddr string `json:"clone_addr" binding:"Required"` - AuthUsername string `json:"auth_username"` - AuthPassword string `json:"auth_password"` - UID int `json:"uid" binding:"Required"` - RepoName string `json:"repo_name" binding:"Required"` - Mirror bool `json:"mirror"` - Private bool `json:"private"` - Description string `json:"description"` -} - -// MigrateRepo migrates a repository from other Git hosting sources for the -// authenticated user. -// -// To migrate a repository for a organization, the authenticated user must be a -// owner of the specified organization. -func (c *Client) MigrateRepo(opt MigrateRepoOption) (*Repository, error) { - body, err := json.Marshal(&opt) - if err != nil { - return nil, err - } - repo := new(Repository) - return repo, c.getParsedResponse("POST", "/repos/migrate", jsonHeader, bytes.NewReader(body), repo) -} diff --git a/vendor/github.com/gogits/go-gogs-client/repo_branch.go b/vendor/github.com/gogits/go-gogs-client/repo_branch.go deleted file mode 100644 index 1e581121..00000000 --- a/vendor/github.com/gogits/go-gogs-client/repo_branch.go +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2016 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package gogs - -import ( - "fmt" -) - -// Branch represents a repository branch. -type Branch struct { - Name string `json:"name"` - Commit *PayloadCommit `json:"commit"` -} - -func (c *Client) ListRepoBranches(user, repo string) ([]*Branch, error) { - branches := make([]*Branch, 0, 10) - return branches, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/branches", user, repo), nil, nil, &branches) -} - -func (c *Client) GetRepoBranch(user, repo, branch string) (*Branch, error) { - b := new(Branch) - return b, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/branches/%s", user, repo, branch), nil, nil, &b) -} diff --git a/vendor/github.com/gogits/go-gogs-client/repo_collaborator.go b/vendor/github.com/gogits/go-gogs-client/repo_collaborator.go deleted file mode 100644 index c382bc77..00000000 --- a/vendor/github.com/gogits/go-gogs-client/repo_collaborator.go +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2016 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package gogs - -import ( - "bytes" - "encoding/json" - "fmt" -) - -type Collaborator struct { - *User - Permissions Permission `json:"permissions"` -} - -type AddCollaboratorOption struct { - Permission *string `json:"permission"` -} - -func (c *Client) ListCollaborator(user, repo string) ([]*Collaborator, error) { - collabs := make([]*Collaborator, 0, 10) - return collabs, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/collaborators", user, repo), nil, nil, &collabs) -} - -func (c *Client) AddCollaborator(user, repo, collaborator string, opt AddCollaboratorOption) error { - body, err := json.Marshal(&opt) - if err != nil { - return err - } - _, err = c.getResponse("PUT", fmt.Sprintf("/repos/%s/%s/collaborators/%s", user, repo, collaborator), nil, bytes.NewReader(body)) - return err -} - -func (c *Client) DeleteCollaborator(user, repo, collaborator string) error { - _, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/collaborators/%s", user, repo, collaborator), nil, nil) - return err -} - -func (c *Client) IsCollaborator(user, repo, collaborator string) error { - _, err := c.getResponse("GET", fmt.Sprintf("/repos/%s/%s/collaborators/%s", user, repo, collaborator), nil, nil) - return err -} diff --git a/vendor/github.com/gogits/go-gogs-client/repo_file.go b/vendor/github.com/gogits/go-gogs-client/repo_file.go deleted file mode 100644 index c50708b4..00000000 --- a/vendor/github.com/gogits/go-gogs-client/repo_file.go +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2014 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package gogs - -import ( - "fmt" -) - -// GetFile downloads a file of repository, ref can be branch/tag/commit. -// e.g.: ref -> master, tree -> macaron.go(no leading slash) -func (c *Client) GetFile(user, repo, ref, tree string) ([]byte, error) { - return c.getResponse("GET", fmt.Sprintf("/repos/%s/%s/raw/%s/%s", user, repo, ref, tree), nil, nil) -} diff --git a/vendor/github.com/gogits/go-gogs-client/repo_hook.go b/vendor/github.com/gogits/go-gogs-client/repo_hook.go deleted file mode 100644 index 3d06b9fc..00000000 --- a/vendor/github.com/gogits/go-gogs-client/repo_hook.go +++ /dev/null @@ -1,344 +0,0 @@ -// Copyright 2014 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package gogs - -import ( - "bytes" - "encoding/json" - "errors" - "fmt" - "strings" - "time" -) - -var ( - ErrInvalidReceiveHook = errors.New("Invalid JSON payload received over webhook") -) - -type Hook struct { - ID int64 `json:"id"` - Type string `json:"type"` - URL string `json:"-"` - Config map[string]string `json:"config"` - Events []string `json:"events"` - Active bool `json:"active"` - Updated time.Time `json:"updated_at"` - Created time.Time `json:"created_at"` -} - -func (c *Client) ListRepoHooks(user, repo string) ([]*Hook, error) { - hooks := make([]*Hook, 0, 10) - return hooks, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/hooks", user, repo), nil, nil, &hooks) -} - -type CreateHookOption struct { - Type string `json:"type" binding:"Required"` - Config map[string]string `json:"config" binding:"Required"` - Events []string `json:"events"` - Active bool `json:"active"` -} - -func (c *Client) CreateRepoHook(user, repo string, opt CreateHookOption) (*Hook, error) { - body, err := json.Marshal(&opt) - if err != nil { - return nil, err - } - h := new(Hook) - return h, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/hooks", user, repo), jsonHeader, bytes.NewReader(body), h) -} - -type EditHookOption struct { - Config map[string]string `json:"config"` - Events []string `json:"events"` - Active *bool `json:"active"` -} - -func (c *Client) EditRepoHook(user, repo string, id int64, opt EditHookOption) error { - body, err := json.Marshal(&opt) - if err != nil { - return err - } - _, err = c.getResponse("PATCH", fmt.Sprintf("/repos/%s/%s/hooks/%d", user, repo, id), jsonHeader, bytes.NewReader(body)) - return err -} - -func (c *Client) DeleteRepoHook(user, repo string, id int64) error { - _, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/hooks/%d", user, repo, id), nil, nil) - return err -} - -type Payloader interface { - JSONPayload() ([]byte, error) -} - -type PayloadUser struct { - Name string `json:"name"` - Email string `json:"email"` - UserName string `json:"username"` -} - -// FIXME: consider use same format as API when commits API are added. -type PayloadCommit struct { - ID string `json:"id"` - Message string `json:"message"` - URL string `json:"url"` - Author *PayloadUser `json:"author"` - Committer *PayloadUser `json:"committer"` - - Added []string `json:"added"` - Removed []string `json:"removed"` - Modified []string `json:"modified"` - - Timestamp time.Time `json:"timestamp"` -} - -var ( - _ Payloader = &CreatePayload{} - _ Payloader = &DeletePayload{} - _ Payloader = &ForkPayload{} - _ Payloader = &PushPayload{} - _ Payloader = &IssuesPayload{} - _ Payloader = &IssueCommentPayload{} - _ Payloader = &PullRequestPayload{} -) - -// _________ __ -// \_ ___ \_______ ____ _____ _/ |_ ____ -// / \ \/\_ __ \_/ __ \\__ \\ __\/ __ \ -// \ \____| | \/\ ___/ / __ \| | \ ___/ -// \______ /|__| \___ >____ /__| \___ > -// \/ \/ \/ \/ - -type CreatePayload struct { - Ref string `json:"ref"` - RefType string `json:"ref_type"` - DefaultBranch string `json:"default_branch"` - Repo *Repository `json:"repository"` - Sender *User `json:"sender"` -} - -func (p *CreatePayload) JSONPayload() ([]byte, error) { - return json.MarshalIndent(p, "", " ") -} - -// ParseCreateHook parses create event hook content. -func ParseCreateHook(raw []byte) (*CreatePayload, error) { - hook := new(CreatePayload) - if err := json.Unmarshal(raw, hook); err != nil { - return nil, err - } - - // it is possible the JSON was parsed, however, - // was not from Gogs (maybe was from Bitbucket) - // So we'll check to be sure certain key fields - // were populated - switch { - case hook.Repo == nil: - return nil, ErrInvalidReceiveHook - case len(hook.Ref) == 0: - return nil, ErrInvalidReceiveHook - } - return hook, nil -} - -// ________ .__ __ -// \______ \ ____ | | _____/ |_ ____ -// | | \_/ __ \| | _/ __ \ __\/ __ \ -// | ` \ ___/| |_\ ___/| | \ ___/ -// /_______ /\___ >____/\___ >__| \___ > -// \/ \/ \/ \/ - -type PusherType string - -const ( - PUSHER_TYPE_USER PusherType = "user" -) - -type DeletePayload struct { - Ref string `json:"ref"` - RefType string `json:"ref_type"` - PusherType PusherType `json:"pusher_type"` - Repo *Repository `json:"repository"` - Sender *User `json:"sender"` -} - -func (p *DeletePayload) JSONPayload() ([]byte, error) { - return json.MarshalIndent(p, "", " ") -} - -// ___________ __ -// \_ _____/__________| | __ -// | __)/ _ \_ __ \ |/ / -// | \( <_> ) | \/ < -// \___ / \____/|__| |__|_ \ -// \/ \/ - -type ForkPayload struct { - Forkee *Repository `json:"forkee"` - Repo *Repository `json:"repository"` - Sender *User `json:"sender"` -} - -func (p *ForkPayload) JSONPayload() ([]byte, error) { - return json.MarshalIndent(p, "", " ") -} - -// __________ .__ -// \______ \__ __ _____| |__ -// | ___/ | \/ ___/ | \ -// | | | | /\___ \| Y \ -// |____| |____//____ >___| / -// \/ \/ - -// PushPayload represents a payload information of push event. -type PushPayload struct { - Ref string `json:"ref"` - Before string `json:"before"` - After string `json:"after"` - CompareURL string `json:"compare_url"` - Commits []*PayloadCommit `json:"commits"` - Repo *Repository `json:"repository"` - Pusher *User `json:"pusher"` - Sender *User `json:"sender"` -} - -func (p *PushPayload) JSONPayload() ([]byte, error) { - return json.MarshalIndent(p, "", " ") -} - -// ParsePushHook parses push event hook content. -func ParsePushHook(raw []byte) (*PushPayload, error) { - hook := new(PushPayload) - if err := json.Unmarshal(raw, hook); err != nil { - return nil, err - } - - switch { - case hook.Repo == nil: - return nil, ErrInvalidReceiveHook - case len(hook.Ref) == 0: - return nil, ErrInvalidReceiveHook - } - return hook, nil -} - -// Branch returns branch name from a payload -func (p *PushPayload) Branch() string { - return strings.Replace(p.Ref, "refs/heads/", "", -1) -} - -// .___ -// | | ______ ________ __ ____ -// | |/ ___// ___/ | \_/ __ \ -// | |\___ \ \___ \| | /\ ___/ -// |___/____ >____ >____/ \___ > -// \/ \/ \/ - -type HookIssueAction string - -const ( - HOOK_ISSUE_OPENED HookIssueAction = "opened" - HOOK_ISSUE_CLOSED HookIssueAction = "closed" - HOOK_ISSUE_REOPENED HookIssueAction = "reopened" - HOOK_ISSUE_EDITED HookIssueAction = "edited" - HOOK_ISSUE_ASSIGNED HookIssueAction = "assigned" - HOOK_ISSUE_UNASSIGNED HookIssueAction = "unassigned" - HOOK_ISSUE_LABEL_UPDATED HookIssueAction = "label_updated" - HOOK_ISSUE_LABEL_CLEARED HookIssueAction = "label_cleared" - HOOK_ISSUE_MILESTONED HookIssueAction = "milestoned" - HOOK_ISSUE_DEMILESTONED HookIssueAction = "demilestoned" - HOOK_ISSUE_SYNCHRONIZED HookIssueAction = "synchronized" -) - -type ChangesFromPayload struct { - From string `json:"from"` -} - -type ChangesPayload struct { - Title *ChangesFromPayload `json:"title,omitempty"` - Body *ChangesFromPayload `json:"body,omitempty"` -} - -// IssuesPayload represents a payload information of issues event. -type IssuesPayload struct { - Action HookIssueAction `json:"action"` - Index int64 `json:"number"` - Issue *Issue `json:"issue"` - Changes *ChangesPayload `json:"changes,omitempty"` - Repository *Repository `json:"repository"` - Sender *User `json:"sender"` -} - -func (p *IssuesPayload) JSONPayload() ([]byte, error) { - return json.MarshalIndent(p, "", " ") -} - -type HookIssueCommentAction string - -const ( - HOOK_ISSUE_COMMENT_CREATED HookIssueCommentAction = "created" - HOOK_ISSUE_COMMENT_EDITED HookIssueCommentAction = "edited" - HOOK_ISSUE_COMMENT_DELETED HookIssueCommentAction = "deleted" -) - -// IssueCommentPayload represents a payload information of issue comment event. -type IssueCommentPayload struct { - Action HookIssueCommentAction `json:"action"` - Issue *Issue `json:"issue"` - Comment *Comment `json:"comment"` - Changes *ChangesPayload `json:"changes,omitempty"` - Repository *Repository `json:"repository"` - Sender *User `json:"sender"` -} - -func (p *IssueCommentPayload) JSONPayload() ([]byte, error) { - return json.MarshalIndent(p, "", " ") -} - -// __________ .__ .__ __________ __ -// \______ \__ __| | | | \______ \ ____ ________ __ ____ _______/ |_ -// | ___/ | \ | | | | _// __ \/ ____/ | \_/ __ \ / ___/\ __\ -// | | | | / |_| |__ | | \ ___< <_| | | /\ ___/ \___ \ | | -// |____| |____/|____/____/ |____|_ /\___ >__ |____/ \___ >____ > |__| -// \/ \/ |__| \/ \/ - -// PullRequestPayload represents a payload information of pull request event. -type PullRequestPayload struct { - Action HookIssueAction `json:"action"` - Index int64 `json:"number"` - PullRequest *PullRequest `json:"pull_request"` - Changes *ChangesPayload `json:"changes,omitempty"` - Repository *Repository `json:"repository"` - Sender *User `json:"sender"` -} - -func (p *PullRequestPayload) JSONPayload() ([]byte, error) { - return json.MarshalIndent(p, "", " ") -} - -// __________ .__ -// \______ \ ____ | | ____ _____ ______ ____ -// | _// __ \| | _/ __ \\__ \ / ___// __ \ -// | | \ ___/| |_\ ___/ / __ \_\___ \\ ___/ -// |____|_ /\___ >____/\___ >____ /____ >\___ > -// \/ \/ \/ \/ \/ \/ - -type HookReleaseAction string - -const ( - HOOK_RELEASE_PUBLISHED HookReleaseAction = "published" -) - -// ReleasePayload represents a payload information of release event. -type ReleasePayload struct { - Action HookReleaseAction `json:"action"` - Release *Release `json:"release"` - Repository *Repository `json:"repository"` - Sender *User `json:"sender"` -} - -func (p *ReleasePayload) JSONPayload() ([]byte, error) { - return json.MarshalIndent(p, "", " ") -} diff --git a/vendor/github.com/gogits/go-gogs-client/repo_key.go b/vendor/github.com/gogits/go-gogs-client/repo_key.go deleted file mode 100644 index 2201602c..00000000 --- a/vendor/github.com/gogits/go-gogs-client/repo_key.go +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2015 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package gogs - -import ( - "bytes" - "encoding/json" - "fmt" - "time" -) - -type DeployKey struct { - ID int64 `json:"id"` - Key string `json:"key"` - URL string `json:"url"` - Title string `json:"title"` - Created time.Time `json:"created_at"` - ReadOnly bool `json:"read_only"` -} - -func (c *Client) ListDeployKeys(user, repo string) ([]*DeployKey, error) { - keys := make([]*DeployKey, 0, 10) - return keys, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/keys", user, repo), nil, nil, &keys) -} - -func (c *Client) GetDeployKey(user, repo string, keyID int64) (*DeployKey, error) { - key := new(DeployKey) - return key, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/keys/%d", user, repo, keyID), nil, nil, &key) -} - -type CreateKeyOption struct { - Title string `json:"title" binding:"Required"` - Key string `json:"key" binding:"Required"` -} - -func (c *Client) CreateDeployKey(user, repo string, opt CreateKeyOption) (*DeployKey, error) { - body, err := json.Marshal(&opt) - if err != nil { - return nil, err - } - key := new(DeployKey) - return key, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/keys", user, repo), jsonHeader, bytes.NewReader(body), key) -} - -func (c *Client) DeleteDeployKey(owner, repo string, keyID int64) error { - _, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/keys/%d", owner, repo, keyID), nil, nil) - return err -} diff --git a/vendor/github.com/gogits/go-gogs-client/user.go b/vendor/github.com/gogits/go-gogs-client/user.go deleted file mode 100644 index 3879b1a6..00000000 --- a/vendor/github.com/gogits/go-gogs-client/user.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2014 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package gogs - -import ( - "encoding/json" - "fmt" -) - -// User represents a API user. -type User struct { - ID int64 `json:"id"` - UserName string `json:"login"` - FullName string `json:"full_name"` - Email string `json:"email"` - AvatarUrl string `json:"avatar_url"` -} - -// MarshalJSON implements the json.Marshaler interface for User -func (u User) MarshalJSON() ([]byte, error) { - // Re-declaring User to avoid recursion - type shadow User - return json.Marshal(struct { - shadow - // LEGACY [Gogs 1.0]: remove field(s) for backward compatibility - CompatUserName string `json:"username"` - }{shadow(u), u.UserName}) -} - -func (c *Client) GetUserInfo(user string) (*User, error) { - u := new(User) - err := c.getParsedResponse("GET", fmt.Sprintf("/users/%s", user), nil, nil, u) - return u, err -} diff --git a/vendor/github.com/gogits/go-gogs-client/user_app.go b/vendor/github.com/gogits/go-gogs-client/user_app.go deleted file mode 100644 index 965ed6eb..00000000 --- a/vendor/github.com/gogits/go-gogs-client/user_app.go +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2014 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package gogs - -import ( - "bytes" - "encoding/base64" - "encoding/json" - "fmt" - "net/http" -) - -func BasicAuthEncode(user, pass string) string { - return base64.StdEncoding.EncodeToString([]byte(user + ":" + pass)) -} - -// AccessToken represents a API access token. -type AccessToken struct { - Name string `json:"name"` - Sha1 string `json:"sha1"` -} - -func (c *Client) ListAccessTokens(user, pass string) ([]*AccessToken, error) { - tokens := make([]*AccessToken, 0, 10) - return tokens, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/tokens", user), - http.Header{"Authorization": []string{"Basic " + BasicAuthEncode(user, pass)}}, nil, &tokens) -} - -type CreateAccessTokenOption struct { - Name string `json:"name" binding:"Required"` -} - -func (c *Client) CreateAccessToken(user, pass string, opt CreateAccessTokenOption) (*AccessToken, error) { - body, err := json.Marshal(&opt) - if err != nil { - return nil, err - } - t := new(AccessToken) - return t, c.getParsedResponse("POST", fmt.Sprintf("/users/%s/tokens", user), - http.Header{ - "content-type": []string{"application/json"}, - "Authorization": []string{"Basic " + BasicAuthEncode(user, pass)}}, - bytes.NewReader(body), t) -} diff --git a/vendor/github.com/gogits/go-gogs-client/user_email.go b/vendor/github.com/gogits/go-gogs-client/user_email.go deleted file mode 100644 index 02dd4023..00000000 --- a/vendor/github.com/gogits/go-gogs-client/user_email.go +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2015 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package gogs - -import ( - "bytes" - "encoding/json" -) - -type Email struct { - Email string `json:"email"` - Verified bool `json:"verified"` - Primary bool `json:"primary"` -} - -func (c *Client) ListEmails() ([]*Email, error) { - emails := make([]*Email, 0, 3) - return emails, c.getParsedResponse("GET", "/user/emails", nil, nil, &emails) -} - -type CreateEmailOption struct { - Emails []string `json:"emails"` -} - -func (c *Client) AddEmail(opt CreateEmailOption) ([]*Email, error) { - body, err := json.Marshal(&opt) - if err != nil { - return nil, err - } - emails := make([]*Email, 0, 3) - return emails, c.getParsedResponse("POST", "/user/emails", jsonHeader, bytes.NewReader(body), emails) -} - -func (c *Client) DeleteEmail(opt CreateEmailOption) error { - body, err := json.Marshal(&opt) - if err != nil { - return err - } - _, err = c.getResponse("DELETE", "/user/emails", jsonHeader, bytes.NewReader(body)) - return err -} diff --git a/vendor/github.com/gogits/go-gogs-client/user_follow.go b/vendor/github.com/gogits/go-gogs-client/user_follow.go deleted file mode 100644 index 36cc65d4..00000000 --- a/vendor/github.com/gogits/go-gogs-client/user_follow.go +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2015 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package gogs - -import "fmt" - -func (c *Client) ListMyFollowers(page int) ([]*User, error) { - users := make([]*User, 0, 10) - return users, c.getParsedResponse("GET", fmt.Sprintf("/user/followers?page=%d", page), nil, nil, &users) -} - -func (c *Client) ListFollowers(user string, page int) ([]*User, error) { - users := make([]*User, 0, 10) - return users, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/followers?page=%d", user, page), nil, nil, &users) -} - -func (c *Client) ListMyFollowing(page int) ([]*User, error) { - users := make([]*User, 0, 10) - return users, c.getParsedResponse("GET", fmt.Sprintf("/user/following?page=%d", page), nil, nil, &users) -} - -func (c *Client) ListFollowing(user string, page int) ([]*User, error) { - users := make([]*User, 0, 10) - return users, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/following?page=%d", user, page), nil, nil, &users) -} - -func (c *Client) IsFollowing(target string) bool { - _, err := c.getResponse("GET", fmt.Sprintf("/user/following/%s", target), nil, nil) - return err == nil -} - -func (c *Client) IsUserFollowing(user, target string) bool { - _, err := c.getResponse("GET", fmt.Sprintf("/users/%s/following/%s", user, target), nil, nil) - return err == nil -} - -func (c *Client) Follow(target string) error { - _, err := c.getResponse("PUT", fmt.Sprintf("/user/following/%s", target), nil, nil) - return err -} - -func (c *Client) Unfollow(target string) error { - _, err := c.getResponse("DELETE", fmt.Sprintf("/user/following/%s", target), nil, nil) - return err -} diff --git a/vendor/github.com/gogits/go-gogs-client/user_key.go b/vendor/github.com/gogits/go-gogs-client/user_key.go deleted file mode 100644 index c0278e0e..00000000 --- a/vendor/github.com/gogits/go-gogs-client/user_key.go +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2015 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package gogs - -import ( - "bytes" - "encoding/json" - "fmt" - "time" -) - -type PublicKey struct { - ID int64 `json:"id"` - Key string `json:"key"` - URL string `json:"url,omitempty"` - Title string `json:"title,omitempty"` - Created time.Time `json:"created_at,omitempty"` -} - -func (c *Client) ListPublicKeys(user string) ([]*PublicKey, error) { - keys := make([]*PublicKey, 0, 10) - return keys, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/keys", user), nil, nil, &keys) -} - -func (c *Client) ListMyPublicKeys() ([]*PublicKey, error) { - keys := make([]*PublicKey, 0, 10) - return keys, c.getParsedResponse("GET", "/user/keys", nil, nil, &keys) -} - -func (c *Client) GetPublicKey(keyID int64) (*PublicKey, error) { - key := new(PublicKey) - return key, c.getParsedResponse("GET", fmt.Sprintf("/user/keys/%d", keyID), nil, nil, &key) -} - -func (c *Client) CreatePublicKey(opt CreateKeyOption) (*PublicKey, error) { - body, err := json.Marshal(&opt) - if err != nil { - return nil, err - } - key := new(PublicKey) - return key, c.getParsedResponse("POST", "/user/keys", jsonHeader, bytes.NewReader(body), key) -} - -func (c *Client) DeletePublicKey(keyID int64) error { - _, err := c.getResponse("DELETE", fmt.Sprintf("/user/keys/%d", keyID), nil, nil) - return err -} diff --git a/vendor/github.com/gogits/go-gogs-client/utils.go b/vendor/github.com/gogits/go-gogs-client/utils.go deleted file mode 100644 index a4d673e0..00000000 --- a/vendor/github.com/gogits/go-gogs-client/utils.go +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2015 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package gogs - -import ( - "net/http" -) - -var jsonHeader = http.Header{"content-type": []string{"application/json"}} - -func Bool(v bool) *bool { - return &v -} - -func String(v string) *string { - return &v -} - -func Int64(v int64) *int64 { - return &v -} diff --git a/vendor/github.com/gogits/go-libravatar/LICENSE b/vendor/github.com/gogits/go-libravatar/LICENSE deleted file mode 100644 index 8c89d4e3..00000000 --- a/vendor/github.com/gogits/go-libravatar/LICENSE +++ /dev/null @@ -1,19 +0,0 @@ -Copyright (c) 2016 Sandro Santilli - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/vendor/github.com/gogits/go-libravatar/Makefile b/vendor/github.com/gogits/go-libravatar/Makefile deleted file mode 100644 index 2a70ddc7..00000000 --- a/vendor/github.com/gogits/go-libravatar/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -PACKAGES ?= $(shell go list ./...) - -.PHONY: check -check: lint - go test - -.PHONY: lint -lint: - @which golint > /dev/null; if [ $$? -ne 0 ]; then \ - go get -u github.com/golang/lint/golint; \ - fi - @for PKG in $(PACKAGES); do golint -set_exit_status $$PKG || exit 1; done; diff --git a/vendor/github.com/gogits/go-libravatar/README.md b/vendor/github.com/gogits/go-libravatar/README.md deleted file mode 100644 index c9d72c43..00000000 --- a/vendor/github.com/gogits/go-libravatar/README.md +++ /dev/null @@ -1,28 +0,0 @@ -Simple [golang](https://www.golang.org) library for serving -[federated avatars](https://www.libravatar.org) - -[![trunk](https://goreportcard.com/badge/strk.kbt.io/projects/go/libravatar)] -(https://goreportcard.com/report/strk.kbt.io/projects/go/libravatar) - -# Use - -```sh -go get strk.kbt.io/projects/go/libravatar -cd $GOPATH/src/strk.kbt.io/projects/go/libravatar -go doc -``` - -# Contribute - -A clone of the code repository would be downloaded by `go get`. -You can send patches or pull requests to strk@kbt.io. - -If you need a place to publish your contribution branches, -you could start from a fork of the gitlab mirror: -https://gitlab.com/strk/go-libravatar - -# Contacts - - * Project homepage: http://strk.kbt.io/projects/go/libravatar - * Maintainer: Sandro Santilli - diff --git a/vendor/github.com/gogits/go-libravatar/libravatar.go b/vendor/github.com/gogits/go-libravatar/libravatar.go deleted file mode 100644 index 5088d02c..00000000 --- a/vendor/github.com/gogits/go-libravatar/libravatar.go +++ /dev/null @@ -1,300 +0,0 @@ -// Copyright 2016 by Sandro Santilli -// Use of this source code is governed by a MIT -// license that can be found in the LICENSE file. - -// Implements support for federated avatars lookup. -// See https://wiki.libravatar.org/api/ - -package libravatar - -import ( - "crypto/md5" - "crypto/sha256" - "fmt" - "math/rand" - "net" - "net/mail" - "net/url" - "strings" - "time" -) - -// Default images (to be used as defaultURL) -const ( - // Do not load any image if none is associated with the email - // hash, instead return an HTTP 404 (File Not Found) response - HTTP404 = "404" - // (mystery-man) a simple, cartoon-style silhouetted outline of - // a person (does not vary by email hash) - MysteryMan = "mm" - // a geometric pattern based on an email hash - IdentIcon = "identicon" - // a generated 'monster' with different colors, faces, etc - MonsterID = "monsterid" - // generated faces with differing features and backgrounds - Wavatar = "wavatar" - // awesome generated, 8-bit arcade-style pixelated faces - Retro = "retro" -) - -var ( - // DefaultLibravatar is a default Libravatar object, - // enabling object-less function calls - DefaultLibravatar = New() -) - -/* This should be moved in its own file */ -type cacheKey struct { - service string - domain string -} - -type cacheValue struct { - target string - checkedAt time.Time -} - -// Libravatar is an opaque structure holding service configuration -type Libravatar struct { - defURL string // default url - picSize int // picture size - fallbackHost string // default fallback URL - secureFallbackHost string // default fallback URL for secure connections - useHTTPS bool - nameCache map[cacheKey]cacheValue - nameCacheDuration time.Duration - minSize uint // smallest image dimension allowed - maxSize uint // largest image dimension allowed - size uint // what dimension should be used - serviceBase string // SRV record to be queried for federation - secureServiceBase string // SRV record to be queried for federation with secure servers -} - -// New instanciates a new Libravatar object (handle) -func New() *Libravatar { - // According to https://wiki.libravatar.org/running_your_own/ - // the time-to-live (cache expiry) should be set to at least 1 day. - return &Libravatar{ - fallbackHost: `cdn.libravatar.org`, - secureFallbackHost: `seccdn.libravatar.org`, - minSize: 1, - maxSize: 512, - size: 0, // unset, defaults to 80 - serviceBase: `avatars`, - secureServiceBase: `avatars-sec`, - nameCache: make(map[cacheKey]cacheValue), - nameCacheDuration: 24 * time.Hour, - } -} - -// SetFallbackHost sets the hostname for fallbacks in case no avatar -// service is defined for a domain -func (v *Libravatar) SetFallbackHost(host string) { - v.fallbackHost = host -} - -// SetSecureFallbackHost sets the hostname for fallbacks in case no -// avatar service is defined for a domain, when requiring secure domains -func (v *Libravatar) SetSecureFallbackHost(host string) { - v.secureFallbackHost = host -} - -// SetUseHTTPS sets flag requesting use of https for fetching avatars -func (v *Libravatar) SetUseHTTPS(use bool) { - v.useHTTPS = use -} - -// SetAvatarSize sets avatars image dimension (0 for default) -func (v *Libravatar) SetAvatarSize(size uint) { - v.size = size -} - -// generate hash, either with email address or OpenID -func (v *Libravatar) genHash(email *mail.Address, openid *url.URL) string { - if email != nil { - email.Address = strings.ToLower(strings.TrimSpace(email.Address)) - sum := md5.Sum([]byte(email.Address)) - return fmt.Sprintf("%x", sum) - } else if openid != nil { - openid.Scheme = strings.ToLower(openid.Scheme) - openid.Host = strings.ToLower(openid.Host) - sum := sha256.Sum256([]byte(openid.String())) - return fmt.Sprintf("%x", sum) - } - // panic, because this should not be reachable - panic("Neither Email or OpenID set") -} - -// Gets domain out of email or openid (for openid to be parsed, email has to be nil) -func (v *Libravatar) getDomain(email *mail.Address, openid *url.URL) string { - if email != nil { - u, err := url.Parse("//" + email.Address) - if err != nil { - if v.useHTTPS && v.secureFallbackHost != "" { - return v.secureFallbackHost - } - return v.fallbackHost - } - return u.Host - } else if openid != nil { - return openid.Host - } - // panic, because this should not be reachable - panic("Neither Email or OpenID set") -} - -// Processes email or openid (for openid to be processed, email has to be nil) -func (v *Libravatar) process(email *mail.Address, openid *url.URL) (string, error) { - URL, err := v.baseURL(email, openid) - if err != nil { - return "", err - } - res := fmt.Sprintf("%s/avatar/%s", URL, v.genHash(email, openid)) - - values := make(url.Values) - if v.defURL != "" { - values.Add("d", v.defURL) - } - if v.size > 0 { - values.Add("s", fmt.Sprintf("%d", v.size)) - } - - if len(values) > 0 { - return fmt.Sprintf("%s?%s", res, values.Encode()), nil - } - return res, nil -} - -// Finds or defaults a URL for Federation (for openid to be used, email has to be nil) -func (v *Libravatar) baseURL(email *mail.Address, openid *url.URL) (string, error) { - var service, protocol, domain string - - if v.useHTTPS { - protocol = "https://" - service = v.secureServiceBase - domain = v.secureFallbackHost - - } else { - protocol = "http://" - service = v.serviceBase - domain = v.fallbackHost - } - - host := v.getDomain(email, openid) - key := cacheKey{service, host} - now := time.Now() - val, found := v.nameCache[key] - if found && now.Sub(val.checkedAt) <= v.nameCacheDuration { - return protocol + val.target, nil - } - - _, addrs, err := net.LookupSRV(service, "tcp", host) - if err != nil && err.(*net.DNSError).IsTimeout { - return "", err - } - - if len(addrs) == 1 { - // select only record, if only one is available - domain = strings.TrimSuffix(addrs[0].Target, ".") - } else if len(addrs) > 1 { - // Select first record according to RFC2782 weight - // ordering algorithm (page 3) - - type record struct { - srv *net.SRV - weight uint16 - } - - var ( - totalWeight uint16 - records []record - topPriority = addrs[0].Priority - topRecord *net.SRV - ) - - for _, rr := range addrs { - if rr.Priority > topPriority { - continue - } else if rr.Priority < topPriority { - // won't happen, because net sorts - // by priority, but just in case - totalWeight = 0 - records = nil - topPriority = rr.Priority - } - - totalWeight += rr.Weight - - if rr.Weight > 0 { - records = append(records, record{rr, totalWeight}) - } else if rr.Weight == 0 { - records = append([]record{record{srv: rr, weight: totalWeight}}, records...) - } - } - - if len(records) == 1 { - topRecord = records[0].srv - } else { - randnum := uint16(rand.Intn(int(totalWeight))) - - for _, rr := range records { - if rr.weight >= randnum { - topRecord = rr.srv - break - } - } - } - - domain = fmt.Sprintf("%s:%d", topRecord.Target, topRecord.Port) - } - - v.nameCache[key] = cacheValue{checkedAt: now, target: domain} - return protocol + domain, nil -} - -// FromEmail returns the url of the avatar for the given email -func (v *Libravatar) FromEmail(email string) (string, error) { - addr, err := mail.ParseAddress(email) - if err != nil { - return "", err - } - - link, err := v.process(addr, nil) - if err != nil { - return "", err - } - - return link, nil -} - -// FromEmail is the object-less call to DefaultLibravatar for an email adders -func FromEmail(email string) (string, error) { - return DefaultLibravatar.FromEmail(email) -} - -// FromURL returns the url of the avatar for the given url (typically -// for OpenID) -func (v *Libravatar) FromURL(openid string) (string, error) { - ourl, err := url.Parse(openid) - if err != nil { - return "", err - } - - if !ourl.IsAbs() { - return "", fmt.Errorf("Is not an absolute URL") - } else if ourl.Scheme != "http" && ourl.Scheme != "https" { - return "", fmt.Errorf("Invalid protocol: %s", ourl.Scheme) - } - - link, err := v.process(nil, ourl) - if err != nil { - return "", err - } - - return link, nil -} - -// FromURL is the object-less call to DefaultLibravatar for a URL -func FromURL(openid string) (string, error) { - return DefaultLibravatar.FromURL(openid) -} diff --git a/vendor/github.com/gogits/minwinsvc/LICENSE b/vendor/github.com/gogits/minwinsvc/LICENSE deleted file mode 100644 index fce91b4e..00000000 --- a/vendor/github.com/gogits/minwinsvc/LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -Copyright (c) 2015 Daniel Theophanes - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any damages -arising from the use of this software. - -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it -freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - - 3. This notice may not be removed or altered from any source - distribution. diff --git a/vendor/github.com/gogits/minwinsvc/README.md b/vendor/github.com/gogits/minwinsvc/README.md deleted file mode 100644 index 260dceea..00000000 --- a/vendor/github.com/gogits/minwinsvc/README.md +++ /dev/null @@ -1,18 +0,0 @@ -### Minimal windows service stub - -Programs designed to run from most *nix style operating systems -can import this package to enable running programs as services without modifying -them. - -``` -import _ "github.com/kardianos/minwinsvc" -``` - -If you need more control over the exit behavior, set -``` -minwinsvc.SetOnExit(func() { - // Do something. - // Within 10 seconds call: - os.Exit(0) -}) -``` diff --git a/vendor/github.com/gogits/minwinsvc/minwinsvc.go b/vendor/github.com/gogits/minwinsvc/minwinsvc.go deleted file mode 100644 index 057ba7f9..00000000 --- a/vendor/github.com/gogits/minwinsvc/minwinsvc.go +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2015 Daniel Theophanes. -// Use of this source code is governed by a zlib-style -// license that can be found in the LICENSE file.package service - -// Minimal non-invasive windows only service stub. -// -// Import to allow running as a windows service. -// import _ "github.com/kardianos/minwinsvc" -// This will detect if running as a windows service -// and install required callbacks for windows. -package minwinsvc - -// SetOnExit sets the function to be called when the windows service -// requests an exit. If this is not called, or if it is called where -// f == nil, then it defaults to calling "os.Exit(0)". -func SetOnExit(f func()) { - setOnExit(f) -} diff --git a/vendor/github.com/gogits/minwinsvc/svc_other.go b/vendor/github.com/gogits/minwinsvc/svc_other.go deleted file mode 100644 index 197d3002..00000000 --- a/vendor/github.com/gogits/minwinsvc/svc_other.go +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright 2015 Daniel Theophanes. -// Use of this source code is governed by a zlib-style -// license that can be found in the LICENSE file.package service - -//+build !windows - -package minwinsvc - -func setOnExit(f func()) { - // Nothing. -} diff --git a/vendor/github.com/gogits/minwinsvc/svc_windows.go b/vendor/github.com/gogits/minwinsvc/svc_windows.go deleted file mode 100644 index e79755fa..00000000 --- a/vendor/github.com/gogits/minwinsvc/svc_windows.go +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright 2015 Daniel Theophanes. -// Use of this source code is governed by a zlib-style -// license that can be found in the LICENSE file.package service - -//+build windows - -package minwinsvc - -import ( - "os" - "sync" - - "golang.org/x/sys/windows/svc" -) - -var ( - onExit func() - guard sync.Mutex -) - -func init() { - interactive, err := svc.IsAnInteractiveSession() - if err != nil { - panic(err) - } - // While run as Windows service, it is not an interactive session, - // but we don't want hook execute to be treated as service, e.g. gogs.exe hook pre-receive. - if interactive || len(os.Getenv("SSH_ORIGINAL_COMMAND")) > 0 { - return - } - go func() { - _ = svc.Run("", runner{}) - - guard.Lock() - f := onExit - guard.Unlock() - - // Don't hold this lock in user code. - if f != nil { - f() - } - // Make sure we exit. - os.Exit(0) - }() -} - -func setOnExit(f func()) { - guard.Lock() - onExit = f - guard.Unlock() -} - -type runner struct{} - -func (runner) Execute(args []string, r <-chan svc.ChangeRequest, changes chan<- svc.Status) (bool, uint32) { - const cmdsAccepted = svc.AcceptStop | svc.AcceptShutdown - changes <- svc.Status{State: svc.StartPending} - - changes <- svc.Status{State: svc.Running, Accepts: cmdsAccepted} - for { - c := <-r - switch c.Cmd { - case svc.Interrogate: - changes <- c.CurrentStatus - case svc.Stop, svc.Shutdown: - changes <- svc.Status{State: svc.StopPending} - return false, 0 - } - } - - return false, 0 -} diff --git a/vendor/github.com/gogs/chardet/2022.go b/vendor/github.com/gogs/chardet/2022.go new file mode 100644 index 00000000..e667225e --- /dev/null +++ b/vendor/github.com/gogs/chardet/2022.go @@ -0,0 +1,102 @@ +package chardet + +import ( + "bytes" +) + +type recognizer2022 struct { + charset string + escapes [][]byte +} + +func (r *recognizer2022) Match(input *recognizerInput) (output recognizerOutput) { + return recognizerOutput{ + Charset: r.charset, + Confidence: r.matchConfidence(input.input), + } +} + +func (r *recognizer2022) matchConfidence(input []byte) int { + var hits, misses, shifts int +input: + for i := 0; i < len(input); i++ { + c := input[i] + if c == 0x1B { + for _, esc := range r.escapes { + if bytes.HasPrefix(input[i+1:], esc) { + hits++ + i += len(esc) + continue input + } + } + misses++ + } else if c == 0x0E || c == 0x0F { + shifts++ + } + } + if hits == 0 { + return 0 + } + quality := (100*hits - 100*misses) / (hits + misses) + if hits+shifts < 5 { + quality -= (5 - (hits + shifts)) * 10 + } + if quality < 0 { + quality = 0 + } + return quality +} + +var escapeSequences_2022JP = [][]byte{ + {0x24, 0x28, 0x43}, // KS X 1001:1992 + {0x24, 0x28, 0x44}, // JIS X 212-1990 + {0x24, 0x40}, // JIS C 6226-1978 + {0x24, 0x41}, // GB 2312-80 + {0x24, 0x42}, // JIS X 208-1983 + {0x26, 0x40}, // JIS X 208 1990, 1997 + {0x28, 0x42}, // ASCII + {0x28, 0x48}, // JIS-Roman + {0x28, 0x49}, // Half-width katakana + {0x28, 0x4a}, // JIS-Roman + {0x2e, 0x41}, // ISO 8859-1 + {0x2e, 0x46}, // ISO 8859-7 +} + +var escapeSequences_2022KR = [][]byte{ + {0x24, 0x29, 0x43}, +} + +var escapeSequences_2022CN = [][]byte{ + {0x24, 0x29, 0x41}, // GB 2312-80 + {0x24, 0x29, 0x47}, // CNS 11643-1992 Plane 1 + {0x24, 0x2A, 0x48}, // CNS 11643-1992 Plane 2 + {0x24, 0x29, 0x45}, // ISO-IR-165 + {0x24, 0x2B, 0x49}, // CNS 11643-1992 Plane 3 + {0x24, 0x2B, 0x4A}, // CNS 11643-1992 Plane 4 + {0x24, 0x2B, 0x4B}, // CNS 11643-1992 Plane 5 + {0x24, 0x2B, 0x4C}, // CNS 11643-1992 Plane 6 + {0x24, 0x2B, 0x4D}, // CNS 11643-1992 Plane 7 + {0x4e}, // SS2 + {0x4f}, // SS3 +} + +func newRecognizer_2022JP() *recognizer2022 { + return &recognizer2022{ + "ISO-2022-JP", + escapeSequences_2022JP, + } +} + +func newRecognizer_2022KR() *recognizer2022 { + return &recognizer2022{ + "ISO-2022-KR", + escapeSequences_2022KR, + } +} + +func newRecognizer_2022CN() *recognizer2022 { + return &recognizer2022{ + "ISO-2022-CN", + escapeSequences_2022CN, + } +} diff --git a/vendor/github.com/gogs/chardet/AUTHORS b/vendor/github.com/gogs/chardet/AUTHORS new file mode 100644 index 00000000..842d0216 --- /dev/null +++ b/vendor/github.com/gogs/chardet/AUTHORS @@ -0,0 +1 @@ +Sheng Yu (yusheng dot sjtu at gmail dot com) diff --git a/vendor/github.com/gogs/chardet/LICENSE b/vendor/github.com/gogs/chardet/LICENSE new file mode 100644 index 00000000..35ee796b --- /dev/null +++ b/vendor/github.com/gogs/chardet/LICENSE @@ -0,0 +1,22 @@ +Copyright (c) 2012 chardet Authors + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +Partial of the Software is derived from ICU project. See icu-license.html for +license of the derivative portions. diff --git a/vendor/github.com/gogs/chardet/README.md b/vendor/github.com/gogs/chardet/README.md new file mode 100644 index 00000000..bbde23fb --- /dev/null +++ b/vendor/github.com/gogs/chardet/README.md @@ -0,0 +1,12 @@ +# chardet + +chardet is library to automatically detect +[charset](http://en.wikipedia.org/wiki/Character_encoding) of texts for [Go +programming language](http://golang.org/). It's based on the algorithm and data +in [ICU](http://icu-project.org/)'s implementation. + +The project was created by [saintfish](http://github.com/saintfish/chardet). In January 2015 it was forked by the gogits project in order to incorporate bugfixes and new features. + +## Documentation and Usage + +See [pkgdoc](http://godoc.org/github.com/gogits/chardet) diff --git a/vendor/github.com/gogs/chardet/detector.go b/vendor/github.com/gogs/chardet/detector.go new file mode 100644 index 00000000..e11c222e --- /dev/null +++ b/vendor/github.com/gogs/chardet/detector.go @@ -0,0 +1,136 @@ +// Package chardet ports character set detection from ICU. +package chardet + +import ( + "errors" + "sort" +) + +// Result contains all the information that charset detector gives. +type Result struct { + // IANA name of the detected charset. + Charset string + // IANA name of the detected language. It may be empty for some charsets. + Language string + // Confidence of the Result. Scale from 1 to 100. The bigger, the more confident. + Confidence int +} + +// Detector implements charset detection. +type Detector struct { + recognizers []recognizer + stripTag bool +} + +// List of charset recognizers +var recognizers = []recognizer{ + newRecognizer_utf8(), + newRecognizer_utf16be(), + newRecognizer_utf16le(), + newRecognizer_utf32be(), + newRecognizer_utf32le(), + newRecognizer_8859_1_en(), + newRecognizer_8859_1_da(), + newRecognizer_8859_1_de(), + newRecognizer_8859_1_es(), + newRecognizer_8859_1_fr(), + newRecognizer_8859_1_it(), + newRecognizer_8859_1_nl(), + newRecognizer_8859_1_no(), + newRecognizer_8859_1_pt(), + newRecognizer_8859_1_sv(), + newRecognizer_8859_2_cs(), + newRecognizer_8859_2_hu(), + newRecognizer_8859_2_pl(), + newRecognizer_8859_2_ro(), + newRecognizer_8859_5_ru(), + newRecognizer_8859_6_ar(), + newRecognizer_8859_7_el(), + newRecognizer_8859_8_I_he(), + newRecognizer_8859_8_he(), + newRecognizer_windows_1251(), + newRecognizer_windows_1256(), + newRecognizer_KOI8_R(), + newRecognizer_8859_9_tr(), + + newRecognizer_sjis(), + newRecognizer_gb_18030(), + newRecognizer_euc_jp(), + newRecognizer_euc_kr(), + newRecognizer_big5(), + + newRecognizer_2022JP(), + newRecognizer_2022KR(), + newRecognizer_2022CN(), + + newRecognizer_IBM424_he_rtl(), + newRecognizer_IBM424_he_ltr(), + newRecognizer_IBM420_ar_rtl(), + newRecognizer_IBM420_ar_ltr(), +} + +// NewTextDetector creates a Detector for plain text. +func NewTextDetector() *Detector { + return &Detector{recognizers, false} +} + +// NewHtmlDetector creates a Detector for Html. +func NewHtmlDetector() *Detector { + return &Detector{recognizers, true} +} + +var ( + NotDetectedError = errors.New("Charset not detected.") +) + +// DetectBest returns the Result with highest Confidence. +func (d *Detector) DetectBest(b []byte) (r *Result, err error) { + var all []Result + if all, err = d.DetectAll(b); err == nil { + r = &all[0] + } + return +} + +// DetectAll returns all Results which have non-zero Confidence. The Results are sorted by Confidence in descending order. +func (d *Detector) DetectAll(b []byte) ([]Result, error) { + input := newRecognizerInput(b, d.stripTag) + outputChan := make(chan recognizerOutput) + for _, r := range d.recognizers { + go matchHelper(r, input, outputChan) + } + outputs := make([]recognizerOutput, 0, len(d.recognizers)) + for i := 0; i < len(d.recognizers); i++ { + o := <-outputChan + if o.Confidence > 0 { + outputs = append(outputs, o) + } + } + if len(outputs) == 0 { + return nil, NotDetectedError + } + + sort.Sort(recognizerOutputs(outputs)) + dedupOutputs := make([]Result, 0, len(outputs)) + foundCharsets := make(map[string]struct{}, len(outputs)) + for _, o := range outputs { + if _, found := foundCharsets[o.Charset]; !found { + dedupOutputs = append(dedupOutputs, Result(o)) + foundCharsets[o.Charset] = struct{}{} + } + } + if len(dedupOutputs) == 0 { + return nil, NotDetectedError + } + return dedupOutputs, nil +} + +func matchHelper(r recognizer, input *recognizerInput, outputChan chan<- recognizerOutput) { + outputChan <- r.Match(input) +} + +type recognizerOutputs []recognizerOutput + +func (r recognizerOutputs) Len() int { return len(r) } +func (r recognizerOutputs) Less(i, j int) bool { return r[i].Confidence > r[j].Confidence } +func (r recognizerOutputs) Swap(i, j int) { r[i], r[j] = r[j], r[i] } diff --git a/vendor/github.com/gogs/chardet/icu-license.html b/vendor/github.com/gogs/chardet/icu-license.html new file mode 100644 index 00000000..d078d057 --- /dev/null +++ b/vendor/github.com/gogs/chardet/icu-license.html @@ -0,0 +1,51 @@ + + + + +ICU License - ICU 1.8.1 and later + + + +

ICU License - ICU 1.8.1 and later

+ +

COPYRIGHT AND PERMISSION NOTICE

+ +

+Copyright (c) 1995-2012 International Business Machines Corporation and others +

+

+All rights reserved. +

+

+Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, and/or sell +copies of the Software, and to permit persons +to whom the Software is furnished to do so, provided that the above +copyright notice(s) and this permission notice appear in all copies +of the Software and that both the above copyright notice(s) and this +permission notice appear in supporting documentation. +

+

+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL +THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, +OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER +RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, +NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE +USE OR PERFORMANCE OF THIS SOFTWARE. +

+

+Except as contained in this notice, the name of a copyright holder shall not be +used in advertising or otherwise to promote the sale, use or other dealings in +this Software without prior written authorization of the copyright holder. +

+ +
+

+All trademarks and registered trademarks mentioned herein are the property of their respective owners. +

+ + diff --git a/vendor/github.com/gogs/chardet/multi_byte.go b/vendor/github.com/gogs/chardet/multi_byte.go new file mode 100644 index 00000000..b5cdf3d6 --- /dev/null +++ b/vendor/github.com/gogs/chardet/multi_byte.go @@ -0,0 +1,345 @@ +package chardet + +import ( + "errors" + "math" +) + +type recognizerMultiByte struct { + charset string + language string + decoder charDecoder + commonChars []uint16 +} + +type charDecoder interface { + DecodeOneChar([]byte) (c uint16, remain []byte, err error) +} + +func (r *recognizerMultiByte) Match(input *recognizerInput) (output recognizerOutput) { + return recognizerOutput{ + Charset: r.charset, + Language: r.language, + Confidence: r.matchConfidence(input), + } +} + +func (r *recognizerMultiByte) matchConfidence(input *recognizerInput) int { + raw := input.raw + var c uint16 + var err error + var totalCharCount, badCharCount, singleByteCharCount, doubleByteCharCount, commonCharCount int + for c, raw, err = r.decoder.DecodeOneChar(raw); len(raw) > 0; c, raw, err = r.decoder.DecodeOneChar(raw) { + totalCharCount++ + if err != nil { + badCharCount++ + } else if c <= 0xFF { + singleByteCharCount++ + } else { + doubleByteCharCount++ + if r.commonChars != nil && binarySearch(r.commonChars, c) { + commonCharCount++ + } + } + if badCharCount >= 2 && badCharCount*5 >= doubleByteCharCount { + return 0 + } + } + + if doubleByteCharCount <= 10 && badCharCount == 0 { + if doubleByteCharCount == 0 && totalCharCount < 10 { + return 0 + } else { + return 10 + } + } + + if doubleByteCharCount < 20*badCharCount { + return 0 + } + if r.commonChars == nil { + confidence := 30 + doubleByteCharCount - 20*badCharCount + if confidence > 100 { + confidence = 100 + } + return confidence + } + maxVal := math.Log(float64(doubleByteCharCount) / 4) + scaleFactor := 90 / maxVal + confidence := int(math.Log(float64(commonCharCount)+1)*scaleFactor + 10) + if confidence > 100 { + confidence = 100 + } + if confidence < 0 { + confidence = 0 + } + return confidence +} + +func binarySearch(l []uint16, c uint16) bool { + start := 0 + end := len(l) - 1 + for start <= end { + mid := (start + end) / 2 + if c == l[mid] { + return true + } else if c < l[mid] { + end = mid - 1 + } else { + start = mid + 1 + } + } + return false +} + +var eobError = errors.New("End of input buffer") +var badCharError = errors.New("Decode a bad char") + +type charDecoder_sjis struct { +} + +func (charDecoder_sjis) DecodeOneChar(input []byte) (c uint16, remain []byte, err error) { + if len(input) == 0 { + return 0, nil, eobError + } + first := input[0] + c = uint16(first) + remain = input[1:] + if first <= 0x7F || (first > 0xA0 && first <= 0xDF) { + return + } + if len(remain) == 0 { + return c, remain, badCharError + } + second := remain[0] + remain = remain[1:] + c = c<<8 | uint16(second) + if (second >= 0x40 && second <= 0x7F) || (second >= 0x80 && second <= 0xFE) { + } else { + err = badCharError + } + return +} + +var commonChars_sjis = []uint16{ + 0x8140, 0x8141, 0x8142, 0x8145, 0x815b, 0x8169, 0x816a, 0x8175, 0x8176, 0x82a0, + 0x82a2, 0x82a4, 0x82a9, 0x82aa, 0x82ab, 0x82ad, 0x82af, 0x82b1, 0x82b3, 0x82b5, + 0x82b7, 0x82bd, 0x82be, 0x82c1, 0x82c4, 0x82c5, 0x82c6, 0x82c8, 0x82c9, 0x82cc, + 0x82cd, 0x82dc, 0x82e0, 0x82e7, 0x82e8, 0x82e9, 0x82ea, 0x82f0, 0x82f1, 0x8341, + 0x8343, 0x834e, 0x834f, 0x8358, 0x835e, 0x8362, 0x8367, 0x8375, 0x8376, 0x8389, + 0x838a, 0x838b, 0x838d, 0x8393, 0x8e96, 0x93fa, 0x95aa, +} + +func newRecognizer_sjis() *recognizerMultiByte { + return &recognizerMultiByte{ + "Shift_JIS", + "ja", + charDecoder_sjis{}, + commonChars_sjis, + } +} + +type charDecoder_euc struct { +} + +func (charDecoder_euc) DecodeOneChar(input []byte) (c uint16, remain []byte, err error) { + if len(input) == 0 { + return 0, nil, eobError + } + first := input[0] + remain = input[1:] + c = uint16(first) + if first <= 0x8D { + return uint16(first), remain, nil + } + if len(remain) == 0 { + return 0, nil, eobError + } + second := remain[0] + remain = remain[1:] + c = c<<8 | uint16(second) + if first >= 0xA1 && first <= 0xFE { + if second < 0xA1 { + err = badCharError + } + return + } + if first == 0x8E { + if second < 0xA1 { + err = badCharError + } + return + } + if first == 0x8F { + if len(remain) == 0 { + return 0, nil, eobError + } + third := remain[0] + remain = remain[1:] + c = c<<0 | uint16(third) + if third < 0xa1 { + err = badCharError + } + } + return +} + +var commonChars_euc_jp = []uint16{ + 0xa1a1, 0xa1a2, 0xa1a3, 0xa1a6, 0xa1bc, 0xa1ca, 0xa1cb, 0xa1d6, 0xa1d7, 0xa4a2, + 0xa4a4, 0xa4a6, 0xa4a8, 0xa4aa, 0xa4ab, 0xa4ac, 0xa4ad, 0xa4af, 0xa4b1, 0xa4b3, + 0xa4b5, 0xa4b7, 0xa4b9, 0xa4bb, 0xa4bd, 0xa4bf, 0xa4c0, 0xa4c1, 0xa4c3, 0xa4c4, + 0xa4c6, 0xa4c7, 0xa4c8, 0xa4c9, 0xa4ca, 0xa4cb, 0xa4ce, 0xa4cf, 0xa4d0, 0xa4de, + 0xa4df, 0xa4e1, 0xa4e2, 0xa4e4, 0xa4e8, 0xa4e9, 0xa4ea, 0xa4eb, 0xa4ec, 0xa4ef, + 0xa4f2, 0xa4f3, 0xa5a2, 0xa5a3, 0xa5a4, 0xa5a6, 0xa5a7, 0xa5aa, 0xa5ad, 0xa5af, + 0xa5b0, 0xa5b3, 0xa5b5, 0xa5b7, 0xa5b8, 0xa5b9, 0xa5bf, 0xa5c3, 0xa5c6, 0xa5c7, + 0xa5c8, 0xa5c9, 0xa5cb, 0xa5d0, 0xa5d5, 0xa5d6, 0xa5d7, 0xa5de, 0xa5e0, 0xa5e1, + 0xa5e5, 0xa5e9, 0xa5ea, 0xa5eb, 0xa5ec, 0xa5ed, 0xa5f3, 0xb8a9, 0xb9d4, 0xbaee, + 0xbbc8, 0xbef0, 0xbfb7, 0xc4ea, 0xc6fc, 0xc7bd, 0xcab8, 0xcaf3, 0xcbdc, 0xcdd1, +} + +var commonChars_euc_kr = []uint16{ + 0xb0a1, 0xb0b3, 0xb0c5, 0xb0cd, 0xb0d4, 0xb0e6, 0xb0ed, 0xb0f8, 0xb0fa, 0xb0fc, + 0xb1b8, 0xb1b9, 0xb1c7, 0xb1d7, 0xb1e2, 0xb3aa, 0xb3bb, 0xb4c2, 0xb4cf, 0xb4d9, + 0xb4eb, 0xb5a5, 0xb5b5, 0xb5bf, 0xb5c7, 0xb5e9, 0xb6f3, 0xb7af, 0xb7c2, 0xb7ce, + 0xb8a6, 0xb8ae, 0xb8b6, 0xb8b8, 0xb8bb, 0xb8e9, 0xb9ab, 0xb9ae, 0xb9cc, 0xb9ce, + 0xb9fd, 0xbab8, 0xbace, 0xbad0, 0xbaf1, 0xbbe7, 0xbbf3, 0xbbfd, 0xbcad, 0xbcba, + 0xbcd2, 0xbcf6, 0xbdba, 0xbdc0, 0xbdc3, 0xbdc5, 0xbec6, 0xbec8, 0xbedf, 0xbeee, + 0xbef8, 0xbefa, 0xbfa1, 0xbfa9, 0xbfc0, 0xbfe4, 0xbfeb, 0xbfec, 0xbff8, 0xc0a7, + 0xc0af, 0xc0b8, 0xc0ba, 0xc0bb, 0xc0bd, 0xc0c7, 0xc0cc, 0xc0ce, 0xc0cf, 0xc0d6, + 0xc0da, 0xc0e5, 0xc0fb, 0xc0fc, 0xc1a4, 0xc1a6, 0xc1b6, 0xc1d6, 0xc1df, 0xc1f6, + 0xc1f8, 0xc4a1, 0xc5cd, 0xc6ae, 0xc7cf, 0xc7d1, 0xc7d2, 0xc7d8, 0xc7e5, 0xc8ad, +} + +func newRecognizer_euc_jp() *recognizerMultiByte { + return &recognizerMultiByte{ + "EUC-JP", + "ja", + charDecoder_euc{}, + commonChars_euc_jp, + } +} + +func newRecognizer_euc_kr() *recognizerMultiByte { + return &recognizerMultiByte{ + "EUC-KR", + "ko", + charDecoder_euc{}, + commonChars_euc_kr, + } +} + +type charDecoder_big5 struct { +} + +func (charDecoder_big5) DecodeOneChar(input []byte) (c uint16, remain []byte, err error) { + if len(input) == 0 { + return 0, nil, eobError + } + first := input[0] + remain = input[1:] + c = uint16(first) + if first <= 0x7F || first == 0xFF { + return + } + if len(remain) == 0 { + return c, nil, eobError + } + second := remain[0] + remain = remain[1:] + c = c<<8 | uint16(second) + if second < 0x40 || second == 0x7F || second == 0xFF { + err = badCharError + } + return +} + +var commonChars_big5 = []uint16{ + 0xa140, 0xa141, 0xa142, 0xa143, 0xa147, 0xa149, 0xa175, 0xa176, 0xa440, 0xa446, + 0xa447, 0xa448, 0xa451, 0xa454, 0xa457, 0xa464, 0xa46a, 0xa46c, 0xa477, 0xa4a3, + 0xa4a4, 0xa4a7, 0xa4c1, 0xa4ce, 0xa4d1, 0xa4df, 0xa4e8, 0xa4fd, 0xa540, 0xa548, + 0xa558, 0xa569, 0xa5cd, 0xa5e7, 0xa657, 0xa661, 0xa662, 0xa668, 0xa670, 0xa6a8, + 0xa6b3, 0xa6b9, 0xa6d3, 0xa6db, 0xa6e6, 0xa6f2, 0xa740, 0xa751, 0xa759, 0xa7da, + 0xa8a3, 0xa8a5, 0xa8ad, 0xa8d1, 0xa8d3, 0xa8e4, 0xa8fc, 0xa9c0, 0xa9d2, 0xa9f3, + 0xaa6b, 0xaaba, 0xaabe, 0xaacc, 0xaafc, 0xac47, 0xac4f, 0xacb0, 0xacd2, 0xad59, + 0xaec9, 0xafe0, 0xb0ea, 0xb16f, 0xb2b3, 0xb2c4, 0xb36f, 0xb44c, 0xb44e, 0xb54c, + 0xb5a5, 0xb5bd, 0xb5d0, 0xb5d8, 0xb671, 0xb7ed, 0xb867, 0xb944, 0xbad8, 0xbb44, + 0xbba1, 0xbdd1, 0xc2c4, 0xc3b9, 0xc440, 0xc45f, +} + +func newRecognizer_big5() *recognizerMultiByte { + return &recognizerMultiByte{ + "Big5", + "zh", + charDecoder_big5{}, + commonChars_big5, + } +} + +type charDecoder_gb_18030 struct { +} + +func (charDecoder_gb_18030) DecodeOneChar(input []byte) (c uint16, remain []byte, err error) { + if len(input) == 0 { + return 0, nil, eobError + } + first := input[0] + remain = input[1:] + c = uint16(first) + if first <= 0x80 { + return + } + if len(remain) == 0 { + return 0, nil, eobError + } + second := remain[0] + remain = remain[1:] + c = c<<8 | uint16(second) + if first >= 0x81 && first <= 0xFE { + if (second >= 0x40 && second <= 0x7E) || (second >= 0x80 && second <= 0xFE) { + return + } + + if second >= 0x30 && second <= 0x39 { + if len(remain) == 0 { + return 0, nil, eobError + } + third := remain[0] + remain = remain[1:] + if third >= 0x81 && third <= 0xFE { + if len(remain) == 0 { + return 0, nil, eobError + } + fourth := remain[0] + remain = remain[1:] + if fourth >= 0x30 && fourth <= 0x39 { + c = c<<16 | uint16(third)<<8 | uint16(fourth) + return + } + } + } + err = badCharError + } + return +} + +var commonChars_gb_18030 = []uint16{ + 0xa1a1, 0xa1a2, 0xa1a3, 0xa1a4, 0xa1b0, 0xa1b1, 0xa1f1, 0xa1f3, 0xa3a1, 0xa3ac, + 0xa3ba, 0xb1a8, 0xb1b8, 0xb1be, 0xb2bb, 0xb3c9, 0xb3f6, 0xb4f3, 0xb5bd, 0xb5c4, + 0xb5e3, 0xb6af, 0xb6d4, 0xb6e0, 0xb7a2, 0xb7a8, 0xb7bd, 0xb7d6, 0xb7dd, 0xb8b4, + 0xb8df, 0xb8f6, 0xb9ab, 0xb9c9, 0xb9d8, 0xb9fa, 0xb9fd, 0xbacd, 0xbba7, 0xbbd6, + 0xbbe1, 0xbbfa, 0xbcbc, 0xbcdb, 0xbcfe, 0xbdcc, 0xbecd, 0xbedd, 0xbfb4, 0xbfc6, + 0xbfc9, 0xc0b4, 0xc0ed, 0xc1cb, 0xc2db, 0xc3c7, 0xc4dc, 0xc4ea, 0xc5cc, 0xc6f7, + 0xc7f8, 0xc8ab, 0xc8cb, 0xc8d5, 0xc8e7, 0xc9cf, 0xc9fa, 0xcab1, 0xcab5, 0xcac7, + 0xcad0, 0xcad6, 0xcaf5, 0xcafd, 0xccec, 0xcdf8, 0xceaa, 0xcec4, 0xced2, 0xcee5, + 0xcfb5, 0xcfc2, 0xcfd6, 0xd0c2, 0xd0c5, 0xd0d0, 0xd0d4, 0xd1a7, 0xd2aa, 0xd2b2, + 0xd2b5, 0xd2bb, 0xd2d4, 0xd3c3, 0xd3d0, 0xd3fd, 0xd4c2, 0xd4da, 0xd5e2, 0xd6d0, +} + +func newRecognizer_gb_18030() *recognizerMultiByte { + return &recognizerMultiByte{ + "GB18030", + "zh", + charDecoder_gb_18030{}, + commonChars_gb_18030, + } +} diff --git a/vendor/github.com/gogs/chardet/recognizer.go b/vendor/github.com/gogs/chardet/recognizer.go new file mode 100644 index 00000000..1bf8461c --- /dev/null +++ b/vendor/github.com/gogs/chardet/recognizer.go @@ -0,0 +1,83 @@ +package chardet + +type recognizer interface { + Match(*recognizerInput) recognizerOutput +} + +type recognizerOutput Result + +type recognizerInput struct { + raw []byte + input []byte + tagStripped bool + byteStats []int + hasC1Bytes bool +} + +func newRecognizerInput(raw []byte, stripTag bool) *recognizerInput { + input, stripped := mayStripInput(raw, stripTag) + byteStats := computeByteStats(input) + return &recognizerInput{ + raw: raw, + input: input, + tagStripped: stripped, + byteStats: byteStats, + hasC1Bytes: computeHasC1Bytes(byteStats), + } +} + +func mayStripInput(raw []byte, stripTag bool) (out []byte, stripped bool) { + const inputBufferSize = 8192 + out = make([]byte, 0, inputBufferSize) + var badTags, openTags int32 + var inMarkup bool = false + stripped = false + if stripTag { + stripped = true + for _, c := range raw { + if c == '<' { + if inMarkup { + badTags += 1 + } + inMarkup = true + openTags += 1 + } + if !inMarkup { + out = append(out, c) + if len(out) >= inputBufferSize { + break + } + } + if c == '>' { + inMarkup = false + } + } + } + if openTags < 5 || openTags/5 < badTags || (len(out) < 100 && len(raw) > 600) { + limit := len(raw) + if limit > inputBufferSize { + limit = inputBufferSize + } + out = make([]byte, limit) + copy(out, raw[:limit]) + stripped = false + } + return +} + +func computeByteStats(input []byte) []int { + r := make([]int, 256) + for _, c := range input { + r[c] += 1 + } + return r +} + +func computeHasC1Bytes(byteStats []int) bool { + for _, count := range byteStats[0x80 : 0x9F+1] { + if count > 0 { + return true + } + } + return false +} diff --git a/vendor/github.com/gogs/chardet/single_byte.go b/vendor/github.com/gogs/chardet/single_byte.go new file mode 100644 index 00000000..a7ce39bc --- /dev/null +++ b/vendor/github.com/gogs/chardet/single_byte.go @@ -0,0 +1,882 @@ +package chardet + +// Recognizer for single byte charset family +type recognizerSingleByte struct { + charset string + hasC1ByteCharset string + language string + charMap *[256]byte + ngram *[64]uint32 +} + +func (r *recognizerSingleByte) Match(input *recognizerInput) recognizerOutput { + var charset string = r.charset + if input.hasC1Bytes && len(r.hasC1ByteCharset) > 0 { + charset = r.hasC1ByteCharset + } + return recognizerOutput{ + Charset: charset, + Language: r.language, + Confidence: r.parseNgram(input.input), + } +} + +type ngramState struct { + ngram uint32 + ignoreSpace bool + ngramCount, ngramHit uint32 + table *[64]uint32 +} + +func newNgramState(table *[64]uint32) *ngramState { + return &ngramState{ + ngram: 0, + ignoreSpace: false, + ngramCount: 0, + ngramHit: 0, + table: table, + } +} + +func (s *ngramState) AddByte(b byte) { + const ngramMask = 0xFFFFFF + if !(b == 0x20 && s.ignoreSpace) { + s.ngram = ((s.ngram << 8) | uint32(b)) & ngramMask + s.ignoreSpace = (s.ngram == 0x20) + s.ngramCount++ + if s.lookup() { + s.ngramHit++ + } + } + s.ignoreSpace = (b == 0x20) +} + +func (s *ngramState) HitRate() float32 { + if s.ngramCount == 0 { + return 0 + } + return float32(s.ngramHit) / float32(s.ngramCount) +} + +func (s *ngramState) lookup() bool { + var index int + if s.table[index+32] <= s.ngram { + index += 32 + } + if s.table[index+16] <= s.ngram { + index += 16 + } + if s.table[index+8] <= s.ngram { + index += 8 + } + if s.table[index+4] <= s.ngram { + index += 4 + } + if s.table[index+2] <= s.ngram { + index += 2 + } + if s.table[index+1] <= s.ngram { + index += 1 + } + if s.table[index] > s.ngram { + index -= 1 + } + if index < 0 || s.table[index] != s.ngram { + return false + } + return true +} + +func (r *recognizerSingleByte) parseNgram(input []byte) int { + state := newNgramState(r.ngram) + for _, inChar := range input { + c := r.charMap[inChar] + if c != 0 { + state.AddByte(c) + } + } + state.AddByte(0x20) + rate := state.HitRate() + if rate > 0.33 { + return 98 + } + return int(rate * 300) +} + +var charMap_8859_1 = [256]byte{ + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, + 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, + 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, + 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, + 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0xAA, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0xB5, 0x20, 0x20, + 0x20, 0x20, 0xBA, 0x20, 0x20, 0x20, 0x20, 0x20, + 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, + 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, + 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0x20, + 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xDF, + 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, + 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, + 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0x20, + 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF, +} + +var ngrams_8859_1_en = [64]uint32{ + 0x206120, 0x20616E, 0x206265, 0x20636F, 0x20666F, 0x206861, 0x206865, 0x20696E, 0x206D61, 0x206F66, 0x207072, 0x207265, 0x207361, 0x207374, 0x207468, 0x20746F, + 0x207768, 0x616964, 0x616C20, 0x616E20, 0x616E64, 0x617320, 0x617420, 0x617465, 0x617469, 0x642061, 0x642074, 0x652061, 0x652073, 0x652074, 0x656420, 0x656E74, + 0x657220, 0x657320, 0x666F72, 0x686174, 0x686520, 0x686572, 0x696420, 0x696E20, 0x696E67, 0x696F6E, 0x697320, 0x6E2061, 0x6E2074, 0x6E6420, 0x6E6720, 0x6E7420, + 0x6F6620, 0x6F6E20, 0x6F7220, 0x726520, 0x727320, 0x732061, 0x732074, 0x736169, 0x737420, 0x742074, 0x746572, 0x746861, 0x746865, 0x74696F, 0x746F20, 0x747320, +} + +var ngrams_8859_1_da = [64]uint32{ + 0x206166, 0x206174, 0x206465, 0x20656E, 0x206572, 0x20666F, 0x206861, 0x206920, 0x206D65, 0x206F67, 0x2070E5, 0x207369, 0x207374, 0x207469, 0x207669, 0x616620, + 0x616E20, 0x616E64, 0x617220, 0x617420, 0x646520, 0x64656E, 0x646572, 0x646574, 0x652073, 0x656420, 0x656465, 0x656E20, 0x656E64, 0x657220, 0x657265, 0x657320, + 0x657420, 0x666F72, 0x676520, 0x67656E, 0x676572, 0x696765, 0x696C20, 0x696E67, 0x6B6520, 0x6B6B65, 0x6C6572, 0x6C6967, 0x6C6C65, 0x6D6564, 0x6E6465, 0x6E6520, + 0x6E6720, 0x6E6765, 0x6F6720, 0x6F6D20, 0x6F7220, 0x70E520, 0x722064, 0x722065, 0x722073, 0x726520, 0x737465, 0x742073, 0x746520, 0x746572, 0x74696C, 0x766572, +} + +var ngrams_8859_1_de = [64]uint32{ + 0x20616E, 0x206175, 0x206265, 0x206461, 0x206465, 0x206469, 0x206569, 0x206765, 0x206861, 0x20696E, 0x206D69, 0x207363, 0x207365, 0x20756E, 0x207665, 0x20766F, + 0x207765, 0x207A75, 0x626572, 0x636820, 0x636865, 0x636874, 0x646173, 0x64656E, 0x646572, 0x646965, 0x652064, 0x652073, 0x65696E, 0x656974, 0x656E20, 0x657220, + 0x657320, 0x67656E, 0x68656E, 0x687420, 0x696368, 0x696520, 0x696E20, 0x696E65, 0x697420, 0x6C6963, 0x6C6C65, 0x6E2061, 0x6E2064, 0x6E2073, 0x6E6420, 0x6E6465, + 0x6E6520, 0x6E6720, 0x6E6765, 0x6E7465, 0x722064, 0x726465, 0x726569, 0x736368, 0x737465, 0x742064, 0x746520, 0x74656E, 0x746572, 0x756E64, 0x756E67, 0x766572, +} + +var ngrams_8859_1_es = [64]uint32{ + 0x206120, 0x206361, 0x20636F, 0x206465, 0x20656C, 0x20656E, 0x206573, 0x20696E, 0x206C61, 0x206C6F, 0x207061, 0x20706F, 0x207072, 0x207175, 0x207265, 0x207365, + 0x20756E, 0x207920, 0x612063, 0x612064, 0x612065, 0x61206C, 0x612070, 0x616369, 0x61646F, 0x616C20, 0x617220, 0x617320, 0x6369F3, 0x636F6E, 0x646520, 0x64656C, + 0x646F20, 0x652064, 0x652065, 0x65206C, 0x656C20, 0x656E20, 0x656E74, 0x657320, 0x657374, 0x69656E, 0x69F36E, 0x6C6120, 0x6C6F73, 0x6E2065, 0x6E7465, 0x6F2064, + 0x6F2065, 0x6F6E20, 0x6F7220, 0x6F7320, 0x706172, 0x717565, 0x726120, 0x726573, 0x732064, 0x732065, 0x732070, 0x736520, 0x746520, 0x746F20, 0x756520, 0xF36E20, +} + +var ngrams_8859_1_fr = [64]uint32{ + 0x206175, 0x20636F, 0x206461, 0x206465, 0x206475, 0x20656E, 0x206574, 0x206C61, 0x206C65, 0x207061, 0x20706F, 0x207072, 0x207175, 0x207365, 0x20736F, 0x20756E, + 0x20E020, 0x616E74, 0x617469, 0x636520, 0x636F6E, 0x646520, 0x646573, 0x647520, 0x652061, 0x652063, 0x652064, 0x652065, 0x65206C, 0x652070, 0x652073, 0x656E20, + 0x656E74, 0x657220, 0x657320, 0x657420, 0x657572, 0x696F6E, 0x697320, 0x697420, 0x6C6120, 0x6C6520, 0x6C6573, 0x6D656E, 0x6E2064, 0x6E6520, 0x6E7320, 0x6E7420, + 0x6F6E20, 0x6F6E74, 0x6F7572, 0x717565, 0x72206C, 0x726520, 0x732061, 0x732064, 0x732065, 0x73206C, 0x732070, 0x742064, 0x746520, 0x74696F, 0x756520, 0x757220, +} + +var ngrams_8859_1_it = [64]uint32{ + 0x20616C, 0x206368, 0x20636F, 0x206465, 0x206469, 0x206520, 0x20696C, 0x20696E, 0x206C61, 0x207065, 0x207072, 0x20756E, 0x612063, 0x612064, 0x612070, 0x612073, + 0x61746F, 0x636865, 0x636F6E, 0x64656C, 0x646920, 0x652061, 0x652063, 0x652064, 0x652069, 0x65206C, 0x652070, 0x652073, 0x656C20, 0x656C6C, 0x656E74, 0x657220, + 0x686520, 0x692061, 0x692063, 0x692064, 0x692073, 0x696120, 0x696C20, 0x696E20, 0x696F6E, 0x6C6120, 0x6C6520, 0x6C6920, 0x6C6C61, 0x6E6520, 0x6E6920, 0x6E6F20, + 0x6E7465, 0x6F2061, 0x6F2064, 0x6F2069, 0x6F2073, 0x6F6E20, 0x6F6E65, 0x706572, 0x726120, 0x726520, 0x736920, 0x746120, 0x746520, 0x746920, 0x746F20, 0x7A696F, +} + +var ngrams_8859_1_nl = [64]uint32{ + 0x20616C, 0x206265, 0x206461, 0x206465, 0x206469, 0x206565, 0x20656E, 0x206765, 0x206865, 0x20696E, 0x206D61, 0x206D65, 0x206F70, 0x207465, 0x207661, 0x207665, + 0x20766F, 0x207765, 0x207A69, 0x61616E, 0x616172, 0x616E20, 0x616E64, 0x617220, 0x617420, 0x636874, 0x646520, 0x64656E, 0x646572, 0x652062, 0x652076, 0x65656E, + 0x656572, 0x656E20, 0x657220, 0x657273, 0x657420, 0x67656E, 0x686574, 0x696520, 0x696E20, 0x696E67, 0x697320, 0x6E2062, 0x6E2064, 0x6E2065, 0x6E2068, 0x6E206F, + 0x6E2076, 0x6E6465, 0x6E6720, 0x6F6E64, 0x6F6F72, 0x6F7020, 0x6F7220, 0x736368, 0x737465, 0x742064, 0x746520, 0x74656E, 0x746572, 0x76616E, 0x766572, 0x766F6F, +} + +var ngrams_8859_1_no = [64]uint32{ + 0x206174, 0x206176, 0x206465, 0x20656E, 0x206572, 0x20666F, 0x206861, 0x206920, 0x206D65, 0x206F67, 0x2070E5, 0x207365, 0x20736B, 0x20736F, 0x207374, 0x207469, + 0x207669, 0x20E520, 0x616E64, 0x617220, 0x617420, 0x646520, 0x64656E, 0x646574, 0x652073, 0x656420, 0x656E20, 0x656E65, 0x657220, 0x657265, 0x657420, 0x657474, + 0x666F72, 0x67656E, 0x696B6B, 0x696C20, 0x696E67, 0x6B6520, 0x6B6B65, 0x6C6520, 0x6C6C65, 0x6D6564, 0x6D656E, 0x6E2073, 0x6E6520, 0x6E6720, 0x6E6765, 0x6E6E65, + 0x6F6720, 0x6F6D20, 0x6F7220, 0x70E520, 0x722073, 0x726520, 0x736F6D, 0x737465, 0x742073, 0x746520, 0x74656E, 0x746572, 0x74696C, 0x747420, 0x747465, 0x766572, +} + +var ngrams_8859_1_pt = [64]uint32{ + 0x206120, 0x20636F, 0x206461, 0x206465, 0x20646F, 0x206520, 0x206573, 0x206D61, 0x206E6F, 0x206F20, 0x207061, 0x20706F, 0x207072, 0x207175, 0x207265, 0x207365, + 0x20756D, 0x612061, 0x612063, 0x612064, 0x612070, 0x616465, 0x61646F, 0x616C20, 0x617220, 0x617261, 0x617320, 0x636F6D, 0x636F6E, 0x646120, 0x646520, 0x646F20, + 0x646F73, 0x652061, 0x652064, 0x656D20, 0x656E74, 0x657320, 0x657374, 0x696120, 0x696361, 0x6D656E, 0x6E7465, 0x6E746F, 0x6F2061, 0x6F2063, 0x6F2064, 0x6F2065, + 0x6F2070, 0x6F7320, 0x706172, 0x717565, 0x726120, 0x726573, 0x732061, 0x732064, 0x732065, 0x732070, 0x737461, 0x746520, 0x746F20, 0x756520, 0xE36F20, 0xE7E36F, +} + +var ngrams_8859_1_sv = [64]uint32{ + 0x206174, 0x206176, 0x206465, 0x20656E, 0x2066F6, 0x206861, 0x206920, 0x20696E, 0x206B6F, 0x206D65, 0x206F63, 0x2070E5, 0x20736B, 0x20736F, 0x207374, 0x207469, + 0x207661, 0x207669, 0x20E472, 0x616465, 0x616E20, 0x616E64, 0x617220, 0x617474, 0x636820, 0x646520, 0x64656E, 0x646572, 0x646574, 0x656420, 0x656E20, 0x657220, + 0x657420, 0x66F672, 0x67656E, 0x696C6C, 0x696E67, 0x6B6120, 0x6C6C20, 0x6D6564, 0x6E2073, 0x6E6120, 0x6E6465, 0x6E6720, 0x6E6765, 0x6E696E, 0x6F6368, 0x6F6D20, + 0x6F6E20, 0x70E520, 0x722061, 0x722073, 0x726120, 0x736B61, 0x736F6D, 0x742073, 0x746120, 0x746520, 0x746572, 0x74696C, 0x747420, 0x766172, 0xE47220, 0xF67220, +} + +func newRecognizer_8859_1(language string, ngram *[64]uint32) *recognizerSingleByte { + return &recognizerSingleByte{ + charset: "ISO-8859-1", + hasC1ByteCharset: "windows-1252", + language: language, + charMap: &charMap_8859_1, + ngram: ngram, + } +} + +func newRecognizer_8859_1_en() *recognizerSingleByte { + return newRecognizer_8859_1("en", &ngrams_8859_1_en) +} +func newRecognizer_8859_1_da() *recognizerSingleByte { + return newRecognizer_8859_1("da", &ngrams_8859_1_da) +} +func newRecognizer_8859_1_de() *recognizerSingleByte { + return newRecognizer_8859_1("de", &ngrams_8859_1_de) +} +func newRecognizer_8859_1_es() *recognizerSingleByte { + return newRecognizer_8859_1("es", &ngrams_8859_1_es) +} +func newRecognizer_8859_1_fr() *recognizerSingleByte { + return newRecognizer_8859_1("fr", &ngrams_8859_1_fr) +} +func newRecognizer_8859_1_it() *recognizerSingleByte { + return newRecognizer_8859_1("it", &ngrams_8859_1_it) +} +func newRecognizer_8859_1_nl() *recognizerSingleByte { + return newRecognizer_8859_1("nl", &ngrams_8859_1_nl) +} +func newRecognizer_8859_1_no() *recognizerSingleByte { + return newRecognizer_8859_1("no", &ngrams_8859_1_no) +} +func newRecognizer_8859_1_pt() *recognizerSingleByte { + return newRecognizer_8859_1("pt", &ngrams_8859_1_pt) +} +func newRecognizer_8859_1_sv() *recognizerSingleByte { + return newRecognizer_8859_1("sv", &ngrams_8859_1_sv) +} + +var charMap_8859_2 = [256]byte{ + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, + 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, + 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, + 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, + 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0xB1, 0x20, 0xB3, 0x20, 0xB5, 0xB6, 0x20, + 0x20, 0xB9, 0xBA, 0xBB, 0xBC, 0x20, 0xBE, 0xBF, + 0x20, 0xB1, 0x20, 0xB3, 0x20, 0xB5, 0xB6, 0xB7, + 0x20, 0xB9, 0xBA, 0xBB, 0xBC, 0x20, 0xBE, 0xBF, + 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, + 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, + 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0x20, + 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xDF, + 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, + 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, + 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0x20, + 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0x20, +} + +var ngrams_8859_2_cs = [64]uint32{ + 0x206120, 0x206279, 0x20646F, 0x206A65, 0x206E61, 0x206E65, 0x206F20, 0x206F64, 0x20706F, 0x207072, 0x2070F8, 0x20726F, 0x207365, 0x20736F, 0x207374, 0x20746F, + 0x207620, 0x207679, 0x207A61, 0x612070, 0x636520, 0x636820, 0x652070, 0x652073, 0x652076, 0x656D20, 0x656EED, 0x686F20, 0x686F64, 0x697374, 0x6A6520, 0x6B7465, + 0x6C6520, 0x6C6920, 0x6E6120, 0x6EE920, 0x6EEC20, 0x6EED20, 0x6F2070, 0x6F646E, 0x6F6A69, 0x6F7374, 0x6F7520, 0x6F7661, 0x706F64, 0x706F6A, 0x70726F, 0x70F865, + 0x736520, 0x736F75, 0x737461, 0x737469, 0x73746E, 0x746572, 0x746EED, 0x746F20, 0x752070, 0xBE6520, 0xE16EED, 0xE9686F, 0xED2070, 0xED2073, 0xED6D20, 0xF86564, +} + +var ngrams_8859_2_hu = [64]uint32{ + 0x206120, 0x20617A, 0x206265, 0x206567, 0x20656C, 0x206665, 0x206861, 0x20686F, 0x206973, 0x206B65, 0x206B69, 0x206BF6, 0x206C65, 0x206D61, 0x206D65, 0x206D69, + 0x206E65, 0x20737A, 0x207465, 0x20E973, 0x612061, 0x61206B, 0x61206D, 0x612073, 0x616B20, 0x616E20, 0x617A20, 0x62616E, 0x62656E, 0x656779, 0x656B20, 0x656C20, + 0x656C65, 0x656D20, 0x656E20, 0x657265, 0x657420, 0x657465, 0x657474, 0x677920, 0x686F67, 0x696E74, 0x697320, 0x6B2061, 0x6BF67A, 0x6D6567, 0x6D696E, 0x6E2061, + 0x6E616B, 0x6E656B, 0x6E656D, 0x6E7420, 0x6F6779, 0x732061, 0x737A65, 0x737A74, 0x737AE1, 0x73E967, 0x742061, 0x747420, 0x74E173, 0x7A6572, 0xE16E20, 0xE97320, +} + +var ngrams_8859_2_pl = [64]uint32{ + 0x20637A, 0x20646F, 0x206920, 0x206A65, 0x206B6F, 0x206D61, 0x206D69, 0x206E61, 0x206E69, 0x206F64, 0x20706F, 0x207072, 0x207369, 0x207720, 0x207769, 0x207779, + 0x207A20, 0x207A61, 0x612070, 0x612077, 0x616E69, 0x636820, 0x637A65, 0x637A79, 0x646F20, 0x647A69, 0x652070, 0x652073, 0x652077, 0x65207A, 0x65676F, 0x656A20, + 0x656D20, 0x656E69, 0x676F20, 0x696120, 0x696520, 0x69656A, 0x6B6120, 0x6B6920, 0x6B6965, 0x6D6965, 0x6E6120, 0x6E6961, 0x6E6965, 0x6F2070, 0x6F7761, 0x6F7769, + 0x706F6C, 0x707261, 0x70726F, 0x70727A, 0x727A65, 0x727A79, 0x7369EA, 0x736B69, 0x737461, 0x776965, 0x796368, 0x796D20, 0x7A6520, 0x7A6965, 0x7A7920, 0xF37720, +} + +var ngrams_8859_2_ro = [64]uint32{ + 0x206120, 0x206163, 0x206361, 0x206365, 0x20636F, 0x206375, 0x206465, 0x206469, 0x206C61, 0x206D61, 0x207065, 0x207072, 0x207365, 0x2073E3, 0x20756E, 0x20BA69, + 0x20EE6E, 0x612063, 0x612064, 0x617265, 0x617420, 0x617465, 0x617520, 0x636172, 0x636F6E, 0x637520, 0x63E320, 0x646520, 0x652061, 0x652063, 0x652064, 0x652070, + 0x652073, 0x656120, 0x656920, 0x656C65, 0x656E74, 0x657374, 0x692061, 0x692063, 0x692064, 0x692070, 0x696520, 0x696920, 0x696E20, 0x6C6120, 0x6C6520, 0x6C6F72, + 0x6C7569, 0x6E6520, 0x6E7472, 0x6F7220, 0x70656E, 0x726520, 0x726561, 0x727520, 0x73E320, 0x746520, 0x747275, 0x74E320, 0x756920, 0x756C20, 0xBA6920, 0xEE6E20, +} + +func newRecognizer_8859_2(language string, ngram *[64]uint32) *recognizerSingleByte { + return &recognizerSingleByte{ + charset: "ISO-8859-2", + hasC1ByteCharset: "windows-1250", + language: language, + charMap: &charMap_8859_2, + ngram: ngram, + } +} + +func newRecognizer_8859_2_cs() *recognizerSingleByte { + return newRecognizer_8859_2("cs", &ngrams_8859_2_cs) +} +func newRecognizer_8859_2_hu() *recognizerSingleByte { + return newRecognizer_8859_2("hu", &ngrams_8859_2_hu) +} +func newRecognizer_8859_2_pl() *recognizerSingleByte { + return newRecognizer_8859_2("pl", &ngrams_8859_2_pl) +} +func newRecognizer_8859_2_ro() *recognizerSingleByte { + return newRecognizer_8859_2("ro", &ngrams_8859_2_ro) +} + +var charMap_8859_5 = [256]byte{ + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, + 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, + 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, + 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, + 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, + 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0x20, 0xFE, 0xFF, + 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, + 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, + 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, + 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, + 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, + 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, + 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, + 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, + 0x20, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, + 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0x20, 0xFE, 0xFF, +} + +var ngrams_8859_5_ru = [64]uint32{ + 0x20D220, 0x20D2DE, 0x20D4DE, 0x20D7D0, 0x20D820, 0x20DAD0, 0x20DADE, 0x20DDD0, 0x20DDD5, 0x20DED1, 0x20DFDE, 0x20DFE0, 0x20E0D0, 0x20E1DE, 0x20E1E2, 0x20E2DE, + 0x20E7E2, 0x20EDE2, 0xD0DDD8, 0xD0E2EC, 0xD3DE20, 0xD5DBEC, 0xD5DDD8, 0xD5E1E2, 0xD5E220, 0xD820DF, 0xD8D520, 0xD8D820, 0xD8EF20, 0xDBD5DD, 0xDBD820, 0xDBECDD, + 0xDDD020, 0xDDD520, 0xDDD8D5, 0xDDD8EF, 0xDDDE20, 0xDDDED2, 0xDE20D2, 0xDE20DF, 0xDE20E1, 0xDED220, 0xDED2D0, 0xDED3DE, 0xDED920, 0xDEDBEC, 0xDEDC20, 0xDEE1E2, + 0xDFDEDB, 0xDFE0D5, 0xDFE0D8, 0xDFE0DE, 0xE0D0D2, 0xE0D5D4, 0xE1E2D0, 0xE1E2D2, 0xE1E2D8, 0xE1EF20, 0xE2D5DB, 0xE2DE20, 0xE2DEE0, 0xE2EC20, 0xE7E2DE, 0xEBE520, +} + +func newRecognizer_8859_5(language string, ngram *[64]uint32) *recognizerSingleByte { + return &recognizerSingleByte{ + charset: "ISO-8859-5", + language: language, + charMap: &charMap_8859_5, + ngram: ngram, + } +} + +func newRecognizer_8859_5_ru() *recognizerSingleByte { + return newRecognizer_8859_5("ru", &ngrams_8859_5_ru) +} + +var charMap_8859_6 = [256]byte{ + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, + 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, + 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, + 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, + 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, + 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, + 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, + 0xD8, 0xD9, 0xDA, 0x20, 0x20, 0x20, 0x20, 0x20, + 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, + 0xE8, 0xE9, 0xEA, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, +} + +var ngrams_8859_6_ar = [64]uint32{ + 0x20C7E4, 0x20C7E6, 0x20C8C7, 0x20D9E4, 0x20E1EA, 0x20E4E4, 0x20E5E6, 0x20E8C7, 0xC720C7, 0xC7C120, 0xC7CA20, 0xC7D120, 0xC7E420, 0xC7E4C3, 0xC7E4C7, 0xC7E4C8, + 0xC7E4CA, 0xC7E4CC, 0xC7E4CD, 0xC7E4CF, 0xC7E4D3, 0xC7E4D9, 0xC7E4E2, 0xC7E4E5, 0xC7E4E8, 0xC7E4EA, 0xC7E520, 0xC7E620, 0xC7E6CA, 0xC820C7, 0xC920C7, 0xC920E1, + 0xC920E4, 0xC920E5, 0xC920E8, 0xCA20C7, 0xCF20C7, 0xCFC920, 0xD120C7, 0xD1C920, 0xD320C7, 0xD920C7, 0xD9E4E9, 0xE1EA20, 0xE420C7, 0xE4C920, 0xE4E920, 0xE4EA20, + 0xE520C7, 0xE5C720, 0xE5C920, 0xE5E620, 0xE620C7, 0xE720C7, 0xE7C720, 0xE8C7E4, 0xE8E620, 0xE920C7, 0xEA20C7, 0xEA20E5, 0xEA20E8, 0xEAC920, 0xEAD120, 0xEAE620, +} + +func newRecognizer_8859_6(language string, ngram *[64]uint32) *recognizerSingleByte { + return &recognizerSingleByte{ + charset: "ISO-8859-6", + language: language, + charMap: &charMap_8859_6, + ngram: ngram, + } +} + +func newRecognizer_8859_6_ar() *recognizerSingleByte { + return newRecognizer_8859_6("ar", &ngrams_8859_6_ar) +} + +var charMap_8859_7 = [256]byte{ + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, + 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, + 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, + 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, + 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0xA1, 0xA2, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0xDC, 0x20, + 0xDD, 0xDE, 0xDF, 0x20, 0xFC, 0x20, 0xFD, 0xFE, + 0xC0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, + 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, + 0xF0, 0xF1, 0x20, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, + 0xF8, 0xF9, 0xFA, 0xFB, 0xDC, 0xDD, 0xDE, 0xDF, + 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, + 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, + 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, + 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0x20, +} + +var ngrams_8859_7_el = [64]uint32{ + 0x20E1ED, 0x20E1F0, 0x20E3E9, 0x20E4E9, 0x20E5F0, 0x20E720, 0x20EAE1, 0x20ECE5, 0x20EDE1, 0x20EF20, 0x20F0E1, 0x20F0EF, 0x20F0F1, 0x20F3F4, 0x20F3F5, 0x20F4E7, + 0x20F4EF, 0xDFE120, 0xE120E1, 0xE120F4, 0xE1E920, 0xE1ED20, 0xE1F0FC, 0xE1F220, 0xE3E9E1, 0xE5E920, 0xE5F220, 0xE720F4, 0xE7ED20, 0xE7F220, 0xE920F4, 0xE9E120, + 0xE9EADE, 0xE9F220, 0xEAE1E9, 0xEAE1F4, 0xECE520, 0xED20E1, 0xED20E5, 0xED20F0, 0xEDE120, 0xEFF220, 0xEFF520, 0xF0EFF5, 0xF0F1EF, 0xF0FC20, 0xF220E1, 0xF220E5, + 0xF220EA, 0xF220F0, 0xF220F4, 0xF3E520, 0xF3E720, 0xF3F4EF, 0xF4E120, 0xF4E1E9, 0xF4E7ED, 0xF4E7F2, 0xF4E9EA, 0xF4EF20, 0xF4EFF5, 0xF4F9ED, 0xF9ED20, 0xFEED20, +} + +func newRecognizer_8859_7(language string, ngram *[64]uint32) *recognizerSingleByte { + return &recognizerSingleByte{ + charset: "ISO-8859-7", + hasC1ByteCharset: "windows-1253", + language: language, + charMap: &charMap_8859_7, + ngram: ngram, + } +} + +func newRecognizer_8859_7_el() *recognizerSingleByte { + return newRecognizer_8859_7("el", &ngrams_8859_7_el) +} + +var charMap_8859_8 = [256]byte{ + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, + 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, + 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, + 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, + 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0xB5, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, + 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, + 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, + 0xF8, 0xF9, 0xFA, 0x20, 0x20, 0x20, 0x20, 0x20, +} + +var ngrams_8859_8_I_he = [64]uint32{ + 0x20E0E5, 0x20E0E7, 0x20E0E9, 0x20E0FA, 0x20E1E9, 0x20E1EE, 0x20E4E0, 0x20E4E5, 0x20E4E9, 0x20E4EE, 0x20E4F2, 0x20E4F9, 0x20E4FA, 0x20ECE0, 0x20ECE4, 0x20EEE0, + 0x20F2EC, 0x20F9EC, 0xE0FA20, 0xE420E0, 0xE420E1, 0xE420E4, 0xE420EC, 0xE420EE, 0xE420F9, 0xE4E5E0, 0xE5E020, 0xE5ED20, 0xE5EF20, 0xE5F820, 0xE5FA20, 0xE920E4, + 0xE9E420, 0xE9E5FA, 0xE9E9ED, 0xE9ED20, 0xE9EF20, 0xE9F820, 0xE9FA20, 0xEC20E0, 0xEC20E4, 0xECE020, 0xECE420, 0xED20E0, 0xED20E1, 0xED20E4, 0xED20EC, 0xED20EE, + 0xED20F9, 0xEEE420, 0xEF20E4, 0xF0E420, 0xF0E920, 0xF0E9ED, 0xF2EC20, 0xF820E4, 0xF8E9ED, 0xF9EC20, 0xFA20E0, 0xFA20E1, 0xFA20E4, 0xFA20EC, 0xFA20EE, 0xFA20F9, +} + +var ngrams_8859_8_he = [64]uint32{ + 0x20E0E5, 0x20E0EC, 0x20E4E9, 0x20E4EC, 0x20E4EE, 0x20E4F0, 0x20E9F0, 0x20ECF2, 0x20ECF9, 0x20EDE5, 0x20EDE9, 0x20EFE5, 0x20EFE9, 0x20F8E5, 0x20F8E9, 0x20FAE0, + 0x20FAE5, 0x20FAE9, 0xE020E4, 0xE020EC, 0xE020ED, 0xE020FA, 0xE0E420, 0xE0E5E4, 0xE0EC20, 0xE0EE20, 0xE120E4, 0xE120ED, 0xE120FA, 0xE420E4, 0xE420E9, 0xE420EC, + 0xE420ED, 0xE420EF, 0xE420F8, 0xE420FA, 0xE4EC20, 0xE5E020, 0xE5E420, 0xE7E020, 0xE9E020, 0xE9E120, 0xE9E420, 0xEC20E4, 0xEC20ED, 0xEC20FA, 0xECF220, 0xECF920, + 0xEDE9E9, 0xEDE9F0, 0xEDE9F8, 0xEE20E4, 0xEE20ED, 0xEE20FA, 0xEEE120, 0xEEE420, 0xF2E420, 0xF920E4, 0xF920ED, 0xF920FA, 0xF9E420, 0xFAE020, 0xFAE420, 0xFAE5E9, +} + +func newRecognizer_8859_8(language string, ngram *[64]uint32) *recognizerSingleByte { + return &recognizerSingleByte{ + charset: "ISO-8859-8", + hasC1ByteCharset: "windows-1255", + language: language, + charMap: &charMap_8859_8, + ngram: ngram, + } +} + +func newRecognizer_8859_8_I_he() *recognizerSingleByte { + r := newRecognizer_8859_8("he", &ngrams_8859_8_I_he) + r.charset = "ISO-8859-8-I" + return r +} + +func newRecognizer_8859_8_he() *recognizerSingleByte { + return newRecognizer_8859_8("he", &ngrams_8859_8_he) +} + +var charMap_8859_9 = [256]byte{ + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, + 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, + 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, + 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, + 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0xAA, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0xB5, 0x20, 0x20, + 0x20, 0x20, 0xBA, 0x20, 0x20, 0x20, 0x20, 0x20, + 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, + 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, + 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0x20, + 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0x69, 0xFE, 0xDF, + 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, + 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, + 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0x20, + 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF, +} + +var ngrams_8859_9_tr = [64]uint32{ + 0x206261, 0x206269, 0x206275, 0x206461, 0x206465, 0x206765, 0x206861, 0x20696C, 0x206B61, 0x206B6F, 0x206D61, 0x206F6C, 0x207361, 0x207461, 0x207665, 0x207961, + 0x612062, 0x616B20, 0x616C61, 0x616D61, 0x616E20, 0x616EFD, 0x617220, 0x617261, 0x6172FD, 0x6173FD, 0x617961, 0x626972, 0x646120, 0x646520, 0x646920, 0x652062, + 0x65206B, 0x656469, 0x656E20, 0x657220, 0x657269, 0x657369, 0x696C65, 0x696E20, 0x696E69, 0x697220, 0x6C616E, 0x6C6172, 0x6C6520, 0x6C6572, 0x6E2061, 0x6E2062, + 0x6E206B, 0x6E6461, 0x6E6465, 0x6E6520, 0x6E6920, 0x6E696E, 0x6EFD20, 0x72696E, 0x72FD6E, 0x766520, 0x796120, 0x796F72, 0xFD6E20, 0xFD6E64, 0xFD6EFD, 0xFDF0FD, +} + +func newRecognizer_8859_9(language string, ngram *[64]uint32) *recognizerSingleByte { + return &recognizerSingleByte{ + charset: "ISO-8859-9", + hasC1ByteCharset: "windows-1254", + language: language, + charMap: &charMap_8859_9, + ngram: ngram, + } +} + +func newRecognizer_8859_9_tr() *recognizerSingleByte { + return newRecognizer_8859_9("tr", &ngrams_8859_9_tr) +} + +var charMap_windows_1256 = [256]byte{ + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, + 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, + 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, + 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, + 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x81, 0x20, 0x83, 0x20, 0x20, 0x20, 0x20, + 0x88, 0x20, 0x8A, 0x20, 0x9C, 0x8D, 0x8E, 0x8F, + 0x90, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x98, 0x20, 0x9A, 0x20, 0x9C, 0x20, 0x20, 0x9F, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0xAA, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0xB5, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, + 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, + 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0x20, + 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, + 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, + 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, + 0x20, 0x20, 0x20, 0x20, 0xF4, 0x20, 0x20, 0x20, + 0x20, 0xF9, 0x20, 0xFB, 0xFC, 0x20, 0x20, 0xFF, +} + +var ngrams_windows_1256 = [64]uint32{ + 0x20C7E1, 0x20C7E4, 0x20C8C7, 0x20DAE1, 0x20DDED, 0x20E1E1, 0x20E3E4, 0x20E6C7, 0xC720C7, 0xC7C120, 0xC7CA20, 0xC7D120, 0xC7E120, 0xC7E1C3, 0xC7E1C7, 0xC7E1C8, + 0xC7E1CA, 0xC7E1CC, 0xC7E1CD, 0xC7E1CF, 0xC7E1D3, 0xC7E1DA, 0xC7E1DE, 0xC7E1E3, 0xC7E1E6, 0xC7E1ED, 0xC7E320, 0xC7E420, 0xC7E4CA, 0xC820C7, 0xC920C7, 0xC920DD, + 0xC920E1, 0xC920E3, 0xC920E6, 0xCA20C7, 0xCF20C7, 0xCFC920, 0xD120C7, 0xD1C920, 0xD320C7, 0xDA20C7, 0xDAE1EC, 0xDDED20, 0xE120C7, 0xE1C920, 0xE1EC20, 0xE1ED20, + 0xE320C7, 0xE3C720, 0xE3C920, 0xE3E420, 0xE420C7, 0xE520C7, 0xE5C720, 0xE6C7E1, 0xE6E420, 0xEC20C7, 0xED20C7, 0xED20E3, 0xED20E6, 0xEDC920, 0xEDD120, 0xEDE420, +} + +func newRecognizer_windows_1256() *recognizerSingleByte { + return &recognizerSingleByte{ + charset: "windows-1256", + language: "ar", + charMap: &charMap_windows_1256, + ngram: &ngrams_windows_1256, + } +} + +var charMap_windows_1251 = [256]byte{ + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, + 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, + 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, + 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, + 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x90, 0x83, 0x20, 0x83, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x9A, 0x20, 0x9C, 0x9D, 0x9E, 0x9F, + 0x90, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x9A, 0x20, 0x9C, 0x9D, 0x9E, 0x9F, + 0x20, 0xA2, 0xA2, 0xBC, 0x20, 0xB4, 0x20, 0x20, + 0xB8, 0x20, 0xBA, 0x20, 0x20, 0x20, 0x20, 0xBF, + 0x20, 0x20, 0xB3, 0xB3, 0xB4, 0xB5, 0x20, 0x20, + 0xB8, 0x20, 0xBA, 0x20, 0xBC, 0xBE, 0xBE, 0xBF, + 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, + 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, + 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, + 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF, + 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, + 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, + 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, + 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF, +} + +var ngrams_windows_1251 = [64]uint32{ + 0x20E220, 0x20E2EE, 0x20E4EE, 0x20E7E0, 0x20E820, 0x20EAE0, 0x20EAEE, 0x20EDE0, 0x20EDE5, 0x20EEE1, 0x20EFEE, 0x20EFF0, 0x20F0E0, 0x20F1EE, 0x20F1F2, 0x20F2EE, + 0x20F7F2, 0x20FDF2, 0xE0EDE8, 0xE0F2FC, 0xE3EE20, 0xE5EBFC, 0xE5EDE8, 0xE5F1F2, 0xE5F220, 0xE820EF, 0xE8E520, 0xE8E820, 0xE8FF20, 0xEBE5ED, 0xEBE820, 0xEBFCED, + 0xEDE020, 0xEDE520, 0xEDE8E5, 0xEDE8FF, 0xEDEE20, 0xEDEEE2, 0xEE20E2, 0xEE20EF, 0xEE20F1, 0xEEE220, 0xEEE2E0, 0xEEE3EE, 0xEEE920, 0xEEEBFC, 0xEEEC20, 0xEEF1F2, + 0xEFEEEB, 0xEFF0E5, 0xEFF0E8, 0xEFF0EE, 0xF0E0E2, 0xF0E5E4, 0xF1F2E0, 0xF1F2E2, 0xF1F2E8, 0xF1FF20, 0xF2E5EB, 0xF2EE20, 0xF2EEF0, 0xF2FC20, 0xF7F2EE, 0xFBF520, +} + +func newRecognizer_windows_1251() *recognizerSingleByte { + return &recognizerSingleByte{ + charset: "windows-1251", + language: "ar", + charMap: &charMap_windows_1251, + ngram: &ngrams_windows_1251, + } +} + +var charMap_KOI8_R = [256]byte{ + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, + 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, + 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, + 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, + 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0xA3, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0xA3, 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, + 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, + 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, + 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, + 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, + 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, + 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, + 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, +} + +var ngrams_KOI8_R = [64]uint32{ + 0x20C4CF, 0x20C920, 0x20CBC1, 0x20CBCF, 0x20CEC1, 0x20CEC5, 0x20CFC2, 0x20D0CF, 0x20D0D2, 0x20D2C1, 0x20D3CF, 0x20D3D4, 0x20D4CF, 0x20D720, 0x20D7CF, 0x20DAC1, + 0x20DCD4, 0x20DED4, 0xC1CEC9, 0xC1D4D8, 0xC5CCD8, 0xC5CEC9, 0xC5D3D4, 0xC5D420, 0xC7CF20, 0xC920D0, 0xC9C520, 0xC9C920, 0xC9D120, 0xCCC5CE, 0xCCC920, 0xCCD8CE, + 0xCEC120, 0xCEC520, 0xCEC9C5, 0xCEC9D1, 0xCECF20, 0xCECFD7, 0xCF20D0, 0xCF20D3, 0xCF20D7, 0xCFC7CF, 0xCFCA20, 0xCFCCD8, 0xCFCD20, 0xCFD3D4, 0xCFD720, 0xCFD7C1, + 0xD0CFCC, 0xD0D2C5, 0xD0D2C9, 0xD0D2CF, 0xD2C1D7, 0xD2C5C4, 0xD3D120, 0xD3D4C1, 0xD3D4C9, 0xD3D4D7, 0xD4C5CC, 0xD4CF20, 0xD4CFD2, 0xD4D820, 0xD9C820, 0xDED4CF, +} + +func newRecognizer_KOI8_R() *recognizerSingleByte { + return &recognizerSingleByte{ + charset: "KOI8-R", + language: "ru", + charMap: &charMap_KOI8_R, + ngram: &ngrams_KOI8_R, + } +} + +var charMap_IBM424_he = [256]byte{ + /* -0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -A -B -C -D -E -F */ + /* 0- */ 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, + /* 1- */ 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, + /* 2- */ 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, + /* 3- */ 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, + /* 4- */ 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, + /* 5- */ 0x40, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, + /* 6- */ 0x40, 0x40, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, + /* 7- */ 0x40, 0x71, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, 0x40, 0x40, + /* 8- */ 0x40, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, + /* 9- */ 0x40, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, + /* A- */ 0xA0, 0x40, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, + /* B- */ 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, + /* C- */ 0x40, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, + /* D- */ 0x40, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, + /* E- */ 0x40, 0x40, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, + /* F- */ 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, +} + +var ngrams_IBM424_he_rtl = [64]uint32{ + 0x404146, 0x404148, 0x404151, 0x404171, 0x404251, 0x404256, 0x404541, 0x404546, 0x404551, 0x404556, 0x404562, 0x404569, 0x404571, 0x405441, 0x405445, 0x405641, + 0x406254, 0x406954, 0x417140, 0x454041, 0x454042, 0x454045, 0x454054, 0x454056, 0x454069, 0x454641, 0x464140, 0x465540, 0x465740, 0x466840, 0x467140, 0x514045, + 0x514540, 0x514671, 0x515155, 0x515540, 0x515740, 0x516840, 0x517140, 0x544041, 0x544045, 0x544140, 0x544540, 0x554041, 0x554042, 0x554045, 0x554054, 0x554056, + 0x554069, 0x564540, 0x574045, 0x584540, 0x585140, 0x585155, 0x625440, 0x684045, 0x685155, 0x695440, 0x714041, 0x714042, 0x714045, 0x714054, 0x714056, 0x714069, +} + +var ngrams_IBM424_he_ltr = [64]uint32{ + 0x404146, 0x404154, 0x404551, 0x404554, 0x404556, 0x404558, 0x405158, 0x405462, 0x405469, 0x405546, 0x405551, 0x405746, 0x405751, 0x406846, 0x406851, 0x407141, + 0x407146, 0x407151, 0x414045, 0x414054, 0x414055, 0x414071, 0x414540, 0x414645, 0x415440, 0x415640, 0x424045, 0x424055, 0x424071, 0x454045, 0x454051, 0x454054, + 0x454055, 0x454057, 0x454068, 0x454071, 0x455440, 0x464140, 0x464540, 0x484140, 0x514140, 0x514240, 0x514540, 0x544045, 0x544055, 0x544071, 0x546240, 0x546940, + 0x555151, 0x555158, 0x555168, 0x564045, 0x564055, 0x564071, 0x564240, 0x564540, 0x624540, 0x694045, 0x694055, 0x694071, 0x694540, 0x714140, 0x714540, 0x714651, +} + +func newRecognizer_IBM424_he(charset string, ngram *[64]uint32) *recognizerSingleByte { + return &recognizerSingleByte{ + charset: charset, + language: "he", + charMap: &charMap_IBM424_he, + ngram: ngram, + } +} + +func newRecognizer_IBM424_he_rtl() *recognizerSingleByte { + return newRecognizer_IBM424_he("IBM424_rtl", &ngrams_IBM424_he_rtl) +} + +func newRecognizer_IBM424_he_ltr() *recognizerSingleByte { + return newRecognizer_IBM424_he("IBM424_ltr", &ngrams_IBM424_he_ltr) +} + +var charMap_IBM420_ar = [256]byte{ + /* -0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -A -B -C -D -E -F */ + /* 0- */ 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, + /* 1- */ 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, + /* 2- */ 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, + /* 3- */ 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, + /* 4- */ 0x40, 0x40, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, + /* 5- */ 0x40, 0x51, 0x52, 0x40, 0x40, 0x55, 0x56, 0x57, 0x58, 0x59, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, + /* 6- */ 0x40, 0x40, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, + /* 7- */ 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, + /* 8- */ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, + /* 9- */ 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F, + /* A- */ 0xA0, 0x40, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, + /* B- */ 0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0x40, 0x40, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF, + /* C- */ 0x40, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x40, 0xCB, 0x40, 0xCD, 0x40, 0xCF, + /* D- */ 0x40, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, + /* E- */ 0x40, 0x40, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xEA, 0xEB, 0x40, 0xED, 0xEE, 0xEF, + /* F- */ 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0xFB, 0xFC, 0xFD, 0xFE, 0x40, +} + +var ngrams_IBM420_ar_rtl = [64]uint32{ + 0x4056B1, 0x4056BD, 0x405856, 0x409AB1, 0x40ABDC, 0x40B1B1, 0x40BBBD, 0x40CF56, 0x564056, 0x564640, 0x566340, 0x567540, 0x56B140, 0x56B149, 0x56B156, 0x56B158, + 0x56B163, 0x56B167, 0x56B169, 0x56B173, 0x56B178, 0x56B19A, 0x56B1AD, 0x56B1BB, 0x56B1CF, 0x56B1DC, 0x56BB40, 0x56BD40, 0x56BD63, 0x584056, 0x624056, 0x6240AB, + 0x6240B1, 0x6240BB, 0x6240CF, 0x634056, 0x734056, 0x736240, 0x754056, 0x756240, 0x784056, 0x9A4056, 0x9AB1DA, 0xABDC40, 0xB14056, 0xB16240, 0xB1DA40, 0xB1DC40, + 0xBB4056, 0xBB5640, 0xBB6240, 0xBBBD40, 0xBD4056, 0xBF4056, 0xBF5640, 0xCF56B1, 0xCFBD40, 0xDA4056, 0xDC4056, 0xDC40BB, 0xDC40CF, 0xDC6240, 0xDC7540, 0xDCBD40, +} + +var ngrams_IBM420_ar_ltr = [64]uint32{ + 0x404656, 0x4056BB, 0x4056BF, 0x406273, 0x406275, 0x4062B1, 0x4062BB, 0x4062DC, 0x406356, 0x407556, 0x4075DC, 0x40B156, 0x40BB56, 0x40BD56, 0x40BDBB, 0x40BDCF, + 0x40BDDC, 0x40DAB1, 0x40DCAB, 0x40DCB1, 0x49B156, 0x564056, 0x564058, 0x564062, 0x564063, 0x564073, 0x564075, 0x564078, 0x56409A, 0x5640B1, 0x5640BB, 0x5640BD, + 0x5640BF, 0x5640DA, 0x5640DC, 0x565840, 0x56B156, 0x56CF40, 0x58B156, 0x63B156, 0x63BD56, 0x67B156, 0x69B156, 0x73B156, 0x78B156, 0x9AB156, 0xAB4062, 0xADB156, + 0xB14062, 0xB15640, 0xB156CF, 0xB19A40, 0xB1B140, 0xBB4062, 0xBB40DC, 0xBBB156, 0xBD5640, 0xBDBB40, 0xCF4062, 0xCF40DC, 0xCFB156, 0xDAB19A, 0xDCAB40, 0xDCB156, +} + +func newRecognizer_IBM420_ar(charset string, ngram *[64]uint32) *recognizerSingleByte { + return &recognizerSingleByte{ + charset: charset, + language: "ar", + charMap: &charMap_IBM420_ar, + ngram: ngram, + } +} + +func newRecognizer_IBM420_ar_rtl() *recognizerSingleByte { + return newRecognizer_IBM420_ar("IBM420_rtl", &ngrams_IBM420_ar_rtl) +} + +func newRecognizer_IBM420_ar_ltr() *recognizerSingleByte { + return newRecognizer_IBM420_ar("IBM420_ltr", &ngrams_IBM420_ar_ltr) +} diff --git a/vendor/github.com/gogs/chardet/unicode.go b/vendor/github.com/gogs/chardet/unicode.go new file mode 100644 index 00000000..6f9fa9e6 --- /dev/null +++ b/vendor/github.com/gogs/chardet/unicode.go @@ -0,0 +1,103 @@ +package chardet + +import ( + "bytes" +) + +var ( + utf16beBom = []byte{0xFE, 0xFF} + utf16leBom = []byte{0xFF, 0xFE} + utf32beBom = []byte{0x00, 0x00, 0xFE, 0xFF} + utf32leBom = []byte{0xFF, 0xFE, 0x00, 0x00} +) + +type recognizerUtf16be struct { +} + +func newRecognizer_utf16be() *recognizerUtf16be { + return &recognizerUtf16be{} +} + +func (*recognizerUtf16be) Match(input *recognizerInput) (output recognizerOutput) { + output = recognizerOutput{ + Charset: "UTF-16BE", + } + if bytes.HasPrefix(input.raw, utf16beBom) { + output.Confidence = 100 + } + return +} + +type recognizerUtf16le struct { +} + +func newRecognizer_utf16le() *recognizerUtf16le { + return &recognizerUtf16le{} +} + +func (*recognizerUtf16le) Match(input *recognizerInput) (output recognizerOutput) { + output = recognizerOutput{ + Charset: "UTF-16LE", + } + if bytes.HasPrefix(input.raw, utf16leBom) && !bytes.HasPrefix(input.raw, utf32leBom) { + output.Confidence = 100 + } + return +} + +type recognizerUtf32 struct { + name string + bom []byte + decodeChar func(input []byte) uint32 +} + +func decodeUtf32be(input []byte) uint32 { + return uint32(input[0])<<24 | uint32(input[1])<<16 | uint32(input[2])<<8 | uint32(input[3]) +} + +func decodeUtf32le(input []byte) uint32 { + return uint32(input[3])<<24 | uint32(input[2])<<16 | uint32(input[1])<<8 | uint32(input[0]) +} + +func newRecognizer_utf32be() *recognizerUtf32 { + return &recognizerUtf32{ + "UTF-32BE", + utf32beBom, + decodeUtf32be, + } +} + +func newRecognizer_utf32le() *recognizerUtf32 { + return &recognizerUtf32{ + "UTF-32LE", + utf32leBom, + decodeUtf32le, + } +} + +func (r *recognizerUtf32) Match(input *recognizerInput) (output recognizerOutput) { + output = recognizerOutput{ + Charset: r.name, + } + hasBom := bytes.HasPrefix(input.raw, r.bom) + var numValid, numInvalid uint32 + for b := input.raw; len(b) >= 4; b = b[4:] { + if c := r.decodeChar(b); c >= 0x10FFFF || (c >= 0xD800 && c <= 0xDFFF) { + numInvalid++ + } else { + numValid++ + } + } + if hasBom && numInvalid == 0 { + output.Confidence = 100 + } else if hasBom && numValid > numInvalid*10 { + output.Confidence = 80 + } else if numValid > 3 && numInvalid == 0 { + output.Confidence = 100 + } else if numValid > 0 && numInvalid == 0 { + output.Confidence = 80 + } else if numValid > numInvalid*10 { + output.Confidence = 25 + } + return +} diff --git a/vendor/github.com/gogs/chardet/utf8.go b/vendor/github.com/gogs/chardet/utf8.go new file mode 100644 index 00000000..ae036ad9 --- /dev/null +++ b/vendor/github.com/gogs/chardet/utf8.go @@ -0,0 +1,71 @@ +package chardet + +import ( + "bytes" +) + +var utf8Bom = []byte{0xEF, 0xBB, 0xBF} + +type recognizerUtf8 struct { +} + +func newRecognizer_utf8() *recognizerUtf8 { + return &recognizerUtf8{} +} + +func (*recognizerUtf8) Match(input *recognizerInput) (output recognizerOutput) { + output = recognizerOutput{ + Charset: "UTF-8", + } + hasBom := bytes.HasPrefix(input.raw, utf8Bom) + inputLen := len(input.raw) + var numValid, numInvalid uint32 + var trailBytes uint8 + for i := 0; i < inputLen; i++ { + c := input.raw[i] + if c&0x80 == 0 { + continue + } + if c&0xE0 == 0xC0 { + trailBytes = 1 + } else if c&0xF0 == 0xE0 { + trailBytes = 2 + } else if c&0xF8 == 0xF0 { + trailBytes = 3 + } else { + numInvalid++ + if numInvalid > 5 { + break + } + trailBytes = 0 + } + + for i++; i < inputLen; i++ { + c = input.raw[i] + if c&0xC0 != 0x80 { + numInvalid++ + break + } + if trailBytes--; trailBytes == 0 { + numValid++ + break + } + } + } + + if hasBom && numInvalid == 0 { + output.Confidence = 100 + } else if hasBom && numValid > numInvalid*10 { + output.Confidence = 80 + } else if numValid > 3 && numInvalid == 0 { + output.Confidence = 100 + } else if numValid > 0 && numInvalid == 0 { + output.Confidence = 80 + } else if numValid == 0 && numInvalid == 0 { + // Plain ASCII + output.Confidence = 10 + } else if numValid > numInvalid*10 { + output.Confidence = 25 + } + return +} diff --git a/vendor/github.com/gogs/cron/LICENSE b/vendor/github.com/gogs/cron/LICENSE new file mode 100644 index 00000000..3a0f627f --- /dev/null +++ b/vendor/github.com/gogs/cron/LICENSE @@ -0,0 +1,21 @@ +Copyright (C) 2012 Rob Figueiredo +All Rights Reserved. + +MIT LICENSE + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/vendor/github.com/gogs/cron/README.md b/vendor/github.com/gogs/cron/README.md new file mode 100644 index 00000000..157ed082 --- /dev/null +++ b/vendor/github.com/gogs/cron/README.md @@ -0,0 +1,2 @@ +[![GoDoc](http://godoc.org/github.com/robfig/cron?status.png)](http://godoc.org/github.com/robfig/cron) +[![Build Status](https://travis-ci.org/robfig/cron.svg?branch=master)](https://travis-ci.org/robfig/cron) diff --git a/vendor/github.com/gogs/cron/constantdelay.go b/vendor/github.com/gogs/cron/constantdelay.go new file mode 100644 index 00000000..cd6e7b1b --- /dev/null +++ b/vendor/github.com/gogs/cron/constantdelay.go @@ -0,0 +1,27 @@ +package cron + +import "time" + +// ConstantDelaySchedule represents a simple recurring duty cycle, e.g. "Every 5 minutes". +// It does not support jobs more frequent than once a second. +type ConstantDelaySchedule struct { + Delay time.Duration +} + +// Every returns a crontab Schedule that activates once every duration. +// Delays of less than a second are not supported (will round up to 1 second). +// Any fields less than a Second are truncated. +func Every(duration time.Duration) ConstantDelaySchedule { + if duration < time.Second { + duration = time.Second + } + return ConstantDelaySchedule{ + Delay: duration - time.Duration(duration.Nanoseconds())%time.Second, + } +} + +// Next returns the next time this should be run. +// This rounds so that the next activation time will be on the second. +func (schedule ConstantDelaySchedule) Next(t time.Time) time.Time { + return t.Add(schedule.Delay - time.Duration(t.Nanosecond())*time.Nanosecond) +} diff --git a/vendor/github.com/gogs/cron/cron.go b/vendor/github.com/gogs/cron/cron.go new file mode 100644 index 00000000..ed6ad21c --- /dev/null +++ b/vendor/github.com/gogs/cron/cron.go @@ -0,0 +1,243 @@ +// This library implements a cron spec parser and runner. See the README for +// more details. +package cron + +import ( + "log" + "runtime" + "sort" + "time" +) + +// Cron keeps track of any number of entries, invoking the associated func as +// specified by the schedule. It may be started, stopped, and the entries may +// be inspected while running. +type Cron struct { + entries []*Entry + stop chan struct{} + add chan *Entry + snapshot chan []*Entry + running bool + ErrorLog *log.Logger +} + +// Job is an interface for submitted cron jobs. +type Job interface { + Run() +} + +// The Schedule describes a job's duty cycle. +type Schedule interface { + // Return the next activation time, later than the given time. + // Next is invoked initially, and then each time the job is run. + Next(time.Time) time.Time +} + +// Entry consists of a schedule and the func to execute on that schedule. +type Entry struct { + Description string + Spec string + + // The schedule on which this job should be run. + Schedule Schedule + + // The next time the job will run. This is the zero time if Cron has not been + // started or this entry's schedule is unsatisfiable + Next time.Time + + // The last time this job was run. This is the zero time if the job has never + // been run. + Prev time.Time + + // The Job to run. + Job Job + + ExecTimes int // Execute times count. +} + +// byTime is a wrapper for sorting the entry array by time +// (with zero time at the end). +type byTime []*Entry + +func (s byTime) Len() int { return len(s) } +func (s byTime) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +func (s byTime) Less(i, j int) bool { + // Two zero times should return false. + // Otherwise, zero is "greater" than any other time. + // (To sort it at the end of the list.) + if s[i].Next.IsZero() { + return false + } + if s[j].Next.IsZero() { + return true + } + return s[i].Next.Before(s[j].Next) +} + +// New returns a new Cron job runner. +func New() *Cron { + return &Cron{ + entries: nil, + add: make(chan *Entry), + stop: make(chan struct{}), + snapshot: make(chan []*Entry), + running: false, + ErrorLog: nil, + } +} + +// A wrapper that turns a func() into a cron.Job +type FuncJob func() + +func (f FuncJob) Run() { f() } + +// AddFunc adds a func to the Cron to be run on the given schedule. +func (c *Cron) AddFunc(desc, spec string, cmd func()) (*Entry, error) { + return c.AddJob(desc, spec, FuncJob(cmd)) +} + +// AddJob adds a Job to the Cron to be run on the given schedule. +func (c *Cron) AddJob(desc, spec string, cmd Job) (*Entry, error) { + schedule, err := Parse(spec) + if err != nil { + return nil, err + } + return c.Schedule(desc, spec, schedule, cmd), nil +} + +// Schedule adds a Job to the Cron to be run on the given schedule. +func (c *Cron) Schedule(desc, spec string, schedule Schedule, cmd Job) *Entry { + entry := &Entry{ + Description: desc, + Spec: spec, + Schedule: schedule, + Job: cmd, + } + if c.running { + c.add <- entry + } else { + c.entries = append(c.entries, entry) + } + return entry +} + +// Entries returns a snapshot of the cron entries. +func (c *Cron) Entries() []*Entry { + if c.running { + c.snapshot <- nil + x := <-c.snapshot + return x + } + return c.entrySnapshot() +} + +// Start the cron scheduler in its own go-routine, or no-op if already started. +func (c *Cron) Start() { + if c.running { + return + } + c.running = true + go c.run() +} + +func (c *Cron) runWithRecovery(j Job) { + defer func() { + if r := recover(); r != nil { + const size = 64 << 10 + buf := make([]byte, size) + buf = buf[:runtime.Stack(buf, false)] + c.logf("cron: panic running job: %v\n%s", r, buf) + } + }() + j.Run() +} + +// Run the scheduler.. this is private just due to the need to synchronize +// access to the 'running' state variable. +func (c *Cron) run() { + // Figure out the next activation times for each entry. + now := time.Now().Local() + for _, entry := range c.entries { + entry.Next = entry.Schedule.Next(now) + } + + for { + // Determine the next entry to run. + sort.Sort(byTime(c.entries)) + + var effective time.Time + if len(c.entries) == 0 || c.entries[0].Next.IsZero() { + // If there are no entries yet, just sleep - it still handles new entries + // and stop requests. + effective = now.AddDate(10, 0, 0) + } else { + effective = c.entries[0].Next + } + + timer := time.NewTimer(effective.Sub(now)) + select { + case now = <-timer.C: + // Run every entry whose next time was this effective time. + for _, e := range c.entries { + if e.Next != effective { + break + } + go c.runWithRecovery(e.Job) + e.ExecTimes++ + e.Prev = e.Next + e.Next = e.Schedule.Next(now) + } + continue + + case newEntry := <-c.add: + c.entries = append(c.entries, newEntry) + newEntry.Next = newEntry.Schedule.Next(time.Now().Local()) + + case <-c.snapshot: + c.snapshot <- c.entrySnapshot() + + case <-c.stop: + timer.Stop() + return + } + + // 'now' should be updated after newEntry and snapshot cases. + now = time.Now().Local() + timer.Stop() + } +} + +// Logs an error to stderr or to the configured error log +func (c *Cron) logf(format string, args ...interface{}) { + if c.ErrorLog != nil { + c.ErrorLog.Printf(format, args...) + } else { + log.Printf(format, args...) + } +} + +// Stop stops the cron scheduler if it is running; otherwise it does nothing. +func (c *Cron) Stop() { + if !c.running { + return + } + c.stop <- struct{}{} + c.running = false +} + +// entrySnapshot returns a copy of the current cron entry list. +func (c *Cron) entrySnapshot() []*Entry { + entries := []*Entry{} + for _, e := range c.entries { + entries = append(entries, &Entry{ + Description: e.Description, + Spec: e.Spec, + Schedule: e.Schedule, + Next: e.Next, + Prev: e.Prev, + Job: e.Job, + ExecTimes: e.ExecTimes, + }) + } + return entries +} diff --git a/vendor/github.com/gogs/cron/doc.go b/vendor/github.com/gogs/cron/doc.go new file mode 100644 index 00000000..dbdf5012 --- /dev/null +++ b/vendor/github.com/gogs/cron/doc.go @@ -0,0 +1,129 @@ +/* +Package cron implements a cron spec parser and job runner. + +Usage + +Callers may register Funcs to be invoked on a given schedule. Cron will run +them in their own goroutines. + + c := cron.New() + c.AddFunc("0 30 * * * *", func() { fmt.Println("Every hour on the half hour") }) + c.AddFunc("@hourly", func() { fmt.Println("Every hour") }) + c.AddFunc("@every 1h30m", func() { fmt.Println("Every hour thirty") }) + c.Start() + .. + // Funcs are invoked in their own goroutine, asynchronously. + ... + // Funcs may also be added to a running Cron + c.AddFunc("@daily", func() { fmt.Println("Every day") }) + .. + // Inspect the cron job entries' next and previous run times. + inspect(c.Entries()) + .. + c.Stop() // Stop the scheduler (does not stop any jobs already running). + +CRON Expression Format + +A cron expression represents a set of times, using 6 space-separated fields. + + Field name | Mandatory? | Allowed values | Allowed special characters + ---------- | ---------- | -------------- | -------------------------- + Seconds | Yes | 0-59 | * / , - + Minutes | Yes | 0-59 | * / , - + Hours | Yes | 0-23 | * / , - + Day of month | Yes | 1-31 | * / , - ? + Month | Yes | 1-12 or JAN-DEC | * / , - + Day of week | Yes | 0-6 or SUN-SAT | * / , - ? + +Note: Month and Day-of-week field values are case insensitive. "SUN", "Sun", +and "sun" are equally accepted. + +Special Characters + +Asterisk ( * ) + +The asterisk indicates that the cron expression will match for all values of the +field; e.g., using an asterisk in the 5th field (month) would indicate every +month. + +Slash ( / ) + +Slashes are used to describe increments of ranges. For example 3-59/15 in the +1st field (minutes) would indicate the 3rd minute of the hour and every 15 +minutes thereafter. The form "*\/..." is equivalent to the form "first-last/...", +that is, an increment over the largest possible range of the field. The form +"N/..." is accepted as meaning "N-MAX/...", that is, starting at N, use the +increment until the end of that specific range. It does not wrap around. + +Comma ( , ) + +Commas are used to separate items of a list. For example, using "MON,WED,FRI" in +the 5th field (day of week) would mean Mondays, Wednesdays and Fridays. + +Hyphen ( - ) + +Hyphens are used to define ranges. For example, 9-17 would indicate every +hour between 9am and 5pm inclusive. + +Question mark ( ? ) + +Question mark may be used instead of '*' for leaving either day-of-month or +day-of-week blank. + +Predefined schedules + +You may use one of several pre-defined schedules in place of a cron expression. + + Entry | Description | Equivalent To + ----- | ----------- | ------------- + @yearly (or @annually) | Run once a year, midnight, Jan. 1st | 0 0 0 1 1 * + @monthly | Run once a month, midnight, first of month | 0 0 0 1 * * + @weekly | Run once a week, midnight on Sunday | 0 0 0 * * 0 + @daily (or @midnight) | Run once a day, midnight | 0 0 0 * * * + @hourly | Run once an hour, beginning of hour | 0 0 * * * * + +Intervals + +You may also schedule a job to execute at fixed intervals. This is supported by +formatting the cron spec like this: + + @every + +where "duration" is a string accepted by time.ParseDuration +(http://golang.org/pkg/time/#ParseDuration). + +For example, "@every 1h30m10s" would indicate a schedule that activates every +1 hour, 30 minutes, 10 seconds. + +Note: The interval does not take the job runtime into account. For example, +if a job takes 3 minutes to run, and it is scheduled to run every 5 minutes, +it will have only 2 minutes of idle time between each run. + +Time zones + +All interpretation and scheduling is done in the machine's local time zone (as +provided by the Go time package (http://www.golang.org/pkg/time). + +Be aware that jobs scheduled during daylight-savings leap-ahead transitions will +not be run! + +Thread safety + +Since the Cron service runs concurrently with the calling code, some amount of +care must be taken to ensure proper synchronization. + +All cron methods are designed to be correctly synchronized as long as the caller +ensures that invocations have a clear happens-before ordering between them. + +Implementation + +Cron entries are stored in an array, sorted by their next activation time. Cron +sleeps until the next job is due to be run. + +Upon waking: + - it runs each entry that is active on that second + - it calculates the next run times for the jobs that were run + - it re-sorts the array of entries by next activation time. + - it goes to sleep until the soonest job. +*/ +package cron diff --git a/vendor/github.com/gogs/cron/parser.go b/vendor/github.com/gogs/cron/parser.go new file mode 100644 index 00000000..fd217c92 --- /dev/null +++ b/vendor/github.com/gogs/cron/parser.go @@ -0,0 +1,234 @@ +package cron + +import ( + "fmt" + "log" + "math" + "strconv" + "strings" + "time" +) + +// Parse returns a new crontab schedule representing the given spec. +// It returns a descriptive error if the spec is not valid. +// +// It accepts +// - Full crontab specs, e.g. "* * * * * ?" +// - Descriptors, e.g. "@midnight", "@every 1h30m" +func Parse(spec string) (_ Schedule, err error) { + // Convert panics into errors + defer func() { + if recovered := recover(); recovered != nil { + err = fmt.Errorf("%v", recovered) + } + }() + + if spec[0] == '@' { + return parseDescriptor(spec), nil + } + + // Split on whitespace. We require 5 or 6 fields. + // (second) (minute) (hour) (day of month) (month) (day of week, optional) + fields := strings.Fields(spec) + if len(fields) != 5 && len(fields) != 6 { + log.Panicf("Expected 5 or 6 fields, found %d: %s", len(fields), spec) + } + + // If a sixth field is not provided (DayOfWeek), then it is equivalent to star. + if len(fields) == 5 { + fields = append(fields, "*") + } + + schedule := &SpecSchedule{ + Second: getField(fields[0], seconds), + Minute: getField(fields[1], minutes), + Hour: getField(fields[2], hours), + Dom: getField(fields[3], dom), + Month: getField(fields[4], months), + Dow: getField(fields[5], dow), + } + + return schedule, nil +} + +// getField returns an Int with the bits set representing all of the times that +// the field represents. A "field" is a comma-separated list of "ranges". +func getField(field string, r bounds) uint64 { + // list = range {"," range} + var bits uint64 + ranges := strings.FieldsFunc(field, func(r rune) bool { return r == ',' }) + for _, expr := range ranges { + bits |= getRange(expr, r) + } + return bits +} + +// getRange returns the bits indicated by the given expression: +// number | number "-" number [ "/" number ] +func getRange(expr string, r bounds) uint64 { + + var ( + start, end, step uint + rangeAndStep = strings.Split(expr, "/") + lowAndHigh = strings.Split(rangeAndStep[0], "-") + singleDigit = len(lowAndHigh) == 1 + ) + + var extra_star uint64 + if lowAndHigh[0] == "*" || lowAndHigh[0] == "?" { + start = r.min + end = r.max + extra_star = starBit + } else { + start = parseIntOrName(lowAndHigh[0], r.names) + switch len(lowAndHigh) { + case 1: + end = start + case 2: + end = parseIntOrName(lowAndHigh[1], r.names) + default: + log.Panicf("Too many hyphens: %s", expr) + } + } + + switch len(rangeAndStep) { + case 1: + step = 1 + case 2: + step = mustParseInt(rangeAndStep[1]) + + // Special handling: "N/step" means "N-max/step". + if singleDigit { + end = r.max + } + default: + log.Panicf("Too many slashes: %s", expr) + } + + if start < r.min { + log.Panicf("Beginning of range (%d) below minimum (%d): %s", start, r.min, expr) + } + if end > r.max { + log.Panicf("End of range (%d) above maximum (%d): %s", end, r.max, expr) + } + if start > end { + log.Panicf("Beginning of range (%d) beyond end of range (%d): %s", start, end, expr) + } + if step == 0 { + log.Panicf("Step of range should be a positive number: %s", expr) + } + + return getBits(start, end, step) | extra_star +} + +// parseIntOrName returns the (possibly-named) integer contained in expr. +func parseIntOrName(expr string, names map[string]uint) uint { + if names != nil { + if namedInt, ok := names[strings.ToLower(expr)]; ok { + return namedInt + } + } + return mustParseInt(expr) +} + +// mustParseInt parses the given expression as an int or panics. +func mustParseInt(expr string) uint { + num, err := strconv.Atoi(expr) + if err != nil { + log.Panicf("Failed to parse int from %s: %s", expr, err) + } + if num < 0 { + log.Panicf("Negative number (%d) not allowed: %s", num, expr) + } + + return uint(num) +} + +// getBits sets all bits in the range [min, max], modulo the given step size. +func getBits(min, max, step uint) uint64 { + var bits uint64 + + // If step is 1, use shifts. + if step == 1 { + return ^(math.MaxUint64 << (max + 1)) & (math.MaxUint64 << min) + } + + // Else, use a simple loop. + for i := min; i <= max; i += step { + bits |= 1 << i + } + return bits +} + +// all returns all bits within the given bounds. (plus the star bit) +func all(r bounds) uint64 { + return getBits(r.min, r.max, 1) | starBit +} + +// parseDescriptor returns a pre-defined schedule for the expression, or panics +// if none matches. +func parseDescriptor(spec string) Schedule { + switch spec { + case "@yearly", "@annually": + return &SpecSchedule{ + Second: 1 << seconds.min, + Minute: 1 << minutes.min, + Hour: 1 << hours.min, + Dom: 1 << dom.min, + Month: 1 << months.min, + Dow: all(dow), + } + + case "@monthly": + return &SpecSchedule{ + Second: 1 << seconds.min, + Minute: 1 << minutes.min, + Hour: 1 << hours.min, + Dom: 1 << dom.min, + Month: all(months), + Dow: all(dow), + } + + case "@weekly": + return &SpecSchedule{ + Second: 1 << seconds.min, + Minute: 1 << minutes.min, + Hour: 1 << hours.min, + Dom: all(dom), + Month: all(months), + Dow: 1 << dow.min, + } + + case "@daily", "@midnight": + return &SpecSchedule{ + Second: 1 << seconds.min, + Minute: 1 << minutes.min, + Hour: 1 << hours.min, + Dom: all(dom), + Month: all(months), + Dow: all(dow), + } + + case "@hourly": + return &SpecSchedule{ + Second: 1 << seconds.min, + Minute: 1 << minutes.min, + Hour: all(hours), + Dom: all(dom), + Month: all(months), + Dow: all(dow), + } + } + + const every = "@every " + if strings.HasPrefix(spec, every) { + duration, err := time.ParseDuration(spec[len(every):]) + if err != nil { + log.Panicf("Failed to parse duration %s: %s", spec, err) + } + return Every(duration) + } + + log.Panicf("Unrecognized descriptor: %s", spec) + return nil +} diff --git a/vendor/github.com/gogs/cron/spec.go b/vendor/github.com/gogs/cron/spec.go new file mode 100644 index 00000000..2b541269 --- /dev/null +++ b/vendor/github.com/gogs/cron/spec.go @@ -0,0 +1,159 @@ +package cron + +import "time" + +// SpecSchedule specifies a duty cycle (to the second granularity), based on a +// traditional crontab specification. It is computed initially and stored as bit sets. +type SpecSchedule struct { + Second, Minute, Hour, Dom, Month, Dow uint64 +} + +// bounds provides a range of acceptable values (plus a map of name to value). +type bounds struct { + min, max uint + names map[string]uint +} + +// The bounds for each field. +var ( + seconds = bounds{0, 59, nil} + minutes = bounds{0, 59, nil} + hours = bounds{0, 23, nil} + dom = bounds{1, 31, nil} + months = bounds{1, 12, map[string]uint{ + "jan": 1, + "feb": 2, + "mar": 3, + "apr": 4, + "may": 5, + "jun": 6, + "jul": 7, + "aug": 8, + "sep": 9, + "oct": 10, + "nov": 11, + "dec": 12, + }} + dow = bounds{0, 6, map[string]uint{ + "sun": 0, + "mon": 1, + "tue": 2, + "wed": 3, + "thu": 4, + "fri": 5, + "sat": 6, + }} +) + +const ( + // Set the top bit if a star was included in the expression. + starBit = 1 << 63 +) + +// Next returns the next time this schedule is activated, greater than the given +// time. If no time can be found to satisfy the schedule, return the zero time. +func (s *SpecSchedule) Next(t time.Time) time.Time { + // General approach: + // For Month, Day, Hour, Minute, Second: + // Check if the time value matches. If yes, continue to the next field. + // If the field doesn't match the schedule, then increment the field until it matches. + // While incrementing the field, a wrap-around brings it back to the beginning + // of the field list (since it is necessary to re-verify previous field + // values) + + // Start at the earliest possible time (the upcoming second). + t = t.Add(1*time.Second - time.Duration(t.Nanosecond())*time.Nanosecond) + + // This flag indicates whether a field has been incremented. + added := false + + // If no time is found within five years, return zero. + yearLimit := t.Year() + 5 + +WRAP: + if t.Year() > yearLimit { + return time.Time{} + } + + // Find the first applicable month. + // If it's this month, then do nothing. + for 1< 0 + dowMatch bool = 1< 0 + ) + + if s.Dom&starBit > 0 || s.Dow&starBit > 0 { + return domMatch && dowMatch + } + return domMatch || dowMatch +} diff --git a/vendor/github.com/gogs/git-module/LICENSE b/vendor/github.com/gogs/git-module/LICENSE new file mode 100644 index 00000000..176d8dfe --- /dev/null +++ b/vendor/github.com/gogs/git-module/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2015 All Gogs Contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/vendor/github.com/gogs/git-module/README.md b/vendor/github.com/gogs/git-module/README.md new file mode 100644 index 00000000..f9569ceb --- /dev/null +++ b/vendor/github.com/gogs/git-module/README.md @@ -0,0 +1,13 @@ +# Git Module [![Build Status](https://travis-ci.org/gogits/git-module.svg?branch=master)](https://travis-ci.org/gogits/git-module) + +Package git-module is a Go module for Git access through shell commands. + +## Limitations + +- Go version must be at least **1.4**. +- Git version must be no less than **1.7.1**, and greater than or equal to **1.8.3** is recommended. +- For Windows users, try use as new a version as possible. + +## License + +This project is under the MIT License. See the [LICENSE](LICENSE) file for the full license text. diff --git a/vendor/github.com/gogs/git-module/blob.go b/vendor/github.com/gogs/git-module/blob.go new file mode 100644 index 00000000..7731226d --- /dev/null +++ b/vendor/github.com/gogs/git-module/blob.go @@ -0,0 +1,35 @@ +// Copyright 2015 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package git + +import ( + "bytes" + "io" +) + +// Blob represents a Git object. +type Blob struct { + repo *Repository + *TreeEntry +} + +// Data gets content of blob all at once and wrap it as io.Reader. +// This can be very slow and memory consuming for huge content. +func (b *Blob) Data() (io.Reader, error) { + stdout := new(bytes.Buffer) + stderr := new(bytes.Buffer) + + // Preallocate memory to save ~50% memory usage on big files. + stdout.Grow(int(b.Size() + 2048)) + + if err := b.DataPipeline(stdout, stderr); err != nil { + return nil, concatenateError(err, stderr.String()) + } + return stdout, nil +} + +func (b *Blob) DataPipeline(stdout, stderr io.Writer) error { + return NewCommand("show", b.ID.String()).RunInDirPipeline(b.repo.Path, stdout, stderr) +} diff --git a/vendor/github.com/gogs/git-module/command.go b/vendor/github.com/gogs/git-module/command.go new file mode 100644 index 00000000..80caea08 --- /dev/null +++ b/vendor/github.com/gogs/git-module/command.go @@ -0,0 +1,150 @@ +// Copyright 2015 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package git + +import ( + "bytes" + "fmt" + "io" + "os" + "os/exec" + "strings" + "time" +) + +// Command represents a command with its subcommands or arguments. +type Command struct { + name string + args []string + envs []string +} + +func (c *Command) String() string { + if len(c.args) == 0 { + return c.name + } + return fmt.Sprintf("%s %s", c.name, strings.Join(c.args, " ")) +} + +// NewCommand creates and returns a new Git Command based on given command and arguments. +func NewCommand(args ...string) *Command { + return &Command{ + name: "git", + args: args, + } +} + +// AddArguments adds new argument(s) to the command. +func (c *Command) AddArguments(args ...string) *Command { + c.args = append(c.args, args...) + return c +} + +// AddEnvs adds new environment variables to the command. +func (c *Command) AddEnvs(envs ...string) *Command { + c.envs = append(c.envs, envs...) + return c +} + +const DEFAULT_TIMEOUT = 60 * time.Second + +// RunInDirTimeoutPipeline executes the command in given directory with given timeout, +// it pipes stdout and stderr to given io.Writer. +func (c *Command) RunInDirTimeoutPipeline(timeout time.Duration, dir string, stdout, stderr io.Writer) error { + if timeout == -1 { + timeout = DEFAULT_TIMEOUT + } + + if len(dir) == 0 { + log(c.String()) + } else { + log("%s: %v", dir, c) + } + + cmd := exec.Command(c.name, c.args...) + if c.envs != nil { + cmd.Env = append(os.Environ(), c.envs...) + } + cmd.Dir = dir + cmd.Stdout = stdout + cmd.Stderr = stderr + if err := cmd.Start(); err != nil { + return err + } + + done := make(chan error) + go func() { + done <- cmd.Wait() + }() + + var err error + select { + case <-time.After(timeout): + if cmd.Process != nil && cmd.ProcessState != nil && !cmd.ProcessState.Exited() { + if err := cmd.Process.Kill(); err != nil { + return fmt.Errorf("fail to kill process: %v", err) + } + } + + <-done + return ErrExecTimeout{timeout} + case err = <-done: + } + + return err +} + +// RunInDirTimeout executes the command in given directory with given timeout, +// and returns stdout in []byte and error (combined with stderr). +func (c *Command) RunInDirTimeout(timeout time.Duration, dir string) ([]byte, error) { + stdout := new(bytes.Buffer) + stderr := new(bytes.Buffer) + if err := c.RunInDirTimeoutPipeline(timeout, dir, stdout, stderr); err != nil { + return nil, concatenateError(err, stderr.String()) + } + + if stdout.Len() > 0 { + log("stdout:\n%s", stdout.Bytes()[:1024]) + } + return stdout.Bytes(), nil +} + +// RunInDirPipeline executes the command in given directory, +// it pipes stdout and stderr to given io.Writer. +func (c *Command) RunInDirPipeline(dir string, stdout, stderr io.Writer) error { + return c.RunInDirTimeoutPipeline(-1, dir, stdout, stderr) +} + +// RunInDir executes the command in given directory +// and returns stdout in []byte and error (combined with stderr). +func (c *Command) RunInDirBytes(dir string) ([]byte, error) { + return c.RunInDirTimeout(-1, dir) +} + +// RunInDir executes the command in given directory +// and returns stdout in string and error (combined with stderr). +func (c *Command) RunInDir(dir string) (string, error) { + stdout, err := c.RunInDirTimeout(-1, dir) + if err != nil { + return "", err + } + return string(stdout), nil +} + +// RunTimeout executes the command in defualt working directory with given timeout, +// and returns stdout in string and error (combined with stderr). +func (c *Command) RunTimeout(timeout time.Duration) (string, error) { + stdout, err := c.RunInDirTimeout(timeout, "") + if err != nil { + return "", err + } + return string(stdout), nil +} + +// Run executes the command in defualt working directory +// and returns stdout in string and error (combined with stderr). +func (c *Command) Run() (string, error) { + return c.RunTimeout(-1) +} diff --git a/vendor/github.com/gogs/git-module/commit.go b/vendor/github.com/gogs/git-module/commit.go new file mode 100644 index 00000000..64831d7f --- /dev/null +++ b/vendor/github.com/gogs/git-module/commit.go @@ -0,0 +1,310 @@ +// Copyright 2015 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package git + +import ( + "bufio" + "bytes" + "container/list" + "fmt" + "io" + "net/http" + "strconv" + "strings" + + "github.com/mcuadros/go-version" +) + +// Commit represents a git commit. +type Commit struct { + Tree + ID sha1 // The ID of this commit object + Author *Signature + Committer *Signature + CommitMessage string + + parents []sha1 // SHA1 strings + submoduleCache *objectCache +} + +// Message returns the commit message. Same as retrieving CommitMessage directly. +func (c *Commit) Message() string { + return c.CommitMessage +} + +// Summary returns first line of commit message. +func (c *Commit) Summary() string { + return strings.Split(c.CommitMessage, "\n")[0] +} + +// ParentID returns oid of n-th parent (0-based index). +// It returns nil if no such parent exists. +func (c *Commit) ParentID(n int) (sha1, error) { + if n >= len(c.parents) { + return sha1{}, ErrNotExist{"", ""} + } + return c.parents[n], nil +} + +// Parent returns n-th parent (0-based index) of the commit. +func (c *Commit) Parent(n int) (*Commit, error) { + id, err := c.ParentID(n) + if err != nil { + return nil, err + } + parent, err := c.repo.getCommit(id) + if err != nil { + return nil, err + } + return parent, nil +} + +// ParentCount returns number of parents of the commit. +// 0 if this is the root commit, otherwise 1,2, etc. +func (c *Commit) ParentCount() int { + return len(c.parents) +} + +func isImageFile(data []byte) (string, bool) { + contentType := http.DetectContentType(data) + if strings.Index(contentType, "image/") != -1 { + return contentType, true + } + return contentType, false +} + +func (c *Commit) IsImageFile(name string) bool { + blob, err := c.GetBlobByPath(name) + if err != nil { + return false + } + + dataRc, err := blob.Data() + if err != nil { + return false + } + buf := make([]byte, 1024) + n, _ := dataRc.Read(buf) + buf = buf[:n] + _, isImage := isImageFile(buf) + return isImage +} + +// GetCommitByPath return the commit of relative path object. +func (c *Commit) GetCommitByPath(relpath string) (*Commit, error) { + return c.repo.getCommitByPathWithID(c.ID, relpath) +} + +// AddAllChanges marks local changes to be ready for commit. +func AddChanges(repoPath string, all bool, files ...string) error { + cmd := NewCommand("add") + if all { + cmd.AddArguments("--all") + } + _, err := cmd.AddArguments(files...).RunInDir(repoPath) + return err +} + +type CommitChangesOptions struct { + Committer *Signature + Author *Signature + Message string +} + +// CommitChanges commits local changes with given committer, author and message. +// If author is nil, it will be the same as committer. +func CommitChanges(repoPath string, opts CommitChangesOptions) error { + cmd := NewCommand() + if opts.Committer != nil { + cmd.AddEnvs("GIT_COMMITTER_NAME="+opts.Committer.Name, "GIT_COMMITTER_EMAIL="+opts.Committer.Email) + } + cmd.AddArguments("commit") + + if opts.Author == nil { + opts.Author = opts.Committer + } + if opts.Author != nil { + cmd.AddArguments(fmt.Sprintf("--author='%s <%s>'", opts.Author.Name, opts.Author.Email)) + } + cmd.AddArguments("-m", opts.Message) + + _, err := cmd.RunInDir(repoPath) + // No stderr but exit status 1 means nothing to commit. + if err != nil && err.Error() == "exit status 1" { + return nil + } + return err +} + +func commitsCount(repoPath, revision, relpath string) (int64, error) { + var cmd *Command + isFallback := false + if version.Compare(gitVersion, "1.8.0", "<") { + isFallback = true + cmd = NewCommand("log", "--pretty=format:''") + } else { + cmd = NewCommand("rev-list", "--count") + } + cmd.AddArguments(revision) + if len(relpath) > 0 { + cmd.AddArguments("--", relpath) + } + + stdout, err := cmd.RunInDir(repoPath) + if err != nil { + return 0, err + } + + if isFallback { + return int64(strings.Count(stdout, "\n")) + 1, nil + } + return strconv.ParseInt(strings.TrimSpace(stdout), 10, 64) +} + +// CommitsCount returns number of total commits of until given revision. +func CommitsCount(repoPath, revision string) (int64, error) { + return commitsCount(repoPath, revision, "") +} + +func (c *Commit) CommitsCount() (int64, error) { + return CommitsCount(c.repo.Path, c.ID.String()) +} + +func (c *Commit) CommitsByRangeSize(page, size int) (*list.List, error) { + return c.repo.CommitsByRangeSize(c.ID.String(), page, size) +} + +func (c *Commit) CommitsByRange(page int) (*list.List, error) { + return c.repo.CommitsByRange(c.ID.String(), page) +} + +func (c *Commit) CommitsBefore() (*list.List, error) { + return c.repo.getCommitsBefore(c.ID) +} + +func (c *Commit) CommitsBeforeLimit(num int) (*list.List, error) { + return c.repo.getCommitsBeforeLimit(c.ID, num) +} + +func (c *Commit) CommitsBeforeUntil(commitID string) (*list.List, error) { + endCommit, err := c.repo.GetCommit(commitID) + if err != nil { + return nil, err + } + return c.repo.CommitsBetween(c, endCommit) +} + +func (c *Commit) SearchCommits(keyword string) (*list.List, error) { + return c.repo.searchCommits(c.ID, keyword) +} + +func (c *Commit) GetFilesChangedSinceCommit(pastCommit string) ([]string, error) { + return c.repo.getFilesChanged(pastCommit, c.ID.String()) +} + +func (c *Commit) GetSubModules() (*objectCache, error) { + if c.submoduleCache != nil { + return c.submoduleCache, nil + } + + entry, err := c.GetTreeEntryByPath(".gitmodules") + if err != nil { + return nil, err + } + rd, err := entry.Blob().Data() + if err != nil { + return nil, err + } + + scanner := bufio.NewScanner(rd) + c.submoduleCache = newObjectCache() + var ismodule bool + var path string + for scanner.Scan() { + if strings.HasPrefix(scanner.Text(), "[submodule") { + ismodule = true + continue + } + if ismodule { + fields := strings.Split(scanner.Text(), "=") + k := strings.TrimSpace(fields[0]) + if k == "path" { + path = strings.TrimSpace(fields[1]) + } else if k == "url" { + c.submoduleCache.Set(path, &SubModule{path, strings.TrimSpace(fields[1])}) + ismodule = false + } + } + } + + return c.submoduleCache, nil +} + +func (c *Commit) GetSubModule(entryname string) (*SubModule, error) { + modules, err := c.GetSubModules() + if err != nil { + return nil, err + } + + module, has := modules.Get(entryname) + if has { + return module.(*SubModule), nil + } + return nil, nil +} + +// CommitFileStatus represents status of files in a commit. +type CommitFileStatus struct { + Added []string + Removed []string + Modified []string +} + +func NewCommitFileStatus() *CommitFileStatus { + return &CommitFileStatus{ + []string{}, []string{}, []string{}, + } +} + +// GetCommitFileStatus returns file status of commit in given repository. +func GetCommitFileStatus(repoPath, commitID string) (*CommitFileStatus, error) { + stdout, w := io.Pipe() + done := make(chan struct{}) + fileStatus := NewCommitFileStatus() + go func() { + scanner := bufio.NewScanner(stdout) + for scanner.Scan() { + fields := strings.Fields(scanner.Text()) + if len(fields) < 2 { + continue + } + + switch fields[0][0] { + case 'A': + fileStatus.Added = append(fileStatus.Added, fields[1]) + case 'D': + fileStatus.Removed = append(fileStatus.Removed, fields[1]) + case 'M': + fileStatus.Modified = append(fileStatus.Modified, fields[1]) + } + } + done <- struct{}{} + }() + + stderr := new(bytes.Buffer) + err := NewCommand("log", "-1", "--name-status", "--pretty=format:''", commitID).RunInDirPipeline(repoPath, w, stderr) + w.Close() // Close writer to exit parsing goroutine + if err != nil { + return nil, concatenateError(err, stderr.String()) + } + + <-done + return fileStatus, nil +} + +// FileStatus returns file status of commit. +func (c *Commit) FileStatus() (*CommitFileStatus, error) { + return GetCommitFileStatus(c.repo.Path, c.ID.String()) +} diff --git a/vendor/github.com/gogs/git-module/commit_archive.go b/vendor/github.com/gogs/git-module/commit_archive.go new file mode 100644 index 00000000..1066ba69 --- /dev/null +++ b/vendor/github.com/gogs/git-module/commit_archive.go @@ -0,0 +1,33 @@ +// Copyright 2015 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package git + +import ( + "fmt" + "path/filepath" + "strings" +) + +type ArchiveType int + +const ( + ZIP ArchiveType = iota + 1 + TARGZ +) + +func (c *Commit) CreateArchive(target string, archiveType ArchiveType) error { + var format string + switch archiveType { + case ZIP: + format = "zip" + case TARGZ: + format = "tar.gz" + default: + return fmt.Errorf("unknown format: %v", archiveType) + } + + _, err := NewCommand("archive", "--prefix="+filepath.Base(strings.TrimSuffix(c.repo.Path, ".git"))+"/", "--format="+format, "-o", target, c.ID.String()).RunInDir(c.repo.Path) + return err +} diff --git a/vendor/github.com/gogs/git-module/error.go b/vendor/github.com/gogs/git-module/error.go new file mode 100644 index 00000000..2fefaa1e --- /dev/null +++ b/vendor/github.com/gogs/git-module/error.go @@ -0,0 +1,61 @@ +// Copyright 2015 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package git + +import ( + "fmt" + "time" +) + +type ErrExecTimeout struct { + Duration time.Duration +} + +func IsErrExecTimeout(err error) bool { + _, ok := err.(ErrExecTimeout) + return ok +} + +func (err ErrExecTimeout) Error() string { + return fmt.Sprintf("execution is timeout [duration: %v]", err.Duration) +} + +type ErrNotExist struct { + ID string + RelPath string +} + +func IsErrNotExist(err error) bool { + _, ok := err.(ErrNotExist) + return ok +} + +func (err ErrNotExist) Error() string { + return fmt.Sprintf("object does not exist [id: %s, rel_path: %s]", err.ID, err.RelPath) +} + +type ErrUnsupportedVersion struct { + Required string +} + +func IsErrUnsupportedVersion(err error) bool { + _, ok := err.(ErrUnsupportedVersion) + return ok +} + +func (err ErrUnsupportedVersion) Error() string { + return fmt.Sprintf("Operation requires higher version [required: %s]", err.Required) +} + +type ErrNoMergeBase struct{} + +func IsErrNoMergeBase(err error) bool { + _, ok := err.(ErrNoMergeBase) + return ok +} + +func (err ErrNoMergeBase) Error() string { + return "no merge based found" +} diff --git a/vendor/github.com/gogs/git-module/git.go b/vendor/github.com/gogs/git-module/git.go new file mode 100644 index 00000000..414d67cd --- /dev/null +++ b/vendor/github.com/gogs/git-module/git.go @@ -0,0 +1,80 @@ +// Copyright 2015 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package git + +import ( + "fmt" + "strings" + "time" +) + +const _VERSION = "0.6.4" + +func Version() string { + return _VERSION +} + +var ( + // Debug enables verbose logging on everything. + // This should be false in case Gogs starts in SSH mode. + Debug = false + Prefix = "[git-module] " +) + +func log(format string, args ...interface{}) { + if !Debug { + return + } + + fmt.Print(Prefix) + if len(args) == 0 { + fmt.Println(format) + } else { + fmt.Printf(format+"\n", args...) + } +} + +var gitVersion string + +// Version returns current Git version from shell. +func BinVersion() (string, error) { + if len(gitVersion) > 0 { + return gitVersion, nil + } + + stdout, err := NewCommand("version").Run() + if err != nil { + return "", err + } + + fields := strings.Fields(stdout) + if len(fields) < 3 { + return "", fmt.Errorf("not enough output: %s", stdout) + } + + // Handle special case on Windows. + i := strings.Index(fields[2], "windows") + if i >= 1 { + gitVersion = fields[2][:i-1] + return gitVersion, nil + } + + gitVersion = fields[2] + return gitVersion, nil +} + +func init() { + BinVersion() +} + +// Fsck verifies the connectivity and validity of the objects in the database +func Fsck(repoPath string, timeout time.Duration, args ...string) error { + // Make sure timeout makes sense. + if timeout <= 0 { + timeout = -1 + } + _, err := NewCommand("fsck").AddArguments(args...).RunInDirTimeout(timeout, repoPath) + return err +} diff --git a/vendor/github.com/gogs/git-module/hook.go b/vendor/github.com/gogs/git-module/hook.go new file mode 100644 index 00000000..a0d0b16b --- /dev/null +++ b/vendor/github.com/gogs/git-module/hook.go @@ -0,0 +1,111 @@ +// Copyright 2015 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package git + +import ( + "errors" + "io/ioutil" + "os" + "path" + "strings" +) + +var ( + // Direcotry of hook and sample files. Can be changed to "custom_hooks" for very purpose. + HookDir = "hooks" + HookSampleDir = HookDir + // HookNames is a list of Git server hooks' name that are supported. + HookNames = []string{ + "pre-receive", + "update", + "post-receive", + } +) + +var ( + ErrNotValidHook = errors.New("not a valid Git hook") +) + +// IsValidHookName returns true if given name is a valid Git hook. +func IsValidHookName(name string) bool { + for _, hn := range HookNames { + if hn == name { + return true + } + } + return false +} + +// Hook represents a Git hook. +type Hook struct { + name string + IsActive bool // Indicates whether repository has this hook. + Content string // Content of hook if it's active. + Sample string // Sample content from Git. + path string // Hook file path. +} + +// GetHook returns a Git hook by given name and repository. +func GetHook(repoPath, name string) (*Hook, error) { + if !IsValidHookName(name) { + return nil, ErrNotValidHook + } + h := &Hook{ + name: name, + path: path.Join(repoPath, HookDir, name), + } + if isFile(h.path) { + data, err := ioutil.ReadFile(h.path) + if err != nil { + return nil, err + } + h.IsActive = true + h.Content = string(data) + return h, nil + } + + // Check sample file + samplePath := path.Join(repoPath, HookSampleDir, h.name) + ".sample" + if isFile(samplePath) { + data, err := ioutil.ReadFile(samplePath) + if err != nil { + return nil, err + } + h.Sample = string(data) + } + return h, nil +} + +func (h *Hook) Name() string { + return h.name +} + +// Update updates content hook file. +func (h *Hook) Update() error { + if len(strings.TrimSpace(h.Content)) == 0 { + if isExist(h.path) { + return os.Remove(h.path) + } + return nil + } + os.MkdirAll(path.Dir(h.path), os.ModePerm) + return ioutil.WriteFile(h.path, []byte(strings.Replace(h.Content, "\r", "", -1)), os.ModePerm) +} + +// ListHooks returns a list of Git hooks of given repository. +func ListHooks(repoPath string) (_ []*Hook, err error) { + if !isDir(path.Join(repoPath, "hooks")) { + return nil, errors.New("hooks path does not exist") + } + + hooks := make([]*Hook, len(HookNames)) + for i, name := range HookNames { + hooks[i], err = GetHook(repoPath, name) + if err != nil { + return nil, err + } + } + return hooks, nil +} diff --git a/vendor/github.com/gogs/git-module/repo.go b/vendor/github.com/gogs/git-module/repo.go new file mode 100644 index 00000000..ca4805f5 --- /dev/null +++ b/vendor/github.com/gogs/git-module/repo.go @@ -0,0 +1,295 @@ +// Copyright 2015 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package git + +import ( + "bytes" + "container/list" + "errors" + "os" + "path" + "path/filepath" + "strings" + "time" + + "github.com/Unknwon/com" +) + +// Repository represents a Git repository. +type Repository struct { + Path string + + commitCache *objectCache + tagCache *objectCache +} + +const _PRETTY_LOG_FORMAT = `--pretty=format:%H` + +func (repo *Repository) parsePrettyFormatLogToList(logs []byte) (*list.List, error) { + l := list.New() + if len(logs) == 0 { + return l, nil + } + + parts := bytes.Split(logs, []byte{'\n'}) + + for _, commitId := range parts { + commit, err := repo.GetCommit(string(commitId)) + if err != nil { + return nil, err + } + l.PushBack(commit) + } + + return l, nil +} + +type NetworkOptions struct { + URL string + Timeout time.Duration +} + +// IsRepoURLAccessible checks if given repository URL is accessible. +func IsRepoURLAccessible(opts NetworkOptions) bool { + cmd := NewCommand("ls-remote", "-q", "-h", opts.URL, "HEAD") + if opts.Timeout <= 0 { + opts.Timeout = -1 + } + _, err := cmd.RunTimeout(opts.Timeout) + if err != nil { + return false + } + return true +} + +// InitRepository initializes a new Git repository. +func InitRepository(repoPath string, bare bool) error { + os.MkdirAll(repoPath, os.ModePerm) + + cmd := NewCommand("init") + if bare { + cmd.AddArguments("--bare") + } + _, err := cmd.RunInDir(repoPath) + return err +} + +// OpenRepository opens the repository at the given path. +func OpenRepository(repoPath string) (*Repository, error) { + repoPath, err := filepath.Abs(repoPath) + if err != nil { + return nil, err + } else if !isDir(repoPath) { + return nil, errors.New("no such file or directory") + } + + return &Repository{ + Path: repoPath, + commitCache: newObjectCache(), + tagCache: newObjectCache(), + }, nil +} + +type CloneRepoOptions struct { + Mirror bool + Bare bool + Quiet bool + Branch string + Timeout time.Duration +} + +// Clone clones original repository to target path. +func Clone(from, to string, opts CloneRepoOptions) (err error) { + toDir := path.Dir(to) + if err = os.MkdirAll(toDir, os.ModePerm); err != nil { + return err + } + + cmd := NewCommand("clone") + if opts.Mirror { + cmd.AddArguments("--mirror") + } + if opts.Bare { + cmd.AddArguments("--bare") + } + if opts.Quiet { + cmd.AddArguments("--quiet") + } + if len(opts.Branch) > 0 { + cmd.AddArguments("-b", opts.Branch) + } + cmd.AddArguments(from, to) + + if opts.Timeout <= 0 { + opts.Timeout = -1 + } + _, err = cmd.RunTimeout(opts.Timeout) + return err +} + +type FetchRemoteOptions struct { + Prune bool + Timeout time.Duration +} + +// Fetch fetches changes from remotes without merging. +func Fetch(repoPath string, opts FetchRemoteOptions) error { + cmd := NewCommand("fetch") + if opts.Prune { + cmd.AddArguments("--prune") + } + + if opts.Timeout <= 0 { + opts.Timeout = -1 + } + _, err := cmd.RunInDirTimeout(opts.Timeout, repoPath) + return err +} + +type PullRemoteOptions struct { + All bool + Rebase bool + Remote string + Branch string + Timeout time.Duration +} + +// Pull pulls changes from remotes. +func Pull(repoPath string, opts PullRemoteOptions) error { + cmd := NewCommand("pull") + if opts.Rebase { + cmd.AddArguments("--rebase") + } + if opts.All { + cmd.AddArguments("--all") + } else { + cmd.AddArguments(opts.Remote) + cmd.AddArguments(opts.Branch) + } + + if opts.Timeout <= 0 { + opts.Timeout = -1 + } + _, err := cmd.RunInDirTimeout(opts.Timeout, repoPath) + return err +} + +// Push pushs local commits to given remote branch. +func Push(repoPath, remote, branch string) error { + _, err := NewCommand("push", remote, branch).RunInDir(repoPath) + return err +} + +type CheckoutOptions struct { + Branch string + OldBranch string + Timeout time.Duration +} + +// Checkout checkouts a branch +func Checkout(repoPath string, opts CheckoutOptions) error { + cmd := NewCommand("checkout") + if len(opts.OldBranch) > 0 { + cmd.AddArguments("-b") + } + + cmd.AddArguments(opts.Branch) + + if len(opts.OldBranch) > 0 { + cmd.AddArguments(opts.OldBranch) + } + if opts.Timeout <= 0 { + opts.Timeout = -1 + } + _, err := cmd.RunInDirTimeout(opts.Timeout, repoPath) + return err +} + +// ResetHEAD resets HEAD to given revision or head of branch. +func ResetHEAD(repoPath string, hard bool, revision string) error { + cmd := NewCommand("reset") + if hard { + cmd.AddArguments("--hard") + } + _, err := cmd.AddArguments(revision).RunInDir(repoPath) + return err +} + +// MoveFile moves a file to another file or directory. +func MoveFile(repoPath, oldTreeName, newTreeName string) error { + _, err := NewCommand("mv").AddArguments(oldTreeName, newTreeName).RunInDir(repoPath) + return err +} + +// CountObject represents disk usage report of Git repository. +type CountObject struct { + Count int64 + Size int64 + InPack int64 + Packs int64 + SizePack int64 + PrunePackable int64 + Garbage int64 + SizeGarbage int64 +} + +const ( + _STAT_COUNT = "count: " + _STAT_SIZE = "size: " + _STAT_IN_PACK = "in-pack: " + _STAT_PACKS = "packs: " + _STAT_SIZE_PACK = "size-pack: " + _STAT_PRUNE_PACKABLE = "prune-packable: " + _STAT_GARBAGE = "garbage: " + _STAT_SIZE_GARBAGE = "size-garbage: " +) + +// GetRepoSize returns disk usage report of repository in given path. +func GetRepoSize(repoPath string) (*CountObject, error) { + cmd := NewCommand("count-objects", "-v") + stdout, err := cmd.RunInDir(repoPath) + if err != nil { + return nil, err + } + + countObject := new(CountObject) + for _, line := range strings.Split(stdout, "\n") { + switch { + case strings.HasPrefix(line, _STAT_COUNT): + countObject.Count = com.StrTo(line[7:]).MustInt64() + case strings.HasPrefix(line, _STAT_SIZE): + countObject.Size = com.StrTo(line[6:]).MustInt64() * 1024 + case strings.HasPrefix(line, _STAT_IN_PACK): + countObject.InPack = com.StrTo(line[9:]).MustInt64() + case strings.HasPrefix(line, _STAT_PACKS): + countObject.Packs = com.StrTo(line[7:]).MustInt64() + case strings.HasPrefix(line, _STAT_SIZE_PACK): + countObject.SizePack = com.StrTo(line[11:]).MustInt64() * 1024 + case strings.HasPrefix(line, _STAT_PRUNE_PACKABLE): + countObject.PrunePackable = com.StrTo(line[16:]).MustInt64() + case strings.HasPrefix(line, _STAT_GARBAGE): + countObject.Garbage = com.StrTo(line[9:]).MustInt64() + case strings.HasPrefix(line, _STAT_SIZE_GARBAGE): + countObject.SizeGarbage = com.StrTo(line[14:]).MustInt64() * 1024 + } + } + + return countObject, nil +} + +// GetLatestCommitDate returns the date of latest commit of repository. +// If branch is empty, it returns the latest commit across all branches. +func GetLatestCommitDate(repoPath, branch string) (time.Time, error) { + cmd := NewCommand("for-each-ref", "--count=1", "--sort=-committerdate", "--format=%(committerdate:iso8601)") + if len(branch) > 0 { + cmd.AddArguments("refs/heads/" + branch) + } + stdout, err := cmd.RunInDir(repoPath) + if err != nil { + return time.Time{}, err + } + + return time.Parse("2006-01-02 15:04:05 -0700", strings.TrimSpace(stdout)) +} diff --git a/vendor/github.com/gogs/git-module/repo_branch.go b/vendor/github.com/gogs/git-module/repo_branch.go new file mode 100644 index 00000000..de3f6ca1 --- /dev/null +++ b/vendor/github.com/gogs/git-module/repo_branch.go @@ -0,0 +1,126 @@ +// Copyright 2015 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package git + +import ( + "fmt" + "strings" + + "github.com/mcuadros/go-version" +) + +const BRANCH_PREFIX = "refs/heads/" + +// IsReferenceExist returns true if given reference exists in the repository. +func IsReferenceExist(repoPath, name string) bool { + _, err := NewCommand("show-ref", "--verify", name).RunInDir(repoPath) + return err == nil +} + +// IsBranchExist returns true if given branch exists in the repository. +func IsBranchExist(repoPath, name string) bool { + return IsReferenceExist(repoPath, BRANCH_PREFIX+name) +} + +func (repo *Repository) IsBranchExist(name string) bool { + return IsBranchExist(repo.Path, name) +} + +// Branch represents a Git branch. +type Branch struct { + Name string + Path string +} + +// GetHEADBranch returns corresponding branch of HEAD. +func (repo *Repository) GetHEADBranch() (*Branch, error) { + stdout, err := NewCommand("symbolic-ref", "HEAD").RunInDir(repo.Path) + if err != nil { + return nil, err + } + stdout = strings.TrimSpace(stdout) + + if !strings.HasPrefix(stdout, BRANCH_PREFIX) { + return nil, fmt.Errorf("invalid HEAD branch: %v", stdout) + } + + return &Branch{ + Name: stdout[len(BRANCH_PREFIX):], + Path: stdout, + }, nil +} + +// SetDefaultBranch sets default branch of repository. +func (repo *Repository) SetDefaultBranch(name string) error { + if version.Compare(gitVersion, "1.7.10", "<") { + return ErrUnsupportedVersion{"1.7.10"} + } + + _, err := NewCommand("symbolic-ref", "HEAD", BRANCH_PREFIX+name).RunInDir(repo.Path) + return err +} + +// GetBranches returns all branches of the repository. +func (repo *Repository) GetBranches() ([]string, error) { + stdout, err := NewCommand("show-ref", "--heads").RunInDir(repo.Path) + if err != nil { + return nil, err + } + + infos := strings.Split(stdout, "\n") + branches := make([]string, len(infos)-1) + for i, info := range infos[:len(infos)-1] { + fields := strings.Fields(info) + if len(fields) != 2 { + continue // NOTE: I should believe git will not give me wrong string. + } + branches[i] = strings.TrimPrefix(fields[1], BRANCH_PREFIX) + } + return branches, nil +} + +// Option(s) for delete branch +type DeleteBranchOptions struct { + Force bool +} + +// DeleteBranch deletes a branch from given repository path. +func DeleteBranch(repoPath, name string, opts DeleteBranchOptions) error { + cmd := NewCommand("branch") + + if opts.Force { + cmd.AddArguments("-D") + } else { + cmd.AddArguments("-d") + } + + cmd.AddArguments(name) + _, err := cmd.RunInDir(repoPath) + + return err +} + +// DeleteBranch deletes a branch from repository. +func (repo *Repository) DeleteBranch(name string, opts DeleteBranchOptions) error { + return DeleteBranch(repo.Path, name, opts) +} + +// AddRemote adds a new remote to repository. +func (repo *Repository) AddRemote(name, url string, fetch bool) error { + cmd := NewCommand("remote", "add") + if fetch { + cmd.AddArguments("-f") + } + cmd.AddArguments(name, url) + + _, err := cmd.RunInDir(repo.Path) + return err +} + +// RemoveRemote removes a remote from repository. +func (repo *Repository) RemoveRemote(name string) error { + _, err := NewCommand("remote", "remove", name).RunInDir(repo.Path) + return err +} diff --git a/vendor/github.com/gogs/git-module/repo_commit.go b/vendor/github.com/gogs/git-module/repo_commit.go new file mode 100644 index 00000000..6b629d4d --- /dev/null +++ b/vendor/github.com/gogs/git-module/repo_commit.go @@ -0,0 +1,381 @@ +// Copyright 2015 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package git + +import ( + "bytes" + "container/list" + "fmt" + "strconv" + "strings" + + "github.com/mcuadros/go-version" +) + +const REMOTE_PREFIX = "refs/remotes/" + +// getRefCommitID returns the last commit ID string of given reference (branch or tag). +func (repo *Repository) getRefCommitID(name string) (string, error) { + stdout, err := NewCommand("show-ref", "--verify", name).RunInDir(repo.Path) + if err != nil { + if strings.Contains(err.Error(), "not a valid ref") { + return "", ErrNotExist{name, ""} + } + return "", err + } + return strings.Split(stdout, " ")[0], nil +} + +// GetBranchCommitID returns last commit ID string of given branch. +func (repo *Repository) GetBranchCommitID(name string) (string, error) { + return repo.getRefCommitID(BRANCH_PREFIX + name) +} + +// GetTagCommitID returns last commit ID string of given tag. +func (repo *Repository) GetTagCommitID(name string) (string, error) { + return repo.getRefCommitID(TAG_PREFIX + name) +} + +// GetRemoteBranchCommitID returns last commit ID string of given remote branch. +func (repo *Repository) GetRemoteBranchCommitID(name string) (string, error) { + return repo.getRefCommitID(REMOTE_PREFIX + name) +} + +// parseCommitData parses commit information from the (uncompressed) raw +// data from the commit object. +// \n\n separate headers from message +func parseCommitData(data []byte) (*Commit, error) { + commit := new(Commit) + commit.parents = make([]sha1, 0, 1) + // we now have the contents of the commit object. Let's investigate... + nextline := 0 +l: + for { + eol := bytes.IndexByte(data[nextline:], '\n') + switch { + case eol > 0: + line := data[nextline : nextline+eol] + spacepos := bytes.IndexByte(line, ' ') + reftype := line[:spacepos] + switch string(reftype) { + case "tree", "object": + id, err := NewIDFromString(string(line[spacepos+1:])) + if err != nil { + return nil, err + } + commit.Tree.ID = id + case "parent": + // A commit can have one or more parents + oid, err := NewIDFromString(string(line[spacepos+1:])) + if err != nil { + return nil, err + } + commit.parents = append(commit.parents, oid) + case "author", "tagger": + sig, err := newSignatureFromCommitline(line[spacepos+1:]) + if err != nil { + return nil, err + } + commit.Author = sig + case "committer": + sig, err := newSignatureFromCommitline(line[spacepos+1:]) + if err != nil { + return nil, err + } + commit.Committer = sig + } + nextline += eol + 1 + case eol == 0: + commit.CommitMessage = string(data[nextline+1:]) + break l + default: + break l + } + } + return commit, nil +} + +func (repo *Repository) getCommit(id sha1) (*Commit, error) { + c, ok := repo.commitCache.Get(id.String()) + if ok { + log("Hit cache: %s", id) + return c.(*Commit), nil + } + + data, err := NewCommand("cat-file", "commit", id.String()).RunInDirBytes(repo.Path) + if err != nil { + if strings.Contains(err.Error(), "exit status 128") { + return nil, ErrNotExist{id.String(), ""} + } + return nil, err + } + + commit, err := parseCommitData(data) + if err != nil { + return nil, err + } + commit.repo = repo + commit.ID = id + + repo.commitCache.Set(id.String(), commit) + return commit, nil +} + +// GetCommit returns commit object of by ID string. +func (repo *Repository) GetCommit(commitID string) (*Commit, error) { + if len(commitID) != 40 { + var err error + commitID, err = NewCommand("rev-parse", commitID).RunInDir(repo.Path) + if err != nil { + if strings.Contains(err.Error(), "exit status 128") { + return nil, ErrNotExist{commitID, ""} + } + return nil, err + } + } + id, err := NewIDFromString(commitID) + if err != nil { + return nil, err + } + + return repo.getCommit(id) +} + +// GetBranchCommit returns the last commit of given branch. +func (repo *Repository) GetBranchCommit(name string) (*Commit, error) { + commitID, err := repo.GetBranchCommitID(name) + if err != nil { + return nil, err + } + return repo.GetCommit(commitID) +} + +// GetTagCommit returns the commit of given tag. +func (repo *Repository) GetTagCommit(name string) (*Commit, error) { + commitID, err := repo.GetTagCommitID(name) + if err != nil { + return nil, err + } + return repo.GetCommit(commitID) +} + +// GetRemoteBranchCommit returns the last commit of given remote branch. +func (repo *Repository) GetRemoteBranchCommit(name string) (*Commit, error) { + commitID, err := repo.GetRemoteBranchCommitID(name) + if err != nil { + return nil, err + } + return repo.GetCommit(commitID) +} + +func (repo *Repository) getCommitByPathWithID(id sha1, relpath string) (*Commit, error) { + // File name starts with ':' must be escaped. + if relpath[0] == ':' { + relpath = `\` + relpath + } + + stdout, err := NewCommand("log", "-1", _PRETTY_LOG_FORMAT, id.String(), "--", relpath).RunInDir(repo.Path) + if err != nil { + return nil, err + } + + id, err = NewIDFromString(stdout) + if err != nil { + return nil, err + } + + return repo.getCommit(id) +} + +// GetCommitByPath returns the last commit of relative path. +func (repo *Repository) GetCommitByPath(relpath string) (*Commit, error) { + stdout, err := NewCommand("log", "-1", _PRETTY_LOG_FORMAT, "--", relpath).RunInDirBytes(repo.Path) + if err != nil { + return nil, err + } + + commits, err := repo.parsePrettyFormatLogToList(stdout) + if err != nil { + return nil, err + } + return commits.Front().Value.(*Commit), nil +} + +func (repo *Repository) CommitsByRangeSize(revision string, page, size int) (*list.List, error) { + stdout, err := NewCommand("log", revision, "--skip="+strconv.Itoa((page-1)*size), + "--max-count="+strconv.Itoa(size), _PRETTY_LOG_FORMAT).RunInDirBytes(repo.Path) + if err != nil { + return nil, err + } + return repo.parsePrettyFormatLogToList(stdout) +} + +var DefaultCommitsPageSize = 30 + +func (repo *Repository) CommitsByRange(revision string, page int) (*list.List, error) { + return repo.CommitsByRangeSize(revision, page, DefaultCommitsPageSize) +} + +func (repo *Repository) searchCommits(id sha1, keyword string) (*list.List, error) { + stdout, err := NewCommand("log", id.String(), "-100", "-i", "--grep="+keyword, _PRETTY_LOG_FORMAT).RunInDirBytes(repo.Path) + if err != nil { + return nil, err + } + return repo.parsePrettyFormatLogToList(stdout) +} + +func (repo *Repository) getFilesChanged(id1 string, id2 string) ([]string, error) { + stdout, err := NewCommand("diff", "--name-only", id1, id2).RunInDirBytes(repo.Path) + if err != nil { + return nil, err + } + return strings.Split(string(stdout), "\n"), nil +} + +func (repo *Repository) FileCommitsCount(revision, file string) (int64, error) { + return commitsCount(repo.Path, revision, file) +} + +func (repo *Repository) CommitsByFileAndRangeSize(revision, file string, page, size int) (*list.List, error) { + stdout, err := NewCommand("log", revision, "--skip="+strconv.Itoa((page-1)*size), + "--max-count="+strconv.Itoa(size), _PRETTY_LOG_FORMAT, "--", file).RunInDirBytes(repo.Path) + if err != nil { + return nil, err + } + return repo.parsePrettyFormatLogToList(stdout) +} + +func (repo *Repository) CommitsByFileAndRange(revision, file string, page int) (*list.List, error) { + return repo.CommitsByFileAndRangeSize(revision, file, page, DefaultCommitsPageSize) +} + +func (repo *Repository) FilesCountBetween(startCommitID, endCommitID string) (int, error) { + stdout, err := NewCommand("diff", "--name-only", startCommitID+"..."+endCommitID).RunInDir(repo.Path) + if err != nil { + return 0, err + } + return len(strings.Split(stdout, "\n")) - 1, nil +} + +// CommitsBetween returns a list that contains commits between [last, before). +func (repo *Repository) CommitsBetween(last *Commit, before *Commit) (*list.List, error) { + if version.Compare(gitVersion, "1.8.0", ">=") { + stdout, err := NewCommand("rev-list", before.ID.String()+"..."+last.ID.String()).RunInDirBytes(repo.Path) + if err != nil { + return nil, err + } + return repo.parsePrettyFormatLogToList(bytes.TrimSpace(stdout)) + } + + // Fallback to stupid solution, which iterates all commits of the repository + // if before is not an ancestor of last. + l := list.New() + if last == nil || last.ParentCount() == 0 { + return l, nil + } + + var err error + cur := last + for { + if cur.ID.Equal(before.ID) { + break + } + l.PushBack(cur) + if cur.ParentCount() == 0 { + break + } + cur, err = cur.Parent(0) + if err != nil { + return nil, err + } + } + return l, nil +} + +func (repo *Repository) CommitsBetweenIDs(last, before string) (*list.List, error) { + lastCommit, err := repo.GetCommit(last) + if err != nil { + return nil, err + } + beforeCommit, err := repo.GetCommit(before) + if err != nil { + return nil, err + } + return repo.CommitsBetween(lastCommit, beforeCommit) +} + +func (repo *Repository) CommitsCountBetween(start, end string) (int64, error) { + return commitsCount(repo.Path, start+"..."+end, "") +} + +// The limit is depth, not total number of returned commits. +func (repo *Repository) commitsBefore(l *list.List, parent *list.Element, id sha1, current, limit int) error { + // Reach the limit + if limit > 0 && current > limit { + return nil + } + + commit, err := repo.getCommit(id) + if err != nil { + return fmt.Errorf("getCommit: %v", err) + } + + var e *list.Element + if parent == nil { + e = l.PushBack(commit) + } else { + var in = parent + for { + if in == nil { + break + } else if in.Value.(*Commit).ID.Equal(commit.ID) { + return nil + } else if in.Next() == nil { + break + } + + if in.Value.(*Commit).Committer.When.Equal(commit.Committer.When) { + break + } + + if in.Value.(*Commit).Committer.When.After(commit.Committer.When) && + in.Next().Value.(*Commit).Committer.When.Before(commit.Committer.When) { + break + } + + in = in.Next() + } + + e = l.InsertAfter(commit, in) + } + + pr := parent + if commit.ParentCount() > 1 { + pr = e + } + + for i := 0; i < commit.ParentCount(); i++ { + id, err := commit.ParentID(i) + if err != nil { + return err + } + err = repo.commitsBefore(l, pr, id, current+1, limit) + if err != nil { + return err + } + } + + return nil +} + +func (repo *Repository) getCommitsBefore(id sha1) (*list.List, error) { + l := list.New() + return l, repo.commitsBefore(l, nil, id, 1, 0) +} + +func (repo *Repository) getCommitsBeforeLimit(id sha1, num int) (*list.List, error) { + l := list.New() + return l, repo.commitsBefore(l, nil, id, 1, num) +} diff --git a/vendor/github.com/gogs/git-module/repo_diff.go b/vendor/github.com/gogs/git-module/repo_diff.go new file mode 100644 index 00000000..258a166f --- /dev/null +++ b/vendor/github.com/gogs/git-module/repo_diff.go @@ -0,0 +1,400 @@ +// Copyright 2017 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package git + +import ( + "bufio" + "bytes" + "fmt" + "io" + "io/ioutil" + "strconv" + "strings" + "time" +) + +// DiffLineType represents the type of a line in diff. +type DiffLineType uint8 + +const ( + DIFF_LINE_PLAIN DiffLineType = iota + 1 + DIFF_LINE_ADD + DIFF_LINE_DEL + DIFF_LINE_SECTION +) + +// DiffFileType represents the file status in diff. +type DiffFileType uint8 + +const ( + DIFF_FILE_ADD DiffFileType = iota + 1 + DIFF_FILE_CHANGE + DIFF_FILE_DEL + DIFF_FILE_RENAME +) + +// DiffLine represents a line in diff. +type DiffLine struct { + LeftIdx int + RightIdx int + Type DiffLineType + Content string +} + +func (d *DiffLine) GetType() int { + return int(d.Type) +} + +// DiffSection represents a section in diff. +type DiffSection struct { + Name string + Lines []*DiffLine +} + +// Line returns a specific line by type (add or del) and file line number from a section. +func (diffSection *DiffSection) Line(lineType DiffLineType, idx int) *DiffLine { + var ( + difference = 0 + addCount = 0 + delCount = 0 + matchDiffLine *DiffLine + ) + +LOOP: + for _, diffLine := range diffSection.Lines { + switch diffLine.Type { + case DIFF_LINE_ADD: + addCount++ + case DIFF_LINE_DEL: + delCount++ + default: + if matchDiffLine != nil { + break LOOP + } + difference = diffLine.RightIdx - diffLine.LeftIdx + addCount = 0 + delCount = 0 + } + + switch lineType { + case DIFF_LINE_DEL: + if diffLine.RightIdx == 0 && diffLine.LeftIdx == idx-difference { + matchDiffLine = diffLine + } + case DIFF_LINE_ADD: + if diffLine.LeftIdx == 0 && diffLine.RightIdx == idx+difference { + matchDiffLine = diffLine + } + } + } + + if addCount == delCount { + return matchDiffLine + } + return nil +} + +// DiffFile represents a file in diff. +type DiffFile struct { + Name string + OldName string + Index string // 40-byte SHA, Changed/New: new SHA; Deleted: old SHA + Addition, Deletion int + Type DiffFileType + IsCreated bool + IsDeleted bool + IsBin bool + IsRenamed bool + IsSubmodule bool + Sections []*DiffSection + IsIncomplete bool +} + +func (diffFile *DiffFile) GetType() int { + return int(diffFile.Type) +} + +func (diffFile *DiffFile) NumSections() int { + return len(diffFile.Sections) +} + +// Diff contains all information of a specific diff output. +type Diff struct { + TotalAddition, TotalDeletion int + Files []*DiffFile + IsIncomplete bool +} + +func (diff *Diff) NumFiles() int { + return len(diff.Files) +} + +const _DIFF_HEAD = "diff --git " + +// ParsePatch takes a reader and parses everything it receives in diff format. +func ParsePatch(done chan<- error, maxLines, maxLineCharacteres, maxFiles int, reader io.Reader) *Diff { + var ( + diff = &Diff{Files: make([]*DiffFile, 0)} + + curFile *DiffFile + curSection = &DiffSection{ + Lines: make([]*DiffLine, 0, 10), + } + + leftLine, rightLine int + lineCount int + curFileLinesCount int + ) + input := bufio.NewReader(reader) + isEOF := false + for !isEOF { + // TODO: would input.ReadBytes be more memory-efficient? + line, err := input.ReadString('\n') + if err != nil { + if err == io.EOF { + isEOF = true + } else { + done <- fmt.Errorf("ReadString: %v", err) + return nil + } + } + + if len(line) > 0 && line[len(line)-1] == '\n' { + // Remove line break. + line = line[:len(line)-1] + } + + if strings.HasPrefix(line, "+++ ") || strings.HasPrefix(line, "--- ") || len(line) == 0 { + continue + } + + curFileLinesCount++ + lineCount++ + + // Diff data too large, we only show the first about maxlines lines + if curFileLinesCount >= maxLines || len(line) >= maxLineCharacteres { + curFile.IsIncomplete = true + } + + switch { + case line[0] == ' ': + diffLine := &DiffLine{Type: DIFF_LINE_PLAIN, Content: line, LeftIdx: leftLine, RightIdx: rightLine} + leftLine++ + rightLine++ + curSection.Lines = append(curSection.Lines, diffLine) + continue + case line[0] == '@': + curSection = &DiffSection{} + curFile.Sections = append(curFile.Sections, curSection) + ss := strings.Split(line, "@@") + diffLine := &DiffLine{Type: DIFF_LINE_SECTION, Content: line} + curSection.Lines = append(curSection.Lines, diffLine) + + // Parse line number. + ranges := strings.Split(ss[1][1:], " ") + leftLine, _ = strconv.Atoi(strings.Split(ranges[0], ",")[0][1:]) + if len(ranges) > 1 { + rightLine, _ = strconv.Atoi(strings.Split(ranges[1], ",")[0]) + } else { + rightLine = leftLine + } + continue + case line[0] == '+': + curFile.Addition++ + diff.TotalAddition++ + diffLine := &DiffLine{Type: DIFF_LINE_ADD, Content: line, RightIdx: rightLine} + rightLine++ + curSection.Lines = append(curSection.Lines, diffLine) + continue + case line[0] == '-': + curFile.Deletion++ + diff.TotalDeletion++ + diffLine := &DiffLine{Type: DIFF_LINE_DEL, Content: line, LeftIdx: leftLine} + if leftLine > 0 { + leftLine++ + } + curSection.Lines = append(curSection.Lines, diffLine) + case strings.HasPrefix(line, "Binary"): + curFile.IsBin = true + continue + } + + // Get new file. + if strings.HasPrefix(line, _DIFF_HEAD) { + middle := -1 + + // Note: In case file name is surrounded by double quotes (it happens only in git-shell). + // e.g. diff --git "a/xxx" "b/xxx" + hasQuote := line[len(_DIFF_HEAD)] == '"' + if hasQuote { + middle = strings.Index(line, ` "b/`) + } else { + middle = strings.Index(line, " b/") + } + + beg := len(_DIFF_HEAD) + a := line[beg+2 : middle] + b := line[middle+3:] + if hasQuote { + a = string(UnescapeChars([]byte(a[1 : len(a)-1]))) + b = string(UnescapeChars([]byte(b[1 : len(b)-1]))) + } + + curFile = &DiffFile{ + Name: a, + Type: DIFF_FILE_CHANGE, + Sections: make([]*DiffSection, 0, 10), + } + diff.Files = append(diff.Files, curFile) + if len(diff.Files) >= maxFiles { + diff.IsIncomplete = true + io.Copy(ioutil.Discard, reader) + break + } + curFileLinesCount = 0 + + // Check file diff type and submodule. + CHECK_TYPE: + for { + line, err := input.ReadString('\n') + if err != nil { + if err == io.EOF { + isEOF = true + } else { + done <- fmt.Errorf("ReadString: %v", err) + return nil + } + } + + switch { + case strings.HasPrefix(line, "new file"): + curFile.Type = DIFF_FILE_ADD + curFile.IsCreated = true + curFile.IsSubmodule = strings.HasSuffix(line, " 160000\n") + case strings.HasPrefix(line, "deleted"): + curFile.Type = DIFF_FILE_DEL + curFile.IsDeleted = true + curFile.IsSubmodule = strings.HasSuffix(line, " 160000\n") + case strings.HasPrefix(line, "index"): + if curFile.IsDeleted { + curFile.Index = line[6:46] + } else if len(line) >= 88 { + curFile.Index = line[49:88] + } else { + curFile.Index = curFile.Name + } + break CHECK_TYPE + case strings.HasPrefix(line, "similarity index 100%"): + curFile.Type = DIFF_FILE_RENAME + curFile.IsRenamed = true + curFile.OldName = curFile.Name + curFile.Name = b + curFile.Index = b + break CHECK_TYPE + case strings.HasPrefix(line, "old mode"): + break CHECK_TYPE + } + } + } + } + + done <- nil + return diff +} + +// GetDiffRange returns a parsed diff object between given commits. +func GetDiffRange(repoPath, beforeCommitID, afterCommitID string, maxLines, maxLineCharacteres, maxFiles int) (*Diff, error) { + repo, err := OpenRepository(repoPath) + if err != nil { + return nil, err + } + + commit, err := repo.GetCommit(afterCommitID) + if err != nil { + return nil, err + } + + cmd := NewCommand() + if len(beforeCommitID) == 0 { + // First commit of repository + if commit.ParentCount() == 0 { + cmd.AddArguments("show", "--full-index", afterCommitID) + } else { + c, _ := commit.Parent(0) + cmd.AddArguments("diff", "--full-index", "-M", c.ID.String(), afterCommitID) + } + } else { + cmd.AddArguments("diff", "--full-index", "-M", beforeCommitID, afterCommitID) + } + + stdout, w := io.Pipe() + done := make(chan error) + var diff *Diff + go func() { + diff = ParsePatch(done, maxLines, maxLineCharacteres, maxFiles, stdout) + }() + + stderr := new(bytes.Buffer) + err = cmd.RunInDirTimeoutPipeline(2*time.Minute, repoPath, w, stderr) + w.Close() // Close writer to exit parsing goroutine + if err != nil { + return nil, concatenateError(err, stderr.String()) + } + + return diff, <-done +} + +// RawDiffType represents the type of raw diff format. +type RawDiffType string + +const ( + RAW_DIFF_NORMAL RawDiffType = "diff" + RAW_DIFF_PATCH RawDiffType = "patch" +) + +// GetRawDiff dumps diff results of repository in given commit ID to io.Writer. +func GetRawDiff(repoPath, commitID string, diffType RawDiffType, writer io.Writer) error { + repo, err := OpenRepository(repoPath) + if err != nil { + return fmt.Errorf("OpenRepository: %v", err) + } + + commit, err := repo.GetCommit(commitID) + if err != nil { + return err + } + + cmd := NewCommand() + switch diffType { + case RAW_DIFF_NORMAL: + if commit.ParentCount() == 0 { + cmd.AddArguments("show", commitID) + } else { + c, _ := commit.Parent(0) + cmd.AddArguments("diff", "-M", c.ID.String(), commitID) + } + case RAW_DIFF_PATCH: + if commit.ParentCount() == 0 { + cmd.AddArguments("format-patch", "--no-signature", "--stdout", "--root", commitID) + } else { + c, _ := commit.Parent(0) + query := fmt.Sprintf("%s...%s", commitID, c.ID.String()) + cmd.AddArguments("format-patch", "--no-signature", "--stdout", query) + } + default: + return fmt.Errorf("invalid diffType: %s", diffType) + } + + stderr := new(bytes.Buffer) + if err = cmd.RunInDirPipeline(repoPath, writer, stderr); err != nil { + return concatenateError(err, stderr.String()) + } + return nil +} + +// GetDiffCommit returns a parsed diff object of given commit. +func GetDiffCommit(repoPath, commitID string, maxLines, maxLineCharacteres, maxFiles int) (*Diff, error) { + return GetDiffRange(repoPath, "", commitID, maxLines, maxLineCharacteres, maxFiles) +} diff --git a/vendor/github.com/gogs/git-module/repo_hook.go b/vendor/github.com/gogs/git-module/repo_hook.go new file mode 100644 index 00000000..7b49647e --- /dev/null +++ b/vendor/github.com/gogs/git-module/repo_hook.go @@ -0,0 +1,13 @@ +// Copyright 2015 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package git + +func (repo *Repository) GetHook(name string) (*Hook, error) { + return GetHook(repo.Path, name) +} + +func (repo *Repository) Hooks() ([]*Hook, error) { + return ListHooks(repo.Path) +} diff --git a/vendor/github.com/gogs/git-module/repo_object.go b/vendor/github.com/gogs/git-module/repo_object.go new file mode 100644 index 00000000..416ee459 --- /dev/null +++ b/vendor/github.com/gogs/git-module/repo_object.go @@ -0,0 +1,14 @@ +// Copyright 2014 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package git + +type ObjectType string + +const ( + OBJECT_COMMIT ObjectType = "commit" + OBJECT_TREE ObjectType = "tree" + OBJECT_BLOB ObjectType = "blob" + OBJECT_TAG ObjectType = "tag" +) diff --git a/vendor/github.com/gogs/git-module/repo_pull.go b/vendor/github.com/gogs/git-module/repo_pull.go new file mode 100644 index 00000000..22ccb269 --- /dev/null +++ b/vendor/github.com/gogs/git-module/repo_pull.go @@ -0,0 +1,81 @@ +// Copyright 2015 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package git + +import ( + "container/list" + "fmt" + "strconv" + "strings" + "time" +) + +// PullRequestInfo represents needed information for a pull request. +type PullRequestInfo struct { + MergeBase string + Commits *list.List + NumFiles int +} + +// GetMergeBase checks and returns merge base of two branches. +func (repo *Repository) GetMergeBase(base, head string) (string, error) { + stdout, err := NewCommand("merge-base", base, head).RunInDir(repo.Path) + if err != nil { + if strings.Contains(err.Error(), "exit status 1") { + return "", ErrNoMergeBase{} + } + return "", err + } + return strings.TrimSpace(stdout), nil +} + +// GetPullRequestInfo generates and returns pull request information +// between base and head branches of repositories. +func (repo *Repository) GetPullRequestInfo(basePath, baseBranch, headBranch string) (_ *PullRequestInfo, err error) { + var remoteBranch string + + // We don't need a temporary remote for same repository. + if repo.Path != basePath { + // Add a temporary remote + tmpRemote := strconv.FormatInt(time.Now().UnixNano(), 10) + if err = repo.AddRemote(tmpRemote, basePath, true); err != nil { + return nil, fmt.Errorf("AddRemote: %v", err) + } + defer repo.RemoveRemote(tmpRemote) + + remoteBranch = "remotes/" + tmpRemote + "/" + baseBranch + } else { + remoteBranch = baseBranch + } + + prInfo := new(PullRequestInfo) + prInfo.MergeBase, err = repo.GetMergeBase(remoteBranch, headBranch) + if err != nil { + return nil, err + } + + logs, err := NewCommand("log", prInfo.MergeBase+"..."+headBranch, _PRETTY_LOG_FORMAT).RunInDirBytes(repo.Path) + if err != nil { + return nil, err + } + prInfo.Commits, err = repo.parsePrettyFormatLogToList(logs) + if err != nil { + return nil, fmt.Errorf("parsePrettyFormatLogToList: %v", err) + } + + // Count number of changed files. + stdout, err := NewCommand("diff", "--name-only", remoteBranch+"..."+headBranch).RunInDir(repo.Path) + if err != nil { + return nil, err + } + prInfo.NumFiles = len(strings.Split(stdout, "\n")) - 1 + + return prInfo, nil +} + +// GetPatch generates and returns patch data between given revisions. +func (repo *Repository) GetPatch(base, head string) ([]byte, error) { + return NewCommand("diff", "-p", "--binary", base, head).RunInDirBytes(repo.Path) +} diff --git a/vendor/github.com/gogs/git-module/repo_tag.go b/vendor/github.com/gogs/git-module/repo_tag.go new file mode 100644 index 00000000..4cef496b --- /dev/null +++ b/vendor/github.com/gogs/git-module/repo_tag.go @@ -0,0 +1,209 @@ +// Copyright 2015 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package git + +import ( + "fmt" + "strings" + + "github.com/mcuadros/go-version" +) + +const TAG_PREFIX = "refs/tags/" + +// IsTagExist returns true if given tag exists in the repository. +func IsTagExist(repoPath, name string) bool { + return IsReferenceExist(repoPath, TAG_PREFIX+name) +} + +func (repo *Repository) IsTagExist(name string) bool { + return IsTagExist(repo.Path, name) +} + +func (repo *Repository) CreateTag(name, revision string) error { + _, err := NewCommand("tag", name, revision).RunInDir(repo.Path) + return err +} + +func (repo *Repository) getTag(id sha1) (*Tag, error) { + t, ok := repo.tagCache.Get(id.String()) + if ok { + log("Hit cache: %s", id) + return t.(*Tag), nil + } + + // Get tag type + tp, err := NewCommand("cat-file", "-t", id.String()).RunInDir(repo.Path) + if err != nil { + return nil, err + } + tp = strings.TrimSpace(tp) + + // Tag is a commit. + if ObjectType(tp) == OBJECT_COMMIT { + tag := &Tag{ + ID: id, + Object: id, + Type: string(OBJECT_COMMIT), + repo: repo, + } + + repo.tagCache.Set(id.String(), tag) + return tag, nil + } + + // Tag with message. + data, err := NewCommand("cat-file", "-p", id.String()).RunInDirBytes(repo.Path) + if err != nil { + return nil, err + } + + tag, err := parseTagData(data) + if err != nil { + return nil, err + } + + tag.ID = id + tag.repo = repo + + repo.tagCache.Set(id.String(), tag) + return tag, nil +} + +// GetTag returns a Git tag by given name. +func (repo *Repository) GetTag(name string) (*Tag, error) { + stdout, err := NewCommand("show-ref", "--tags", name).RunInDir(repo.Path) + if err != nil { + return nil, err + } + + id, err := NewIDFromString(strings.Split(stdout, " ")[0]) + if err != nil { + return nil, err + } + + tag, err := repo.getTag(id) + if err != nil { + return nil, err + } + tag.Name = name + return tag, nil +} + +// GetTags returns all tags of the repository. +func (repo *Repository) GetTags() ([]string, error) { + cmd := NewCommand("tag", "-l") + if version.Compare(gitVersion, "2.0.0", ">=") { + cmd.AddArguments("--sort=-v:refname") + } + + stdout, err := cmd.RunInDir(repo.Path) + if err != nil { + return nil, err + } + + tags := strings.Split(stdout, "\n") + tags = tags[:len(tags)-1] + + if version.Compare(gitVersion, "2.0.0", "<") { + version.Sort(tags) + + // Reverse order + for i := 0; i < len(tags)/2; i++ { + j := len(tags) - i - 1 + tags[i], tags[j] = tags[j], tags[i] + } + } + + return tags, nil +} + +type TagsResult struct { + // Indicates whether results include the latest tag. + HasLatest bool + // If results do not include the latest tag, a indicator 'after' to go back. + PreviousAfter string + // Indicates whether results include the oldest tag. + ReachEnd bool + // List of returned tags. + Tags []string +} + +// GetTagsAfter returns list of tags 'after' (exlusive) given tag. +func (repo *Repository) GetTagsAfter(after string, limit int) (*TagsResult, error) { + allTags, err := repo.GetTags() + if err != nil { + return nil, fmt.Errorf("GetTags: %v", err) + } + + if limit < 0 { + limit = 0 + } + + numAllTags := len(allTags) + if len(after) == 0 && limit == 0 { + return &TagsResult{ + HasLatest: true, + ReachEnd: true, + Tags: allTags, + }, nil + } else if len(after) == 0 && limit > 0 { + endIdx := limit + if limit >= numAllTags { + endIdx = numAllTags + } + return &TagsResult{ + HasLatest: true, + ReachEnd: limit >= numAllTags, + Tags: allTags[:endIdx], + }, nil + } + + previousAfter := "" + hasMatch := false + tags := make([]string, 0, len(allTags)) + for i := range allTags { + if hasMatch { + tags = allTags[i:] + break + } + if allTags[i] == after { + hasMatch = true + if limit > 0 && i-limit >= 0 { + previousAfter = allTags[i-limit] + } + continue + } + } + + if !hasMatch { + tags = allTags + } + + // If all tags after match is equal to the limit, it reaches the oldest tag as well. + if limit == 0 || len(tags) <= limit { + return &TagsResult{ + HasLatest: !hasMatch, + PreviousAfter: previousAfter, + ReachEnd: true, + Tags: tags, + }, nil + } + return &TagsResult{ + HasLatest: !hasMatch, + PreviousAfter: previousAfter, + Tags: tags[:limit], + }, nil +} + +// DeleteTag deletes a tag from the repository +func (repo *Repository) DeleteTag(name string) error { + cmd := NewCommand("tag", "-d") + + cmd.AddArguments(name) + _, err := cmd.RunInDir(repo.Path) + + return err +} diff --git a/vendor/github.com/gogs/git-module/repo_tree.go b/vendor/github.com/gogs/git-module/repo_tree.go new file mode 100644 index 00000000..baebb251 --- /dev/null +++ b/vendor/github.com/gogs/git-module/repo_tree.go @@ -0,0 +1,26 @@ +// Copyright 2015 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package git + +func (repo *Repository) getTree(id sha1) (*Tree, error) { + treePath := filepathFromSHA1(repo.Path, id.String()) + if isFile(treePath) { + _, err := NewCommand("ls-tree", id.String()).RunInDir(repo.Path) + if err != nil { + return nil, ErrNotExist{id.String(), ""} + } + } + + return NewTree(repo, id), nil +} + +// Find the tree object in the repository. +func (repo *Repository) GetTree(idStr string) (*Tree, error) { + id, err := NewIDFromString(idStr) + if err != nil { + return nil, err + } + return repo.getTree(id) +} diff --git a/vendor/github.com/gogs/git-module/sha1.go b/vendor/github.com/gogs/git-module/sha1.go new file mode 100644 index 00000000..7744275d --- /dev/null +++ b/vendor/github.com/gogs/git-module/sha1.go @@ -0,0 +1,93 @@ +// Copyright 2015 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package git + +import ( + "encoding/hex" + "fmt" + "strings" +) + +const EMPTY_SHA = "0000000000000000000000000000000000000000" + +type sha1 [20]byte + +// Equal returns true if s has the same sha1 as caller. +// Support 40-length-string, []byte, sha1. +func (id sha1) Equal(s2 interface{}) bool { + switch v := s2.(type) { + case string: + if len(v) != 40 { + return false + } + return v == id.String() + case []byte: + if len(v) != 20 { + return false + } + for i, v := range v { + if id[i] != v { + return false + } + } + case sha1: + for i, v := range v { + if id[i] != v { + return false + } + } + default: + return false + } + return true +} + +// String returns string (hex) representation of the Oid. +func (s sha1) String() string { + result := make([]byte, 0, 40) + hexvalues := []byte("0123456789abcdef") + for i := 0; i < 20; i++ { + result = append(result, hexvalues[s[i]>>4]) + result = append(result, hexvalues[s[i]&0xf]) + } + return string(result) +} + +// MustID always creates a new sha1 from a [20]byte array with no validation of input. +func MustID(b []byte) sha1 { + var id sha1 + for i := 0; i < 20; i++ { + id[i] = b[i] + } + return id +} + +// NewID creates a new sha1 from a [20]byte array. +func NewID(b []byte) (sha1, error) { + if len(b) != 20 { + return sha1{}, fmt.Errorf("Length must be 20: %v", b) + } + return MustID(b), nil +} + +// MustIDFromString always creates a new sha from a ID with no validation of input. +func MustIDFromString(s string) sha1 { + b, _ := hex.DecodeString(s) + return MustID(b) +} + +// NewIDFromString creates a new sha1 from a ID string of length 40. +func NewIDFromString(s string) (sha1, error) { + var id sha1 + s = strings.TrimSpace(s) + if len(s) != 40 { + return id, fmt.Errorf("Length must be 40: %s", s) + } + b, err := hex.DecodeString(s) + if err != nil { + return id, err + } + return NewID(b) +} diff --git a/vendor/github.com/gogs/git-module/signature.go b/vendor/github.com/gogs/git-module/signature.go new file mode 100644 index 00000000..95eb1bbe --- /dev/null +++ b/vendor/github.com/gogs/git-module/signature.go @@ -0,0 +1,48 @@ +// Copyright 2015 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package git + +import ( + "bytes" + "strconv" + "time" +) + +// Signature represents the Author or Committer information. +type Signature struct { + Email string + Name string + When time.Time +} + +// Helper to get a signature from the commit line, which looks like these: +// author Patrick Gundlach 1378823654 +0200 +// author Patrick Gundlach Thu, 07 Apr 2005 22:13:13 +0200 +// but without the "author " at the beginning (this method should) +// be used for author and committer. +// +// FIXME: include timezone for timestamp! +func newSignatureFromCommitline(line []byte) (_ *Signature, err error) { + sig := new(Signature) + emailStart := bytes.IndexByte(line, '<') + sig.Name = string(line[:emailStart-1]) + emailEnd := bytes.IndexByte(line, '>') + sig.Email = string(line[emailStart+1 : emailEnd]) + + // Check date format. + firstChar := line[emailEnd+2] + if firstChar >= 48 && firstChar <= 57 { + timestop := bytes.IndexByte(line[emailEnd+2:], ' ') + timestring := string(line[emailEnd+2 : emailEnd+2+timestop]) + seconds, _ := strconv.ParseInt(timestring, 10, 64) + sig.When = time.Unix(seconds, 0) + } else { + sig.When, err = time.Parse("Mon Jan _2 15:04:05 2006 -0700", string(line[emailEnd+2:])) + if err != nil { + return nil, err + } + } + return sig, nil +} diff --git a/vendor/github.com/gogs/git-module/submodule.go b/vendor/github.com/gogs/git-module/submodule.go new file mode 100644 index 00000000..57773300 --- /dev/null +++ b/vendor/github.com/gogs/git-module/submodule.go @@ -0,0 +1,78 @@ +// Copyright 2015 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package git + +import "strings" + +type SubModule struct { + Name string + URL string +} + +// SubModuleFile represents a file with submodule type. +type SubModuleFile struct { + *Commit + + refURL string + refID string +} + +func NewSubModuleFile(c *Commit, refURL, refID string) *SubModuleFile { + return &SubModuleFile{ + Commit: c, + refURL: refURL, + refID: refID, + } +} + +// RefURL guesses and returns reference URL. +func (sf *SubModuleFile) RefURL(urlPrefix string, parentPath string) string { + if sf.refURL == "" { + return "" + } + + url := strings.TrimSuffix(sf.refURL, ".git") + + // git://xxx/user/repo + if strings.HasPrefix(url, "git://") { + return "http://" + strings.TrimPrefix(url, "git://") + } + + // http[s]://xxx/user/repo + if strings.HasPrefix(url, "http://") || strings.HasPrefix(url, "https://") { + return url + } + + // Relative url prefix check (according to git submodule documentation) + if strings.HasPrefix(url, "./") || strings.HasPrefix(url, "../") { + // ...construct and return correct submodule url here... + idx := strings.Index(parentPath, "/src/") + if idx == -1 { + return url + } + return strings.TrimSuffix(urlPrefix, "/") + parentPath[:idx] + "/" + url + } + + // sysuser@xxx:user/repo + i := strings.Index(url, "@") + j := strings.LastIndex(url, ":") + + // Only process when i < j because git+ssh://git@git.forwardbias.in/npploader.git + if i > -1 && j > -1 && i < j { + // fix problem with reverse proxy works only with local server + if strings.Contains(urlPrefix, url[i+1:j]) { + return urlPrefix + url[j+1:] + } else { + return "http://" + url[i+1:j] + "/" + url[j+1:] + } + } + + return url +} + +// RefID returns reference ID. +func (sf *SubModuleFile) RefID() string { + return sf.refID +} diff --git a/vendor/github.com/gogs/git-module/tag.go b/vendor/github.com/gogs/git-module/tag.go new file mode 100644 index 00000000..f4bf7792 --- /dev/null +++ b/vendor/github.com/gogs/git-module/tag.go @@ -0,0 +1,65 @@ +// Copyright 2015 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package git + +import "bytes" + +// Tag represents a Git tag. +type Tag struct { + Name string + ID sha1 + repo *Repository + Object sha1 // The id of this commit object + Type string + Tagger *Signature + Message string +} + +func (tag *Tag) Commit() (*Commit, error) { + return tag.repo.getCommit(tag.Object) +} + +// Parse commit information from the (uncompressed) raw +// data from the commit object. +// \n\n separate headers from message +func parseTagData(data []byte) (*Tag, error) { + tag := new(Tag) + // we now have the contents of the commit object. Let's investigate... + nextline := 0 +l: + for { + eol := bytes.IndexByte(data[nextline:], '\n') + switch { + case eol > 0: + line := data[nextline : nextline+eol] + spacepos := bytes.IndexByte(line, ' ') + reftype := line[:spacepos] + switch string(reftype) { + case "object": + id, err := NewIDFromString(string(line[spacepos+1:])) + if err != nil { + return nil, err + } + tag.Object = id + case "type": + // A commit can have one or more parents + tag.Type = string(line[spacepos+1:]) + case "tagger": + sig, err := newSignatureFromCommitline(line[spacepos+1:]) + if err != nil { + return nil, err + } + tag.Tagger = sig + } + nextline += eol + 1 + case eol == 0: + tag.Message = string(data[nextline+1:]) + break l + default: + break l + } + } + return tag, nil +} diff --git a/vendor/github.com/gogs/git-module/tree.go b/vendor/github.com/gogs/git-module/tree.go new file mode 100644 index 00000000..789d4c9b --- /dev/null +++ b/vendor/github.com/gogs/git-module/tree.go @@ -0,0 +1,149 @@ +// Copyright 2015 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package git + +import ( + "bytes" + "fmt" + "strings" +) + +// Tree represents a flat directory listing. +type Tree struct { + ID sha1 + repo *Repository + + // parent tree + ptree *Tree + + entries Entries + entriesParsed bool +} + +func NewTree(repo *Repository, id sha1) *Tree { + return &Tree{ + ID: id, + repo: repo, + } +} + +// Predefine []byte variables to avoid runtime allocations. +var ( + escapedSlash = []byte(`\\`) + regularSlash = []byte(`\`) + escapedTab = []byte(`\t`) + regularTab = []byte("\t") +) + +// UnescapeChars reverses escaped characters. +func UnescapeChars(in []byte) []byte { + // LEGACY [Go 1.7]: use more expressive bytes.ContainsAny + if bytes.IndexAny(in, "\\\t") == -1 { + return in + } + + out := bytes.Replace(in, escapedSlash, regularSlash, -1) + out = bytes.Replace(out, escapedTab, regularTab, -1) + return out +} + +// parseTreeData parses tree information from the (uncompressed) raw +// data from the tree object. +func parseTreeData(tree *Tree, data []byte) ([]*TreeEntry, error) { + entries := make([]*TreeEntry, 0, 10) + l := len(data) + pos := 0 + for pos < l { + entry := new(TreeEntry) + entry.ptree = tree + step := 6 + switch string(data[pos : pos+step]) { + case "100644", "100664": + entry.mode = ENTRY_MODE_BLOB + entry.Type = OBJECT_BLOB + case "100755": + entry.mode = ENTRY_MODE_EXEC + entry.Type = OBJECT_BLOB + case "120000": + entry.mode = ENTRY_MODE_SYMLINK + entry.Type = OBJECT_BLOB + case "160000": + entry.mode = ENTRY_MODE_COMMIT + entry.Type = OBJECT_COMMIT + + step = 8 + case "040000": + entry.mode = ENTRY_MODE_TREE + entry.Type = OBJECT_TREE + default: + return nil, fmt.Errorf("unknown type: %v", string(data[pos:pos+step])) + } + pos += step + 6 // Skip string type of entry type. + + step = 40 + id, err := NewIDFromString(string(data[pos : pos+step])) + if err != nil { + return nil, err + } + entry.ID = id + pos += step + 1 // Skip half of sha1. + + step = bytes.IndexByte(data[pos:], '\n') + + // In case entry name is surrounded by double quotes(it happens only in git-shell). + if data[pos] == '"' { + entry.name = string(UnescapeChars(data[pos+1 : pos+step-1])) + } else { + entry.name = string(data[pos : pos+step]) + } + + pos += step + 1 + entries = append(entries, entry) + } + return entries, nil +} + +func (t *Tree) SubTree(rpath string) (*Tree, error) { + if len(rpath) == 0 { + return t, nil + } + + paths := strings.Split(rpath, "/") + var ( + err error + g = t + p = t + te *TreeEntry + ) + for _, name := range paths { + te, err = p.GetTreeEntryByPath(name) + if err != nil { + return nil, err + } + + g, err = t.repo.getTree(te.ID) + if err != nil { + return nil, err + } + g.ptree = p + p = g + } + return g, nil +} + +// ListEntries returns all entries of current tree. +func (t *Tree) ListEntries() (Entries, error) { + if t.entriesParsed { + return t.entries, nil + } + t.entriesParsed = true + + stdout, err := NewCommand("ls-tree", t.ID.String()).RunInDirBytes(t.repo.Path) + if err != nil { + return nil, err + } + t.entries, err = parseTreeData(t, stdout) + return t.entries, err +} diff --git a/vendor/github.com/gogs/git-module/tree_blob.go b/vendor/github.com/gogs/git-module/tree_blob.go new file mode 100644 index 00000000..e2e70152 --- /dev/null +++ b/vendor/github.com/gogs/git-module/tree_blob.go @@ -0,0 +1,57 @@ +// Copyright 2015 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package git + +import ( + "path" + "strings" +) + +func (t *Tree) GetTreeEntryByPath(relpath string) (*TreeEntry, error) { + if len(relpath) == 0 { + return &TreeEntry{ + ID: t.ID, + Type: OBJECT_TREE, + mode: ENTRY_MODE_TREE, + }, nil + } + + relpath = path.Clean(relpath) + parts := strings.Split(relpath, "/") + var err error + tree := t + for i, name := range parts { + if i == len(parts)-1 { + entries, err := tree.ListEntries() + if err != nil { + return nil, err + } + for _, v := range entries { + if v.name == name { + return v, nil + } + } + } else { + tree, err = tree.SubTree(name) + if err != nil { + return nil, err + } + } + } + return nil, ErrNotExist{"", relpath} +} + +func (t *Tree) GetBlobByPath(relpath string) (*Blob, error) { + entry, err := t.GetTreeEntryByPath(relpath) + if err != nil { + return nil, err + } + + if !entry.IsDir() { + return entry.Blob(), nil + } + + return nil, ErrNotExist{"", relpath} +} diff --git a/vendor/github.com/gogs/git-module/tree_entry.go b/vendor/github.com/gogs/git-module/tree_entry.go new file mode 100644 index 00000000..54574035 --- /dev/null +++ b/vendor/github.com/gogs/git-module/tree_entry.go @@ -0,0 +1,226 @@ +// Copyright 2015 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package git + +import ( + "fmt" + "path" + "path/filepath" + "runtime" + "sort" + "strconv" + "strings" +) + +type EntryMode int + +// There are only a few file modes in Git. They look like unix file modes, but they can only be +// one of these. +const ( + ENTRY_MODE_BLOB EntryMode = 0100644 + ENTRY_MODE_EXEC EntryMode = 0100755 + ENTRY_MODE_SYMLINK EntryMode = 0120000 + ENTRY_MODE_COMMIT EntryMode = 0160000 + ENTRY_MODE_TREE EntryMode = 0040000 +) + +type TreeEntry struct { + ID sha1 + Type ObjectType + + mode EntryMode + name string + + ptree *Tree + + commited bool + + size int64 + sized bool +} + +func (te *TreeEntry) Name() string { + return te.name +} + +func (te *TreeEntry) Size() int64 { + if te.IsDir() { + return 0 + } else if te.sized { + return te.size + } + + stdout, err := NewCommand("cat-file", "-s", te.ID.String()).RunInDir(te.ptree.repo.Path) + if err != nil { + return 0 + } + + te.sized = true + te.size, _ = strconv.ParseInt(strings.TrimSpace(stdout), 10, 64) + return te.size +} + +func (te *TreeEntry) IsSubModule() bool { + return te.mode == ENTRY_MODE_COMMIT +} + +func (te *TreeEntry) IsDir() bool { + return te.mode == ENTRY_MODE_TREE +} + +func (te *TreeEntry) IsLink() bool { + return te.mode == ENTRY_MODE_SYMLINK +} + +func (te *TreeEntry) Blob() *Blob { + return &Blob{ + repo: te.ptree.repo, + TreeEntry: te, + } +} + +type Entries []*TreeEntry + +var sorter = []func(t1, t2 *TreeEntry) bool{ + func(t1, t2 *TreeEntry) bool { + return (t1.IsDir() || t1.IsSubModule()) && !t2.IsDir() && !t2.IsSubModule() + }, + func(t1, t2 *TreeEntry) bool { + return t1.name < t2.name + }, +} + +func (tes Entries) Len() int { return len(tes) } +func (tes Entries) Swap(i, j int) { tes[i], tes[j] = tes[j], tes[i] } +func (tes Entries) Less(i, j int) bool { + t1, t2 := tes[i], tes[j] + var k int + for k = 0; k < len(sorter)-1; k++ { + sort := sorter[k] + switch { + case sort(t1, t2): + return true + case sort(t2, t1): + return false + } + } + return sorter[k](t1, t2) +} + +func (tes Entries) Sort() { + sort.Sort(tes) +} + +var defaultConcurrency = runtime.NumCPU() + +type commitInfo struct { + entryName string + infos []interface{} + err error +} + +// GetCommitsInfo takes advantages of concurrency to speed up getting information +// of all commits that are corresponding to these entries. This method will automatically +// choose the right number of goroutine (concurrency) to use related of the host CPU. +func (tes Entries) GetCommitsInfo(commit *Commit, treePath string) ([][]interface{}, error) { + return tes.GetCommitsInfoWithCustomConcurrency(commit, treePath, 0) +} + +// GetCommitsInfoWithCustomConcurrency takes advantages of concurrency to speed up getting information +// of all commits that are corresponding to these entries. If the given maxConcurrency is negative or +// equal to zero: the right number of goroutine (concurrency) to use will be choosen related of the +// host CPU. +func (tes Entries) GetCommitsInfoWithCustomConcurrency(commit *Commit, treePath string, maxConcurrency int) ([][]interface{}, error) { + if len(tes) == 0 { + return nil, nil + } + + if maxConcurrency <= 0 { + maxConcurrency = defaultConcurrency + } + + // Length of taskChan determines how many goroutines (subprocesses) can run at the same time. + // The length of revChan should be same as taskChan so goroutines whoever finished job can + // exit as early as possible, only store data inside channel. + taskChan := make(chan bool, maxConcurrency) + revChan := make(chan commitInfo, maxConcurrency) + doneChan := make(chan error) + + // Receive loop will exit when it collects same number of data pieces as tree entries. + // It notifies doneChan before exits or notify early with possible error. + infoMap := make(map[string][]interface{}, len(tes)) + go func() { + i := 0 + for info := range revChan { + if info.err != nil { + doneChan <- info.err + return + } + + infoMap[info.entryName] = info.infos + i++ + if i == len(tes) { + break + } + } + doneChan <- nil + }() + + for i := range tes { + // When taskChan is idle (or has empty slots), put operation will not block. + // However when taskChan is full, code will block and wait any running goroutines to finish. + taskChan <- true + + if tes[i].Type != OBJECT_COMMIT { + go func(i int) { + cinfo := commitInfo{entryName: tes[i].Name()} + c, err := commit.GetCommitByPath(filepath.Join(treePath, tes[i].Name())) + if err != nil { + cinfo.err = fmt.Errorf("GetCommitByPath (%s/%s): %v", treePath, tes[i].Name(), err) + } else { + cinfo.infos = []interface{}{tes[i], c} + } + revChan <- cinfo + <-taskChan // Clear one slot from taskChan to allow new goroutines to start. + }(i) + continue + } + + // Handle submodule + go func(i int) { + cinfo := commitInfo{entryName: tes[i].Name()} + sm, err := commit.GetSubModule(path.Join(treePath, tes[i].Name())) + if err != nil && !IsErrNotExist(err) { + cinfo.err = fmt.Errorf("GetSubModule (%s/%s): %v", treePath, tes[i].Name(), err) + revChan <- cinfo + return + } + + smURL := "" + if sm != nil { + smURL = sm.URL + } + + c, err := commit.GetCommitByPath(filepath.Join(treePath, tes[i].Name())) + if err != nil { + cinfo.err = fmt.Errorf("GetCommitByPath (%s/%s): %v", treePath, tes[i].Name(), err) + } else { + cinfo.infos = []interface{}{tes[i], NewSubModuleFile(c, smURL, tes[i].ID.String())} + } + revChan <- cinfo + <-taskChan + }(i) + } + + if err := <-doneChan; err != nil { + return nil, err + } + + commitsInfo := make([][]interface{}, len(tes)) + for i := 0; i < len(tes); i++ { + commitsInfo[i] = infoMap[tes[i].Name()] + } + return commitsInfo, nil +} diff --git a/vendor/github.com/gogs/git-module/utils.go b/vendor/github.com/gogs/git-module/utils.go new file mode 100644 index 00000000..da8c5817 --- /dev/null +++ b/vendor/github.com/gogs/git-module/utils.go @@ -0,0 +1,93 @@ +// Copyright 2015 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package git + +import ( + "fmt" + "os" + "path/filepath" + "strings" + "sync" +) + +// objectCache provides thread-safe cache opeations. +type objectCache struct { + lock sync.RWMutex + cache map[string]interface{} +} + +func newObjectCache() *objectCache { + return &objectCache{ + cache: make(map[string]interface{}, 10), + } +} + +func (oc *objectCache) Set(id string, obj interface{}) { + oc.lock.Lock() + defer oc.lock.Unlock() + + oc.cache[id] = obj +} + +func (oc *objectCache) Get(id string) (interface{}, bool) { + oc.lock.RLock() + defer oc.lock.RUnlock() + + obj, has := oc.cache[id] + return obj, has +} + +// isDir returns true if given path is a directory, +// or returns false when it's a file or does not exist. +func isDir(dir string) bool { + f, e := os.Stat(dir) + if e != nil { + return false + } + return f.IsDir() +} + +// isFile returns true if given path is a file, +// or returns false when it's a directory or does not exist. +func isFile(filePath string) bool { + f, e := os.Stat(filePath) + if e != nil { + return false + } + return !f.IsDir() +} + +// isExist checks whether a file or directory exists. +// It returns false when the file or directory does not exist. +func isExist(path string) bool { + _, err := os.Stat(path) + return err == nil || os.IsExist(err) +} + +func concatenateError(err error, stderr string) error { + if len(stderr) == 0 { + return err + } + return fmt.Errorf("%v - %s", err, stderr) +} + +// If the object is stored in its own file (i.e not in a pack file), +// this function returns the full path to the object file. +// It does not test if the file exists. +func filepathFromSHA1(rootdir, sha1 string) string { + return filepath.Join(rootdir, "objects", sha1[:2], sha1[2:]) +} + +func RefEndName(refStr string) string { + if strings.HasPrefix(refStr, BRANCH_PREFIX) { + return refStr[len(BRANCH_PREFIX):] + } + + if strings.HasPrefix(refStr, TAG_PREFIX) { + return refStr[len(TAG_PREFIX):] + } + + return refStr +} diff --git a/vendor/github.com/gogs/go-gogs-client/LICENSE b/vendor/github.com/gogs/go-gogs-client/LICENSE new file mode 100644 index 00000000..18b264d6 --- /dev/null +++ b/vendor/github.com/gogs/go-gogs-client/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2014 Go Git Service + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/vendor/github.com/gogs/go-gogs-client/README.md b/vendor/github.com/gogs/go-gogs-client/README.md new file mode 100644 index 00000000..ae33bc06 --- /dev/null +++ b/vendor/github.com/gogs/go-gogs-client/README.md @@ -0,0 +1,8 @@ +Gogs API client in Go +===================== + +This package is still in experiment, see [Wiki](https://github.com/gogits/go-gogs-client/wiki) for documentation. + +## License + +This project is under the MIT License. See the [LICENSE](https://github.com/gogits/gogs/blob/master/LICENSE) file for the full license text. \ No newline at end of file diff --git a/vendor/github.com/gogs/go-gogs-client/admin_org.go b/vendor/github.com/gogs/go-gogs-client/admin_org.go new file mode 100644 index 00000000..be140625 --- /dev/null +++ b/vendor/github.com/gogs/go-gogs-client/admin_org.go @@ -0,0 +1,21 @@ +// Copyright 2015 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package gogs + +import ( + "bytes" + "encoding/json" + "fmt" +) + +func (c *Client) AdminCreateOrg(user string, opt CreateOrgOption) (*Organization, error) { + body, err := json.Marshal(&opt) + if err != nil { + return nil, err + } + org := new(Organization) + return org, c.getParsedResponse("POST", fmt.Sprintf("/admin/users/%s/orgs", user), + jsonHeader, bytes.NewReader(body), org) +} diff --git a/vendor/github.com/gogs/go-gogs-client/admin_repo.go b/vendor/github.com/gogs/go-gogs-client/admin_repo.go new file mode 100644 index 00000000..50ba2be4 --- /dev/null +++ b/vendor/github.com/gogs/go-gogs-client/admin_repo.go @@ -0,0 +1,21 @@ +// Copyright 2015 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package gogs + +import ( + "bytes" + "encoding/json" + "fmt" +) + +func (c *Client) AdminCreateRepo(user string, opt CreateRepoOption) (*Repository, error) { + body, err := json.Marshal(&opt) + if err != nil { + return nil, err + } + repo := new(Repository) + return repo, c.getParsedResponse("POST", fmt.Sprintf("/admin/users/%s/repos", user), + jsonHeader, bytes.NewReader(body), repo) +} diff --git a/vendor/github.com/gogs/go-gogs-client/admin_user.go b/vendor/github.com/gogs/go-gogs-client/admin_user.go new file mode 100644 index 00000000..459031d7 --- /dev/null +++ b/vendor/github.com/gogs/go-gogs-client/admin_user.go @@ -0,0 +1,68 @@ +// Copyright 2015 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package gogs + +import ( + "bytes" + "encoding/json" + "fmt" +) + +type CreateUserOption struct { + SourceID int64 `json:"source_id"` + LoginName string `json:"login_name"` + Username string `json:"username" binding:"Required;AlphaDashDot;MaxSize(35)"` + FullName string `json:"full_name" binding:"MaxSize(100)"` + Email string `json:"email" binding:"Required;Email;MaxSize(254)"` + Password string `json:"password" binding:"MaxSize(255)"` + SendNotify bool `json:"send_notify"` +} + +func (c *Client) AdminCreateUser(opt CreateUserOption) (*User, error) { + body, err := json.Marshal(&opt) + if err != nil { + return nil, err + } + user := new(User) + return user, c.getParsedResponse("POST", "/admin/users", jsonHeader, bytes.NewReader(body), user) +} + +type EditUserOption struct { + SourceID int64 `json:"source_id"` + LoginName string `json:"login_name"` + FullName string `json:"full_name" binding:"MaxSize(100)"` + Email string `json:"email" binding:"Required;Email;MaxSize(254)"` + Password string `json:"password" binding:"MaxSize(255)"` + Website string `json:"website" binding:"MaxSize(50)"` + Location string `json:"location" binding:"MaxSize(50)"` + Active *bool `json:"active"` + Admin *bool `json:"admin"` + AllowGitHook *bool `json:"allow_git_hook"` + AllowImportLocal *bool `json:"allow_import_local"` + MaxRepoCreation *int `json:"max_repo_creation"` +} + +func (c *Client) AdminEditUser(user string, opt EditUserOption) error { + body, err := json.Marshal(&opt) + if err != nil { + return err + } + _, err = c.getResponse("PATCH", fmt.Sprintf("/admin/users/%s", user), jsonHeader, bytes.NewReader(body)) + return err +} + +func (c *Client) AdminDeleteUser(user string) error { + _, err := c.getResponse("DELETE", fmt.Sprintf("/admin/users/%s", user), nil, nil) + return err +} + +func (c *Client) AdminCreateUserPublicKey(user string, opt CreateKeyOption) (*PublicKey, error) { + body, err := json.Marshal(&opt) + if err != nil { + return nil, err + } + key := new(PublicKey) + return key, c.getParsedResponse("POST", fmt.Sprintf("/admin/users/%s/keys", user), jsonHeader, bytes.NewReader(body), key) +} diff --git a/vendor/github.com/gogs/go-gogs-client/gogs.go b/vendor/github.com/gogs/go-gogs-client/gogs.go new file mode 100644 index 00000000..1c81d16f --- /dev/null +++ b/vendor/github.com/gogs/go-gogs-client/gogs.go @@ -0,0 +1,90 @@ +// Copyright 2014 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package gogs + +import ( + "encoding/json" + "errors" + "io" + "io/ioutil" + "net/http" + "strings" +) + +func Version() string { + return "0.12.12" +} + +// Client represents a Gogs API client. +type Client struct { + url string + accessToken string + client *http.Client +} + +// NewClient initializes and returns a API client. +func NewClient(url, token string) *Client { + return &Client{ + url: strings.TrimSuffix(url, "/"), + accessToken: token, + client: &http.Client{}, + } +} + +// SetHTTPClient replaces default http.Client with user given one. +func (c *Client) SetHTTPClient(client *http.Client) { + c.client = client +} + +func (c *Client) doRequest(method, path string, header http.Header, body io.Reader) (*http.Response, error) { + req, err := http.NewRequest(method, c.url+"/api/v1"+path, body) + if err != nil { + return nil, err + } + req.Header.Set("Authorization", "token "+c.accessToken) + for k, v := range header { + req.Header[k] = v + } + + return c.client.Do(req) +} + +func (c *Client) getResponse(method, path string, header http.Header, body io.Reader) ([]byte, error) { + resp, err := c.doRequest(method, path, header, body) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + data, err := ioutil.ReadAll(resp.Body) + if err != nil { + return nil, err + } + + switch resp.StatusCode { + case 403: + return nil, errors.New("403 Forbidden") + case 404: + return nil, errors.New("404 Not Found") + } + + if resp.StatusCode/100 != 2 { + errMap := make(map[string]interface{}) + if err = json.Unmarshal(data, &errMap); err != nil { + return nil, err + } + return nil, errors.New(errMap["message"].(string)) + } + + return data, nil +} + +func (c *Client) getParsedResponse(method, path string, header http.Header, body io.Reader, obj interface{}) error { + data, err := c.getResponse(method, path, header, body) + if err != nil { + return err + } + return json.Unmarshal(data, obj) +} diff --git a/vendor/github.com/gogs/go-gogs-client/issue.go b/vendor/github.com/gogs/go-gogs-client/issue.go new file mode 100644 index 00000000..aa2f0d8e --- /dev/null +++ b/vendor/github.com/gogs/go-gogs-client/issue.go @@ -0,0 +1,103 @@ +// Copyright 2016 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package gogs + +import ( + "bytes" + "encoding/json" + "fmt" + "time" +) + +type StateType string + +const ( + STATE_OPEN StateType = "open" + STATE_CLOSED StateType = "closed" +) + +type PullRequestMeta struct { + HasMerged bool `json:"merged"` + Merged *time.Time `json:"merged_at"` +} + +type Issue struct { + ID int64 `json:"id"` + Index int64 `json:"number"` + Poster *User `json:"user"` + Title string `json:"title"` + Body string `json:"body"` + Labels []*Label `json:"labels"` + Milestone *Milestone `json:"milestone"` + Assignee *User `json:"assignee"` + State StateType `json:"state"` + Comments int `json:"comments"` + Created time.Time `json:"created_at"` + Updated time.Time `json:"updated_at"` + + PullRequest *PullRequestMeta `json:"pull_request"` +} + +type ListIssueOption struct { + Page int + State string +} + +func (c *Client) ListIssues(opt ListIssueOption) ([]*Issue, error) { + issues := make([]*Issue, 0, 10) + return issues, c.getParsedResponse("GET", fmt.Sprintf("/issues?page=%d", opt.Page), nil, nil, &issues) +} + +func (c *Client) ListUserIssues(opt ListIssueOption) ([]*Issue, error) { + issues := make([]*Issue, 0, 10) + return issues, c.getParsedResponse("GET", fmt.Sprintf("/user/issues?page=%d", opt.Page), nil, nil, &issues) +} + +func (c *Client) ListRepoIssues(owner, repo string, opt ListIssueOption) ([]*Issue, error) { + issues := make([]*Issue, 0, 10) + return issues, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues?page=%d", owner, repo, opt.Page), nil, nil, &issues) +} + +func (c *Client) GetIssue(owner, repo string, index int64) (*Issue, error) { + issue := new(Issue) + return issue, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d", owner, repo, index), nil, nil, issue) +} + +type CreateIssueOption struct { + Title string `json:"title" binding:"Required"` + Body string `json:"body"` + Assignee string `json:"assignee"` + Milestone int64 `json:"milestone"` + Labels []int64 `json:"labels"` + Closed bool `json:"closed"` +} + +func (c *Client) CreateIssue(owner, repo string, opt CreateIssueOption) (*Issue, error) { + body, err := json.Marshal(&opt) + if err != nil { + return nil, err + } + issue := new(Issue) + return issue, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues", owner, repo), + jsonHeader, bytes.NewReader(body), issue) +} + +type EditIssueOption struct { + Title string `json:"title"` + Body *string `json:"body"` + Assignee *string `json:"assignee"` + Milestone *int64 `json:"milestone"` + State *string `json:"state"` +} + +func (c *Client) EditIssue(owner, repo string, index int64, opt EditIssueOption) (*Issue, error) { + body, err := json.Marshal(&opt) + if err != nil { + return nil, err + } + issue := new(Issue) + return issue, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/issues/%d", owner, repo, index), + jsonHeader, bytes.NewReader(body), issue) +} diff --git a/vendor/github.com/gogs/go-gogs-client/issue_comment.go b/vendor/github.com/gogs/go-gogs-client/issue_comment.go new file mode 100644 index 00000000..246af0d9 --- /dev/null +++ b/vendor/github.com/gogs/go-gogs-client/issue_comment.go @@ -0,0 +1,70 @@ +// Copyright 2016 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package gogs + +import ( + "bytes" + "encoding/json" + "fmt" + "time" +) + +// Comment represents a comment in commit and issue page. +type Comment struct { + ID int64 `json:"id"` + HTMLURL string `json:"html_url"` + Poster *User `json:"user"` + Body string `json:"body"` + Created time.Time `json:"created_at"` + Updated time.Time `json:"updated_at"` +} + +// ListIssueComments list comments on an issue. +func (c *Client) ListIssueComments(owner, repo string, index int64) ([]*Comment, error) { + comments := make([]*Comment, 0, 10) + return comments, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/comments", owner, repo, index), nil, nil, &comments) +} + +// ListRepoIssueComments list comments for a given repo. +func (c *Client) ListRepoIssueComments(owner, repo string) ([]*Comment, error) { + comments := make([]*Comment, 0, 10) + return comments, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/comments", owner, repo), nil, nil, &comments) +} + +// CreateIssueCommentOption is option when creating an issue comment. +type CreateIssueCommentOption struct { + Body string `json:"body" binding:"Required"` +} + +// CreateIssueComment create comment on an issue. +func (c *Client) CreateIssueComment(owner, repo string, index int64, opt CreateIssueCommentOption) (*Comment, error) { + body, err := json.Marshal(&opt) + if err != nil { + return nil, err + } + comment := new(Comment) + return comment, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues/%d/comments", owner, repo, index), jsonHeader, bytes.NewReader(body), comment) +} + +// EditIssueCommentOption is option when editing an issue comment. +type EditIssueCommentOption struct { + Body string `json:"body" binding:"Required"` +} + +// EditIssueComment edits an issue comment. +func (c *Client) EditIssueComment(owner, repo string, index, commentID int64, opt EditIssueCommentOption) (*Comment, error) { + body, err := json.Marshal(&opt) + if err != nil { + return nil, err + } + comment := new(Comment) + return comment, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/issues/%d/comments/%d", owner, repo, index, commentID), jsonHeader, bytes.NewReader(body), comment) +} + +// DeleteIssueComment deletes an issue comment. +func (c *Client) DeleteIssueComment(owner, repo string, index, commentID int64) error { + _, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/comments/%d", owner, repo, index, commentID), nil, nil) + return err +} diff --git a/vendor/github.com/gogs/go-gogs-client/issue_label.go b/vendor/github.com/gogs/go-gogs-client/issue_label.go new file mode 100644 index 00000000..b8ff3009 --- /dev/null +++ b/vendor/github.com/gogs/go-gogs-client/issue_label.go @@ -0,0 +1,99 @@ +// Copyright 2016 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package gogs + +import ( + "bytes" + "encoding/json" + "fmt" +) + +type Label struct { + ID int64 `json:"id"` + Name string `json:"name"` + Color string `json:"color"` + URL string `json:"url"` +} + +func (c *Client) ListRepoLabels(owner, repo string) ([]*Label, error) { + labels := make([]*Label, 0, 10) + return labels, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/labels", owner, repo), nil, nil, &labels) +} + +func (c *Client) GetRepoLabel(owner, repo string, id int64) (*Label, error) { + label := new(Label) + return label, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/labels/%d", owner, repo, id), nil, nil, label) +} + +type CreateLabelOption struct { + Name string `json:"name" binding:"Required"` + Color string `json:"color" binding:"Required;Size(7)"` +} + +func (c *Client) CreateLabel(owner, repo string, opt CreateLabelOption) (*Label, error) { + body, err := json.Marshal(&opt) + if err != nil { + return nil, err + } + label := new(Label) + return label, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/labels", owner, repo), + jsonHeader, bytes.NewReader(body), label) +} + +type EditLabelOption struct { + Name *string `json:"name"` + Color *string `json:"color"` +} + +func (c *Client) EditLabel(owner, repo string, id int64, opt EditLabelOption) (*Label, error) { + body, err := json.Marshal(&opt) + if err != nil { + return nil, err + } + label := new(Label) + return label, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/labels/%d", owner, repo, id), jsonHeader, bytes.NewReader(body), label) +} + +func (c *Client) DeleteLabel(owner, repo string, id int64) error { + _, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/labels/%d", owner, repo, id), nil, nil) + return err +} + +type IssueLabelsOption struct { + Labels []int64 `json:"labels"` +} + +func (c *Client) GetIssueLabels(owner, repo string, index int64) ([]*Label, error) { + labels := make([]*Label, 0, 5) + return labels, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/labels", owner, repo, index), nil, nil, &labels) +} + +func (c *Client) AddIssueLabels(owner, repo string, index int64, opt IssueLabelsOption) ([]*Label, error) { + body, err := json.Marshal(&opt) + if err != nil { + return nil, err + } + labels := make([]*Label, 0) + return labels, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues/%d/labels", owner, repo, index), jsonHeader, bytes.NewReader(body), &labels) +} + +func (c *Client) ReplaceIssueLabels(owner, repo string, index int64, opt IssueLabelsOption) ([]*Label, error) { + body, err := json.Marshal(&opt) + if err != nil { + return nil, err + } + labels := make([]*Label, 0) + return labels, c.getParsedResponse("PUT", fmt.Sprintf("/repos/%s/%s/issues/%d/labels", owner, repo, index), jsonHeader, bytes.NewReader(body), &labels) +} + +func (c *Client) DeleteIssueLabel(owner, repo string, index, label int64) error { + _, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/labels/%d", owner, repo, index, label), nil, nil) + return err +} + +func (c *Client) ClearIssueLabels(owner, repo string, index int64) error { + _, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/labels", owner, repo, index), nil, nil) + return err +} diff --git a/vendor/github.com/gogs/go-gogs-client/issue_milestone.go b/vendor/github.com/gogs/go-gogs-client/issue_milestone.go new file mode 100644 index 00000000..ad27a15e --- /dev/null +++ b/vendor/github.com/gogs/go-gogs-client/issue_milestone.go @@ -0,0 +1,69 @@ +// Copyright 2016 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package gogs + +import ( + "bytes" + "encoding/json" + "fmt" + "time" +) + +type Milestone struct { + ID int64 `json:"id"` + Title string `json:"title"` + Description string `json:"description"` + State StateType `json:"state"` + OpenIssues int `json:"open_issues"` + ClosedIssues int `json:"closed_issues"` + Closed *time.Time `json:"closed_at"` + Deadline *time.Time `json:"due_on"` +} + +func (c *Client) ListRepoMilestones(owner, repo string) ([]*Milestone, error) { + milestones := make([]*Milestone, 0, 10) + return milestones, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/milestones", owner, repo), nil, nil, &milestones) +} + +func (c *Client) GetMilestone(owner, repo string, id int64) (*Milestone, error) { + milestone := new(Milestone) + return milestone, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/milestones/%d", owner, repo, id), nil, nil, milestone) +} + +type CreateMilestoneOption struct { + Title string `json:"title"` + Description string `json:"description"` + Deadline *time.Time `json:"due_on"` +} + +func (c *Client) CreateMilestone(owner, repo string, opt CreateMilestoneOption) (*Milestone, error) { + body, err := json.Marshal(&opt) + if err != nil { + return nil, err + } + milestone := new(Milestone) + return milestone, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/milestones", owner, repo), jsonHeader, bytes.NewReader(body), milestone) +} + +type EditMilestoneOption struct { + Title string `json:"title"` + Description *string `json:"description"` + State *string `json:"state"` + Deadline *time.Time `json:"due_on"` +} + +func (c *Client) EditMilestone(owner, repo string, id int64, opt EditMilestoneOption) (*Milestone, error) { + body, err := json.Marshal(&opt) + if err != nil { + return nil, err + } + milestone := new(Milestone) + return milestone, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/milestones/%d", owner, repo, id), jsonHeader, bytes.NewReader(body), milestone) +} + +func (c *Client) DeleteMilestone(owner, repo string, id int64) error { + _, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/milestones/%d", owner, repo, id), nil, nil) + return err +} diff --git a/vendor/github.com/gogs/go-gogs-client/miscellaneous.go b/vendor/github.com/gogs/go-gogs-client/miscellaneous.go new file mode 100644 index 00000000..fcf362ce --- /dev/null +++ b/vendor/github.com/gogs/go-gogs-client/miscellaneous.go @@ -0,0 +1,11 @@ +// Copyright 2015 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package gogs + +type MarkdownOption struct { + Text string + Mode string + Context string +} diff --git a/vendor/github.com/gogs/go-gogs-client/org.go b/vendor/github.com/gogs/go-gogs-client/org.go new file mode 100644 index 00000000..08d00882 --- /dev/null +++ b/vendor/github.com/gogs/go-gogs-client/org.go @@ -0,0 +1,60 @@ +// Copyright 2015 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package gogs + +import ( + "bytes" + "encoding/json" + "fmt" +) + +type Organization struct { + ID int64 `json:"id"` + UserName string `json:"username"` + FullName string `json:"full_name"` + AvatarUrl string `json:"avatar_url"` + Description string `json:"description"` + Website string `json:"website"` + Location string `json:"location"` +} + +func (c *Client) ListMyOrgs() ([]*Organization, error) { + orgs := make([]*Organization, 0, 5) + return orgs, c.getParsedResponse("GET", "/user/orgs", nil, nil, &orgs) +} + +func (c *Client) ListUserOrgs(user string) ([]*Organization, error) { + orgs := make([]*Organization, 0, 5) + return orgs, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/orgs", user), nil, nil, &orgs) +} + +func (c *Client) GetOrg(orgname string) (*Organization, error) { + org := new(Organization) + return org, c.getParsedResponse("GET", fmt.Sprintf("/orgs/%s", orgname), nil, nil, org) +} + +type CreateOrgOption struct { + UserName string `json:"username" binding:"Required"` + FullName string `json:"full_name"` + Description string `json:"description"` + Website string `json:"website"` + Location string `json:"location"` +} + +type EditOrgOption struct { + FullName string `json:"full_name"` + Description string `json:"description"` + Website string `json:"website"` + Location string `json:"location"` +} + +func (c *Client) EditOrg(orgname string, opt EditOrgOption) error { + body, err := json.Marshal(&opt) + if err != nil { + return err + } + _, err = c.getResponse("PATCH", fmt.Sprintf("/orgs/%s", orgname), jsonHeader, bytes.NewReader(body)) + return err +} diff --git a/vendor/github.com/gogs/go-gogs-client/org_member.go b/vendor/github.com/gogs/go-gogs-client/org_member.go new file mode 100644 index 00000000..d9cdadab --- /dev/null +++ b/vendor/github.com/gogs/go-gogs-client/org_member.go @@ -0,0 +1,24 @@ +// Copyright 2016 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package gogs + +import ( + "bytes" + "encoding/json" + "fmt" +) + +type AddOrgMembershipOption struct { + Role string `json:"role" binding:"Required"` +} + +func (c *Client) AddOrgMembership(org, user string, opt AddOrgMembershipOption) error { + body, err := json.Marshal(&opt) + if err != nil { + return err + } + _, err = c.getResponse("PUT", fmt.Sprintf("/orgs/%s/membership/%s", org, user), jsonHeader, bytes.NewReader(body)) + return err +} diff --git a/vendor/github.com/gogs/go-gogs-client/org_team.go b/vendor/github.com/gogs/go-gogs-client/org_team.go new file mode 100644 index 00000000..89f09e3f --- /dev/null +++ b/vendor/github.com/gogs/go-gogs-client/org_team.go @@ -0,0 +1,18 @@ +// Copyright 2016 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package gogs + +type Team struct { + ID int64 `json:"id"` + Name string `json:"name"` + Description string `json:"description"` + Permission string `json:"permission"` +} + +type CreateTeamOption struct { + Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(30)"` + Description string `json:"description" binding:"MaxSize(255)"` + Permission string `json:"permission"` +} diff --git a/vendor/github.com/gogs/go-gogs-client/pull.go b/vendor/github.com/gogs/go-gogs-client/pull.go new file mode 100644 index 00000000..be93b269 --- /dev/null +++ b/vendor/github.com/gogs/go-gogs-client/pull.go @@ -0,0 +1,37 @@ +// Copyright 2016 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package gogs + +import ( + "time" +) + +// PullRequest represents a pull reqesut API object. +type PullRequest struct { + // Copied from issue.go + ID int64 `json:"id"` + Index int64 `json:"number"` + Poster *User `json:"user"` + Title string `json:"title"` + Body string `json:"body"` + Labels []*Label `json:"labels"` + Milestone *Milestone `json:"milestone"` + Assignee *User `json:"assignee"` + State StateType `json:"state"` + Comments int `json:"comments"` + + HeadBranch string `json:"head_branch"` + HeadRepo *Repository `json:"head_repo"` + BaseBranch string `json:"base_branch"` + BaseRepo *Repository `json:"base_repo"` + + HTMLURL string `json:"html_url"` + + Mergeable *bool `json:"mergeable"` + HasMerged bool `json:"merged"` + Merged *time.Time `json:"merged_at"` + MergedCommitID *string `json:"merge_commit_sha"` + MergedBy *User `json:"merged_by"` +} diff --git a/vendor/github.com/gogs/go-gogs-client/release.go b/vendor/github.com/gogs/go-gogs-client/release.go new file mode 100644 index 00000000..69c7f3b9 --- /dev/null +++ b/vendor/github.com/gogs/go-gogs-client/release.go @@ -0,0 +1,22 @@ +// Copyright 2017 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package gogs + +import ( + "time" +) + +// Release represents a release API object. +type Release struct { + ID int64 `json:"id"` + TagName string `json:"tag_name"` + TargetCommitish string `json:"target_commitish"` + Name string `json:"name"` + Body string `json:"body"` + Draft bool `json:"draft"` + Prerelease bool `json:"prerelease"` + Author *User `json:"author"` + Created time.Time `json:"created_at"` +} diff --git a/vendor/github.com/gogs/go-gogs-client/repo.go b/vendor/github.com/gogs/go-gogs-client/repo.go new file mode 100644 index 00000000..48ded475 --- /dev/null +++ b/vendor/github.com/gogs/go-gogs-client/repo.go @@ -0,0 +1,129 @@ +// Copyright 2014 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package gogs + +import ( + "bytes" + "encoding/json" + "fmt" + "time" +) + +// Permission represents a API permission. +type Permission struct { + Admin bool `json:"admin"` + Push bool `json:"push"` + Pull bool `json:"pull"` +} + +// Repository represents a API repository. +type Repository struct { + ID int64 `json:"id"` + Owner *User `json:"owner"` + Name string `json:"name"` + FullName string `json:"full_name"` + Description string `json:"description"` + Private bool `json:"private"` + Fork bool `json:"fork"` + Parent *Repository `json:"parent"` + Empty bool `json:"empty"` + Mirror bool `json:"mirror"` + Size int64 `json:"size"` + HTMLURL string `json:"html_url"` + SSHURL string `json:"ssh_url"` + CloneURL string `json:"clone_url"` + Website string `json:"website"` + Stars int `json:"stars_count"` + Forks int `json:"forks_count"` + Watchers int `json:"watchers_count"` + OpenIssues int `json:"open_issues_count"` + DefaultBranch string `json:"default_branch"` + Created time.Time `json:"created_at"` + Updated time.Time `json:"updated_at"` + Permissions *Permission `json:"permissions,omitempty"` +} + +// ListMyRepos lists all repositories for the authenticated user that has access to. +func (c *Client) ListMyRepos() ([]*Repository, error) { + repos := make([]*Repository, 0, 10) + return repos, c.getParsedResponse("GET", "/user/repos", nil, nil, &repos) +} + +func (c *Client) ListUserRepos(user string) ([]*Repository, error) { + repos := make([]*Repository, 0, 10) + return repos, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/repos", user), nil, nil, &repos) +} + +func (c *Client) ListOrgRepos(org string) ([]*Repository, error) { + repos := make([]*Repository, 0, 10) + return repos, c.getParsedResponse("GET", fmt.Sprintf("/orgs/%s/repos", org), nil, nil, &repos) +} + +type CreateRepoOption struct { + Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(100)"` + Description string `json:"description" binding:"MaxSize(255)"` + Private bool `json:"private"` + AutoInit bool `json:"auto_init"` + Gitignores string `json:"gitignores"` + License string `json:"license"` + Readme string `json:"readme"` +} + +// CreateRepo creates a repository for authenticated user. +func (c *Client) CreateRepo(opt CreateRepoOption) (*Repository, error) { + body, err := json.Marshal(&opt) + if err != nil { + return nil, err + } + repo := new(Repository) + return repo, c.getParsedResponse("POST", "/user/repos", jsonHeader, bytes.NewReader(body), repo) +} + +// CreateOrgRepo creates an organization repository for authenticated user. +func (c *Client) CreateOrgRepo(org string, opt CreateRepoOption) (*Repository, error) { + body, err := json.Marshal(&opt) + if err != nil { + return nil, err + } + repo := new(Repository) + return repo, c.getParsedResponse("POST", fmt.Sprintf("/org/%s/repos", org), jsonHeader, bytes.NewReader(body), repo) +} + +// GetRepo returns information of a repository of given owner. +func (c *Client) GetRepo(owner, reponame string) (*Repository, error) { + repo := new(Repository) + return repo, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s", owner, reponame), nil, nil, repo) +} + +// DeleteRepo deletes a repository of user or organization. +func (c *Client) DeleteRepo(owner, repo string) error { + _, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s", owner, repo), nil, nil) + return err +} + +type MigrateRepoOption struct { + CloneAddr string `json:"clone_addr" binding:"Required"` + AuthUsername string `json:"auth_username"` + AuthPassword string `json:"auth_password"` + UID int `json:"uid" binding:"Required"` + RepoName string `json:"repo_name" binding:"Required"` + Mirror bool `json:"mirror"` + Private bool `json:"private"` + Description string `json:"description"` +} + +// MigrateRepo migrates a repository from other Git hosting sources for the +// authenticated user. +// +// To migrate a repository for a organization, the authenticated user must be a +// owner of the specified organization. +func (c *Client) MigrateRepo(opt MigrateRepoOption) (*Repository, error) { + body, err := json.Marshal(&opt) + if err != nil { + return nil, err + } + repo := new(Repository) + return repo, c.getParsedResponse("POST", "/repos/migrate", jsonHeader, bytes.NewReader(body), repo) +} diff --git a/vendor/github.com/gogs/go-gogs-client/repo_branch.go b/vendor/github.com/gogs/go-gogs-client/repo_branch.go new file mode 100644 index 00000000..1e581121 --- /dev/null +++ b/vendor/github.com/gogs/go-gogs-client/repo_branch.go @@ -0,0 +1,25 @@ +// Copyright 2016 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package gogs + +import ( + "fmt" +) + +// Branch represents a repository branch. +type Branch struct { + Name string `json:"name"` + Commit *PayloadCommit `json:"commit"` +} + +func (c *Client) ListRepoBranches(user, repo string) ([]*Branch, error) { + branches := make([]*Branch, 0, 10) + return branches, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/branches", user, repo), nil, nil, &branches) +} + +func (c *Client) GetRepoBranch(user, repo, branch string) (*Branch, error) { + b := new(Branch) + return b, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/branches/%s", user, repo, branch), nil, nil, &b) +} diff --git a/vendor/github.com/gogs/go-gogs-client/repo_collaborator.go b/vendor/github.com/gogs/go-gogs-client/repo_collaborator.go new file mode 100644 index 00000000..c382bc77 --- /dev/null +++ b/vendor/github.com/gogs/go-gogs-client/repo_collaborator.go @@ -0,0 +1,44 @@ +// Copyright 2016 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package gogs + +import ( + "bytes" + "encoding/json" + "fmt" +) + +type Collaborator struct { + *User + Permissions Permission `json:"permissions"` +} + +type AddCollaboratorOption struct { + Permission *string `json:"permission"` +} + +func (c *Client) ListCollaborator(user, repo string) ([]*Collaborator, error) { + collabs := make([]*Collaborator, 0, 10) + return collabs, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/collaborators", user, repo), nil, nil, &collabs) +} + +func (c *Client) AddCollaborator(user, repo, collaborator string, opt AddCollaboratorOption) error { + body, err := json.Marshal(&opt) + if err != nil { + return err + } + _, err = c.getResponse("PUT", fmt.Sprintf("/repos/%s/%s/collaborators/%s", user, repo, collaborator), nil, bytes.NewReader(body)) + return err +} + +func (c *Client) DeleteCollaborator(user, repo, collaborator string) error { + _, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/collaborators/%s", user, repo, collaborator), nil, nil) + return err +} + +func (c *Client) IsCollaborator(user, repo, collaborator string) error { + _, err := c.getResponse("GET", fmt.Sprintf("/repos/%s/%s/collaborators/%s", user, repo, collaborator), nil, nil) + return err +} diff --git a/vendor/github.com/gogs/go-gogs-client/repo_file.go b/vendor/github.com/gogs/go-gogs-client/repo_file.go new file mode 100644 index 00000000..c50708b4 --- /dev/null +++ b/vendor/github.com/gogs/go-gogs-client/repo_file.go @@ -0,0 +1,15 @@ +// Copyright 2014 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package gogs + +import ( + "fmt" +) + +// GetFile downloads a file of repository, ref can be branch/tag/commit. +// e.g.: ref -> master, tree -> macaron.go(no leading slash) +func (c *Client) GetFile(user, repo, ref, tree string) ([]byte, error) { + return c.getResponse("GET", fmt.Sprintf("/repos/%s/%s/raw/%s/%s", user, repo, ref, tree), nil, nil) +} diff --git a/vendor/github.com/gogs/go-gogs-client/repo_hook.go b/vendor/github.com/gogs/go-gogs-client/repo_hook.go new file mode 100644 index 00000000..3d06b9fc --- /dev/null +++ b/vendor/github.com/gogs/go-gogs-client/repo_hook.go @@ -0,0 +1,344 @@ +// Copyright 2014 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package gogs + +import ( + "bytes" + "encoding/json" + "errors" + "fmt" + "strings" + "time" +) + +var ( + ErrInvalidReceiveHook = errors.New("Invalid JSON payload received over webhook") +) + +type Hook struct { + ID int64 `json:"id"` + Type string `json:"type"` + URL string `json:"-"` + Config map[string]string `json:"config"` + Events []string `json:"events"` + Active bool `json:"active"` + Updated time.Time `json:"updated_at"` + Created time.Time `json:"created_at"` +} + +func (c *Client) ListRepoHooks(user, repo string) ([]*Hook, error) { + hooks := make([]*Hook, 0, 10) + return hooks, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/hooks", user, repo), nil, nil, &hooks) +} + +type CreateHookOption struct { + Type string `json:"type" binding:"Required"` + Config map[string]string `json:"config" binding:"Required"` + Events []string `json:"events"` + Active bool `json:"active"` +} + +func (c *Client) CreateRepoHook(user, repo string, opt CreateHookOption) (*Hook, error) { + body, err := json.Marshal(&opt) + if err != nil { + return nil, err + } + h := new(Hook) + return h, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/hooks", user, repo), jsonHeader, bytes.NewReader(body), h) +} + +type EditHookOption struct { + Config map[string]string `json:"config"` + Events []string `json:"events"` + Active *bool `json:"active"` +} + +func (c *Client) EditRepoHook(user, repo string, id int64, opt EditHookOption) error { + body, err := json.Marshal(&opt) + if err != nil { + return err + } + _, err = c.getResponse("PATCH", fmt.Sprintf("/repos/%s/%s/hooks/%d", user, repo, id), jsonHeader, bytes.NewReader(body)) + return err +} + +func (c *Client) DeleteRepoHook(user, repo string, id int64) error { + _, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/hooks/%d", user, repo, id), nil, nil) + return err +} + +type Payloader interface { + JSONPayload() ([]byte, error) +} + +type PayloadUser struct { + Name string `json:"name"` + Email string `json:"email"` + UserName string `json:"username"` +} + +// FIXME: consider use same format as API when commits API are added. +type PayloadCommit struct { + ID string `json:"id"` + Message string `json:"message"` + URL string `json:"url"` + Author *PayloadUser `json:"author"` + Committer *PayloadUser `json:"committer"` + + Added []string `json:"added"` + Removed []string `json:"removed"` + Modified []string `json:"modified"` + + Timestamp time.Time `json:"timestamp"` +} + +var ( + _ Payloader = &CreatePayload{} + _ Payloader = &DeletePayload{} + _ Payloader = &ForkPayload{} + _ Payloader = &PushPayload{} + _ Payloader = &IssuesPayload{} + _ Payloader = &IssueCommentPayload{} + _ Payloader = &PullRequestPayload{} +) + +// _________ __ +// \_ ___ \_______ ____ _____ _/ |_ ____ +// / \ \/\_ __ \_/ __ \\__ \\ __\/ __ \ +// \ \____| | \/\ ___/ / __ \| | \ ___/ +// \______ /|__| \___ >____ /__| \___ > +// \/ \/ \/ \/ + +type CreatePayload struct { + Ref string `json:"ref"` + RefType string `json:"ref_type"` + DefaultBranch string `json:"default_branch"` + Repo *Repository `json:"repository"` + Sender *User `json:"sender"` +} + +func (p *CreatePayload) JSONPayload() ([]byte, error) { + return json.MarshalIndent(p, "", " ") +} + +// ParseCreateHook parses create event hook content. +func ParseCreateHook(raw []byte) (*CreatePayload, error) { + hook := new(CreatePayload) + if err := json.Unmarshal(raw, hook); err != nil { + return nil, err + } + + // it is possible the JSON was parsed, however, + // was not from Gogs (maybe was from Bitbucket) + // So we'll check to be sure certain key fields + // were populated + switch { + case hook.Repo == nil: + return nil, ErrInvalidReceiveHook + case len(hook.Ref) == 0: + return nil, ErrInvalidReceiveHook + } + return hook, nil +} + +// ________ .__ __ +// \______ \ ____ | | _____/ |_ ____ +// | | \_/ __ \| | _/ __ \ __\/ __ \ +// | ` \ ___/| |_\ ___/| | \ ___/ +// /_______ /\___ >____/\___ >__| \___ > +// \/ \/ \/ \/ + +type PusherType string + +const ( + PUSHER_TYPE_USER PusherType = "user" +) + +type DeletePayload struct { + Ref string `json:"ref"` + RefType string `json:"ref_type"` + PusherType PusherType `json:"pusher_type"` + Repo *Repository `json:"repository"` + Sender *User `json:"sender"` +} + +func (p *DeletePayload) JSONPayload() ([]byte, error) { + return json.MarshalIndent(p, "", " ") +} + +// ___________ __ +// \_ _____/__________| | __ +// | __)/ _ \_ __ \ |/ / +// | \( <_> ) | \/ < +// \___ / \____/|__| |__|_ \ +// \/ \/ + +type ForkPayload struct { + Forkee *Repository `json:"forkee"` + Repo *Repository `json:"repository"` + Sender *User `json:"sender"` +} + +func (p *ForkPayload) JSONPayload() ([]byte, error) { + return json.MarshalIndent(p, "", " ") +} + +// __________ .__ +// \______ \__ __ _____| |__ +// | ___/ | \/ ___/ | \ +// | | | | /\___ \| Y \ +// |____| |____//____ >___| / +// \/ \/ + +// PushPayload represents a payload information of push event. +type PushPayload struct { + Ref string `json:"ref"` + Before string `json:"before"` + After string `json:"after"` + CompareURL string `json:"compare_url"` + Commits []*PayloadCommit `json:"commits"` + Repo *Repository `json:"repository"` + Pusher *User `json:"pusher"` + Sender *User `json:"sender"` +} + +func (p *PushPayload) JSONPayload() ([]byte, error) { + return json.MarshalIndent(p, "", " ") +} + +// ParsePushHook parses push event hook content. +func ParsePushHook(raw []byte) (*PushPayload, error) { + hook := new(PushPayload) + if err := json.Unmarshal(raw, hook); err != nil { + return nil, err + } + + switch { + case hook.Repo == nil: + return nil, ErrInvalidReceiveHook + case len(hook.Ref) == 0: + return nil, ErrInvalidReceiveHook + } + return hook, nil +} + +// Branch returns branch name from a payload +func (p *PushPayload) Branch() string { + return strings.Replace(p.Ref, "refs/heads/", "", -1) +} + +// .___ +// | | ______ ________ __ ____ +// | |/ ___// ___/ | \_/ __ \ +// | |\___ \ \___ \| | /\ ___/ +// |___/____ >____ >____/ \___ > +// \/ \/ \/ + +type HookIssueAction string + +const ( + HOOK_ISSUE_OPENED HookIssueAction = "opened" + HOOK_ISSUE_CLOSED HookIssueAction = "closed" + HOOK_ISSUE_REOPENED HookIssueAction = "reopened" + HOOK_ISSUE_EDITED HookIssueAction = "edited" + HOOK_ISSUE_ASSIGNED HookIssueAction = "assigned" + HOOK_ISSUE_UNASSIGNED HookIssueAction = "unassigned" + HOOK_ISSUE_LABEL_UPDATED HookIssueAction = "label_updated" + HOOK_ISSUE_LABEL_CLEARED HookIssueAction = "label_cleared" + HOOK_ISSUE_MILESTONED HookIssueAction = "milestoned" + HOOK_ISSUE_DEMILESTONED HookIssueAction = "demilestoned" + HOOK_ISSUE_SYNCHRONIZED HookIssueAction = "synchronized" +) + +type ChangesFromPayload struct { + From string `json:"from"` +} + +type ChangesPayload struct { + Title *ChangesFromPayload `json:"title,omitempty"` + Body *ChangesFromPayload `json:"body,omitempty"` +} + +// IssuesPayload represents a payload information of issues event. +type IssuesPayload struct { + Action HookIssueAction `json:"action"` + Index int64 `json:"number"` + Issue *Issue `json:"issue"` + Changes *ChangesPayload `json:"changes,omitempty"` + Repository *Repository `json:"repository"` + Sender *User `json:"sender"` +} + +func (p *IssuesPayload) JSONPayload() ([]byte, error) { + return json.MarshalIndent(p, "", " ") +} + +type HookIssueCommentAction string + +const ( + HOOK_ISSUE_COMMENT_CREATED HookIssueCommentAction = "created" + HOOK_ISSUE_COMMENT_EDITED HookIssueCommentAction = "edited" + HOOK_ISSUE_COMMENT_DELETED HookIssueCommentAction = "deleted" +) + +// IssueCommentPayload represents a payload information of issue comment event. +type IssueCommentPayload struct { + Action HookIssueCommentAction `json:"action"` + Issue *Issue `json:"issue"` + Comment *Comment `json:"comment"` + Changes *ChangesPayload `json:"changes,omitempty"` + Repository *Repository `json:"repository"` + Sender *User `json:"sender"` +} + +func (p *IssueCommentPayload) JSONPayload() ([]byte, error) { + return json.MarshalIndent(p, "", " ") +} + +// __________ .__ .__ __________ __ +// \______ \__ __| | | | \______ \ ____ ________ __ ____ _______/ |_ +// | ___/ | \ | | | | _// __ \/ ____/ | \_/ __ \ / ___/\ __\ +// | | | | / |_| |__ | | \ ___< <_| | | /\ ___/ \___ \ | | +// |____| |____/|____/____/ |____|_ /\___ >__ |____/ \___ >____ > |__| +// \/ \/ |__| \/ \/ + +// PullRequestPayload represents a payload information of pull request event. +type PullRequestPayload struct { + Action HookIssueAction `json:"action"` + Index int64 `json:"number"` + PullRequest *PullRequest `json:"pull_request"` + Changes *ChangesPayload `json:"changes,omitempty"` + Repository *Repository `json:"repository"` + Sender *User `json:"sender"` +} + +func (p *PullRequestPayload) JSONPayload() ([]byte, error) { + return json.MarshalIndent(p, "", " ") +} + +// __________ .__ +// \______ \ ____ | | ____ _____ ______ ____ +// | _// __ \| | _/ __ \\__ \ / ___// __ \ +// | | \ ___/| |_\ ___/ / __ \_\___ \\ ___/ +// |____|_ /\___ >____/\___ >____ /____ >\___ > +// \/ \/ \/ \/ \/ \/ + +type HookReleaseAction string + +const ( + HOOK_RELEASE_PUBLISHED HookReleaseAction = "published" +) + +// ReleasePayload represents a payload information of release event. +type ReleasePayload struct { + Action HookReleaseAction `json:"action"` + Release *Release `json:"release"` + Repository *Repository `json:"repository"` + Sender *User `json:"sender"` +} + +func (p *ReleasePayload) JSONPayload() ([]byte, error) { + return json.MarshalIndent(p, "", " ") +} diff --git a/vendor/github.com/gogs/go-gogs-client/repo_key.go b/vendor/github.com/gogs/go-gogs-client/repo_key.go new file mode 100644 index 00000000..2201602c --- /dev/null +++ b/vendor/github.com/gogs/go-gogs-client/repo_key.go @@ -0,0 +1,50 @@ +// Copyright 2015 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package gogs + +import ( + "bytes" + "encoding/json" + "fmt" + "time" +) + +type DeployKey struct { + ID int64 `json:"id"` + Key string `json:"key"` + URL string `json:"url"` + Title string `json:"title"` + Created time.Time `json:"created_at"` + ReadOnly bool `json:"read_only"` +} + +func (c *Client) ListDeployKeys(user, repo string) ([]*DeployKey, error) { + keys := make([]*DeployKey, 0, 10) + return keys, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/keys", user, repo), nil, nil, &keys) +} + +func (c *Client) GetDeployKey(user, repo string, keyID int64) (*DeployKey, error) { + key := new(DeployKey) + return key, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/keys/%d", user, repo, keyID), nil, nil, &key) +} + +type CreateKeyOption struct { + Title string `json:"title" binding:"Required"` + Key string `json:"key" binding:"Required"` +} + +func (c *Client) CreateDeployKey(user, repo string, opt CreateKeyOption) (*DeployKey, error) { + body, err := json.Marshal(&opt) + if err != nil { + return nil, err + } + key := new(DeployKey) + return key, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/keys", user, repo), jsonHeader, bytes.NewReader(body), key) +} + +func (c *Client) DeleteDeployKey(owner, repo string, keyID int64) error { + _, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/keys/%d", owner, repo, keyID), nil, nil) + return err +} diff --git a/vendor/github.com/gogs/go-gogs-client/user.go b/vendor/github.com/gogs/go-gogs-client/user.go new file mode 100644 index 00000000..3879b1a6 --- /dev/null +++ b/vendor/github.com/gogs/go-gogs-client/user.go @@ -0,0 +1,36 @@ +// Copyright 2014 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package gogs + +import ( + "encoding/json" + "fmt" +) + +// User represents a API user. +type User struct { + ID int64 `json:"id"` + UserName string `json:"login"` + FullName string `json:"full_name"` + Email string `json:"email"` + AvatarUrl string `json:"avatar_url"` +} + +// MarshalJSON implements the json.Marshaler interface for User +func (u User) MarshalJSON() ([]byte, error) { + // Re-declaring User to avoid recursion + type shadow User + return json.Marshal(struct { + shadow + // LEGACY [Gogs 1.0]: remove field(s) for backward compatibility + CompatUserName string `json:"username"` + }{shadow(u), u.UserName}) +} + +func (c *Client) GetUserInfo(user string) (*User, error) { + u := new(User) + err := c.getParsedResponse("GET", fmt.Sprintf("/users/%s", user), nil, nil, u) + return u, err +} diff --git a/vendor/github.com/gogs/go-gogs-client/user_app.go b/vendor/github.com/gogs/go-gogs-client/user_app.go new file mode 100644 index 00000000..965ed6eb --- /dev/null +++ b/vendor/github.com/gogs/go-gogs-client/user_app.go @@ -0,0 +1,46 @@ +// Copyright 2014 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package gogs + +import ( + "bytes" + "encoding/base64" + "encoding/json" + "fmt" + "net/http" +) + +func BasicAuthEncode(user, pass string) string { + return base64.StdEncoding.EncodeToString([]byte(user + ":" + pass)) +} + +// AccessToken represents a API access token. +type AccessToken struct { + Name string `json:"name"` + Sha1 string `json:"sha1"` +} + +func (c *Client) ListAccessTokens(user, pass string) ([]*AccessToken, error) { + tokens := make([]*AccessToken, 0, 10) + return tokens, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/tokens", user), + http.Header{"Authorization": []string{"Basic " + BasicAuthEncode(user, pass)}}, nil, &tokens) +} + +type CreateAccessTokenOption struct { + Name string `json:"name" binding:"Required"` +} + +func (c *Client) CreateAccessToken(user, pass string, opt CreateAccessTokenOption) (*AccessToken, error) { + body, err := json.Marshal(&opt) + if err != nil { + return nil, err + } + t := new(AccessToken) + return t, c.getParsedResponse("POST", fmt.Sprintf("/users/%s/tokens", user), + http.Header{ + "content-type": []string{"application/json"}, + "Authorization": []string{"Basic " + BasicAuthEncode(user, pass)}}, + bytes.NewReader(body), t) +} diff --git a/vendor/github.com/gogs/go-gogs-client/user_email.go b/vendor/github.com/gogs/go-gogs-client/user_email.go new file mode 100644 index 00000000..02dd4023 --- /dev/null +++ b/vendor/github.com/gogs/go-gogs-client/user_email.go @@ -0,0 +1,43 @@ +// Copyright 2015 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package gogs + +import ( + "bytes" + "encoding/json" +) + +type Email struct { + Email string `json:"email"` + Verified bool `json:"verified"` + Primary bool `json:"primary"` +} + +func (c *Client) ListEmails() ([]*Email, error) { + emails := make([]*Email, 0, 3) + return emails, c.getParsedResponse("GET", "/user/emails", nil, nil, &emails) +} + +type CreateEmailOption struct { + Emails []string `json:"emails"` +} + +func (c *Client) AddEmail(opt CreateEmailOption) ([]*Email, error) { + body, err := json.Marshal(&opt) + if err != nil { + return nil, err + } + emails := make([]*Email, 0, 3) + return emails, c.getParsedResponse("POST", "/user/emails", jsonHeader, bytes.NewReader(body), emails) +} + +func (c *Client) DeleteEmail(opt CreateEmailOption) error { + body, err := json.Marshal(&opt) + if err != nil { + return err + } + _, err = c.getResponse("DELETE", "/user/emails", jsonHeader, bytes.NewReader(body)) + return err +} diff --git a/vendor/github.com/gogs/go-gogs-client/user_follow.go b/vendor/github.com/gogs/go-gogs-client/user_follow.go new file mode 100644 index 00000000..36cc65d4 --- /dev/null +++ b/vendor/github.com/gogs/go-gogs-client/user_follow.go @@ -0,0 +1,47 @@ +// Copyright 2015 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package gogs + +import "fmt" + +func (c *Client) ListMyFollowers(page int) ([]*User, error) { + users := make([]*User, 0, 10) + return users, c.getParsedResponse("GET", fmt.Sprintf("/user/followers?page=%d", page), nil, nil, &users) +} + +func (c *Client) ListFollowers(user string, page int) ([]*User, error) { + users := make([]*User, 0, 10) + return users, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/followers?page=%d", user, page), nil, nil, &users) +} + +func (c *Client) ListMyFollowing(page int) ([]*User, error) { + users := make([]*User, 0, 10) + return users, c.getParsedResponse("GET", fmt.Sprintf("/user/following?page=%d", page), nil, nil, &users) +} + +func (c *Client) ListFollowing(user string, page int) ([]*User, error) { + users := make([]*User, 0, 10) + return users, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/following?page=%d", user, page), nil, nil, &users) +} + +func (c *Client) IsFollowing(target string) bool { + _, err := c.getResponse("GET", fmt.Sprintf("/user/following/%s", target), nil, nil) + return err == nil +} + +func (c *Client) IsUserFollowing(user, target string) bool { + _, err := c.getResponse("GET", fmt.Sprintf("/users/%s/following/%s", user, target), nil, nil) + return err == nil +} + +func (c *Client) Follow(target string) error { + _, err := c.getResponse("PUT", fmt.Sprintf("/user/following/%s", target), nil, nil) + return err +} + +func (c *Client) Unfollow(target string) error { + _, err := c.getResponse("DELETE", fmt.Sprintf("/user/following/%s", target), nil, nil) + return err +} diff --git a/vendor/github.com/gogs/go-gogs-client/user_key.go b/vendor/github.com/gogs/go-gogs-client/user_key.go new file mode 100644 index 00000000..c0278e0e --- /dev/null +++ b/vendor/github.com/gogs/go-gogs-client/user_key.go @@ -0,0 +1,49 @@ +// Copyright 2015 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package gogs + +import ( + "bytes" + "encoding/json" + "fmt" + "time" +) + +type PublicKey struct { + ID int64 `json:"id"` + Key string `json:"key"` + URL string `json:"url,omitempty"` + Title string `json:"title,omitempty"` + Created time.Time `json:"created_at,omitempty"` +} + +func (c *Client) ListPublicKeys(user string) ([]*PublicKey, error) { + keys := make([]*PublicKey, 0, 10) + return keys, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/keys", user), nil, nil, &keys) +} + +func (c *Client) ListMyPublicKeys() ([]*PublicKey, error) { + keys := make([]*PublicKey, 0, 10) + return keys, c.getParsedResponse("GET", "/user/keys", nil, nil, &keys) +} + +func (c *Client) GetPublicKey(keyID int64) (*PublicKey, error) { + key := new(PublicKey) + return key, c.getParsedResponse("GET", fmt.Sprintf("/user/keys/%d", keyID), nil, nil, &key) +} + +func (c *Client) CreatePublicKey(opt CreateKeyOption) (*PublicKey, error) { + body, err := json.Marshal(&opt) + if err != nil { + return nil, err + } + key := new(PublicKey) + return key, c.getParsedResponse("POST", "/user/keys", jsonHeader, bytes.NewReader(body), key) +} + +func (c *Client) DeletePublicKey(keyID int64) error { + _, err := c.getResponse("DELETE", fmt.Sprintf("/user/keys/%d", keyID), nil, nil) + return err +} diff --git a/vendor/github.com/gogs/go-gogs-client/utils.go b/vendor/github.com/gogs/go-gogs-client/utils.go new file mode 100644 index 00000000..a4d673e0 --- /dev/null +++ b/vendor/github.com/gogs/go-gogs-client/utils.go @@ -0,0 +1,23 @@ +// Copyright 2015 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package gogs + +import ( + "net/http" +) + +var jsonHeader = http.Header{"content-type": []string{"application/json"}} + +func Bool(v bool) *bool { + return &v +} + +func String(v string) *string { + return &v +} + +func Int64(v int64) *int64 { + return &v +} diff --git a/vendor/github.com/gogs/go-libravatar/LICENSE b/vendor/github.com/gogs/go-libravatar/LICENSE new file mode 100644 index 00000000..8c89d4e3 --- /dev/null +++ b/vendor/github.com/gogs/go-libravatar/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2016 Sandro Santilli + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/vendor/github.com/gogs/go-libravatar/Makefile b/vendor/github.com/gogs/go-libravatar/Makefile new file mode 100644 index 00000000..2a70ddc7 --- /dev/null +++ b/vendor/github.com/gogs/go-libravatar/Makefile @@ -0,0 +1,12 @@ +PACKAGES ?= $(shell go list ./...) + +.PHONY: check +check: lint + go test + +.PHONY: lint +lint: + @which golint > /dev/null; if [ $$? -ne 0 ]; then \ + go get -u github.com/golang/lint/golint; \ + fi + @for PKG in $(PACKAGES); do golint -set_exit_status $$PKG || exit 1; done; diff --git a/vendor/github.com/gogs/go-libravatar/README.md b/vendor/github.com/gogs/go-libravatar/README.md new file mode 100644 index 00000000..c9d72c43 --- /dev/null +++ b/vendor/github.com/gogs/go-libravatar/README.md @@ -0,0 +1,28 @@ +Simple [golang](https://www.golang.org) library for serving +[federated avatars](https://www.libravatar.org) + +[![trunk](https://goreportcard.com/badge/strk.kbt.io/projects/go/libravatar)] +(https://goreportcard.com/report/strk.kbt.io/projects/go/libravatar) + +# Use + +```sh +go get strk.kbt.io/projects/go/libravatar +cd $GOPATH/src/strk.kbt.io/projects/go/libravatar +go doc +``` + +# Contribute + +A clone of the code repository would be downloaded by `go get`. +You can send patches or pull requests to strk@kbt.io. + +If you need a place to publish your contribution branches, +you could start from a fork of the gitlab mirror: +https://gitlab.com/strk/go-libravatar + +# Contacts + + * Project homepage: http://strk.kbt.io/projects/go/libravatar + * Maintainer: Sandro Santilli + diff --git a/vendor/github.com/gogs/go-libravatar/libravatar.go b/vendor/github.com/gogs/go-libravatar/libravatar.go new file mode 100644 index 00000000..5088d02c --- /dev/null +++ b/vendor/github.com/gogs/go-libravatar/libravatar.go @@ -0,0 +1,300 @@ +// Copyright 2016 by Sandro Santilli +// Use of this source code is governed by a MIT +// license that can be found in the LICENSE file. + +// Implements support for federated avatars lookup. +// See https://wiki.libravatar.org/api/ + +package libravatar + +import ( + "crypto/md5" + "crypto/sha256" + "fmt" + "math/rand" + "net" + "net/mail" + "net/url" + "strings" + "time" +) + +// Default images (to be used as defaultURL) +const ( + // Do not load any image if none is associated with the email + // hash, instead return an HTTP 404 (File Not Found) response + HTTP404 = "404" + // (mystery-man) a simple, cartoon-style silhouetted outline of + // a person (does not vary by email hash) + MysteryMan = "mm" + // a geometric pattern based on an email hash + IdentIcon = "identicon" + // a generated 'monster' with different colors, faces, etc + MonsterID = "monsterid" + // generated faces with differing features and backgrounds + Wavatar = "wavatar" + // awesome generated, 8-bit arcade-style pixelated faces + Retro = "retro" +) + +var ( + // DefaultLibravatar is a default Libravatar object, + // enabling object-less function calls + DefaultLibravatar = New() +) + +/* This should be moved in its own file */ +type cacheKey struct { + service string + domain string +} + +type cacheValue struct { + target string + checkedAt time.Time +} + +// Libravatar is an opaque structure holding service configuration +type Libravatar struct { + defURL string // default url + picSize int // picture size + fallbackHost string // default fallback URL + secureFallbackHost string // default fallback URL for secure connections + useHTTPS bool + nameCache map[cacheKey]cacheValue + nameCacheDuration time.Duration + minSize uint // smallest image dimension allowed + maxSize uint // largest image dimension allowed + size uint // what dimension should be used + serviceBase string // SRV record to be queried for federation + secureServiceBase string // SRV record to be queried for federation with secure servers +} + +// New instanciates a new Libravatar object (handle) +func New() *Libravatar { + // According to https://wiki.libravatar.org/running_your_own/ + // the time-to-live (cache expiry) should be set to at least 1 day. + return &Libravatar{ + fallbackHost: `cdn.libravatar.org`, + secureFallbackHost: `seccdn.libravatar.org`, + minSize: 1, + maxSize: 512, + size: 0, // unset, defaults to 80 + serviceBase: `avatars`, + secureServiceBase: `avatars-sec`, + nameCache: make(map[cacheKey]cacheValue), + nameCacheDuration: 24 * time.Hour, + } +} + +// SetFallbackHost sets the hostname for fallbacks in case no avatar +// service is defined for a domain +func (v *Libravatar) SetFallbackHost(host string) { + v.fallbackHost = host +} + +// SetSecureFallbackHost sets the hostname for fallbacks in case no +// avatar service is defined for a domain, when requiring secure domains +func (v *Libravatar) SetSecureFallbackHost(host string) { + v.secureFallbackHost = host +} + +// SetUseHTTPS sets flag requesting use of https for fetching avatars +func (v *Libravatar) SetUseHTTPS(use bool) { + v.useHTTPS = use +} + +// SetAvatarSize sets avatars image dimension (0 for default) +func (v *Libravatar) SetAvatarSize(size uint) { + v.size = size +} + +// generate hash, either with email address or OpenID +func (v *Libravatar) genHash(email *mail.Address, openid *url.URL) string { + if email != nil { + email.Address = strings.ToLower(strings.TrimSpace(email.Address)) + sum := md5.Sum([]byte(email.Address)) + return fmt.Sprintf("%x", sum) + } else if openid != nil { + openid.Scheme = strings.ToLower(openid.Scheme) + openid.Host = strings.ToLower(openid.Host) + sum := sha256.Sum256([]byte(openid.String())) + return fmt.Sprintf("%x", sum) + } + // panic, because this should not be reachable + panic("Neither Email or OpenID set") +} + +// Gets domain out of email or openid (for openid to be parsed, email has to be nil) +func (v *Libravatar) getDomain(email *mail.Address, openid *url.URL) string { + if email != nil { + u, err := url.Parse("//" + email.Address) + if err != nil { + if v.useHTTPS && v.secureFallbackHost != "" { + return v.secureFallbackHost + } + return v.fallbackHost + } + return u.Host + } else if openid != nil { + return openid.Host + } + // panic, because this should not be reachable + panic("Neither Email or OpenID set") +} + +// Processes email or openid (for openid to be processed, email has to be nil) +func (v *Libravatar) process(email *mail.Address, openid *url.URL) (string, error) { + URL, err := v.baseURL(email, openid) + if err != nil { + return "", err + } + res := fmt.Sprintf("%s/avatar/%s", URL, v.genHash(email, openid)) + + values := make(url.Values) + if v.defURL != "" { + values.Add("d", v.defURL) + } + if v.size > 0 { + values.Add("s", fmt.Sprintf("%d", v.size)) + } + + if len(values) > 0 { + return fmt.Sprintf("%s?%s", res, values.Encode()), nil + } + return res, nil +} + +// Finds or defaults a URL for Federation (for openid to be used, email has to be nil) +func (v *Libravatar) baseURL(email *mail.Address, openid *url.URL) (string, error) { + var service, protocol, domain string + + if v.useHTTPS { + protocol = "https://" + service = v.secureServiceBase + domain = v.secureFallbackHost + + } else { + protocol = "http://" + service = v.serviceBase + domain = v.fallbackHost + } + + host := v.getDomain(email, openid) + key := cacheKey{service, host} + now := time.Now() + val, found := v.nameCache[key] + if found && now.Sub(val.checkedAt) <= v.nameCacheDuration { + return protocol + val.target, nil + } + + _, addrs, err := net.LookupSRV(service, "tcp", host) + if err != nil && err.(*net.DNSError).IsTimeout { + return "", err + } + + if len(addrs) == 1 { + // select only record, if only one is available + domain = strings.TrimSuffix(addrs[0].Target, ".") + } else if len(addrs) > 1 { + // Select first record according to RFC2782 weight + // ordering algorithm (page 3) + + type record struct { + srv *net.SRV + weight uint16 + } + + var ( + totalWeight uint16 + records []record + topPriority = addrs[0].Priority + topRecord *net.SRV + ) + + for _, rr := range addrs { + if rr.Priority > topPriority { + continue + } else if rr.Priority < topPriority { + // won't happen, because net sorts + // by priority, but just in case + totalWeight = 0 + records = nil + topPriority = rr.Priority + } + + totalWeight += rr.Weight + + if rr.Weight > 0 { + records = append(records, record{rr, totalWeight}) + } else if rr.Weight == 0 { + records = append([]record{record{srv: rr, weight: totalWeight}}, records...) + } + } + + if len(records) == 1 { + topRecord = records[0].srv + } else { + randnum := uint16(rand.Intn(int(totalWeight))) + + for _, rr := range records { + if rr.weight >= randnum { + topRecord = rr.srv + break + } + } + } + + domain = fmt.Sprintf("%s:%d", topRecord.Target, topRecord.Port) + } + + v.nameCache[key] = cacheValue{checkedAt: now, target: domain} + return protocol + domain, nil +} + +// FromEmail returns the url of the avatar for the given email +func (v *Libravatar) FromEmail(email string) (string, error) { + addr, err := mail.ParseAddress(email) + if err != nil { + return "", err + } + + link, err := v.process(addr, nil) + if err != nil { + return "", err + } + + return link, nil +} + +// FromEmail is the object-less call to DefaultLibravatar for an email adders +func FromEmail(email string) (string, error) { + return DefaultLibravatar.FromEmail(email) +} + +// FromURL returns the url of the avatar for the given url (typically +// for OpenID) +func (v *Libravatar) FromURL(openid string) (string, error) { + ourl, err := url.Parse(openid) + if err != nil { + return "", err + } + + if !ourl.IsAbs() { + return "", fmt.Errorf("Is not an absolute URL") + } else if ourl.Scheme != "http" && ourl.Scheme != "https" { + return "", fmt.Errorf("Invalid protocol: %s", ourl.Scheme) + } + + link, err := v.process(nil, ourl) + if err != nil { + return "", err + } + + return link, nil +} + +// FromURL is the object-less call to DefaultLibravatar for a URL +func FromURL(openid string) (string, error) { + return DefaultLibravatar.FromURL(openid) +} diff --git a/vendor/github.com/gogs/minwinsvc/LICENSE b/vendor/github.com/gogs/minwinsvc/LICENSE new file mode 100644 index 00000000..fce91b4e --- /dev/null +++ b/vendor/github.com/gogs/minwinsvc/LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2015 Daniel Theophanes + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source + distribution. diff --git a/vendor/github.com/gogs/minwinsvc/README.md b/vendor/github.com/gogs/minwinsvc/README.md new file mode 100644 index 00000000..260dceea --- /dev/null +++ b/vendor/github.com/gogs/minwinsvc/README.md @@ -0,0 +1,18 @@ +### Minimal windows service stub + +Programs designed to run from most *nix style operating systems +can import this package to enable running programs as services without modifying +them. + +``` +import _ "github.com/kardianos/minwinsvc" +``` + +If you need more control over the exit behavior, set +``` +minwinsvc.SetOnExit(func() { + // Do something. + // Within 10 seconds call: + os.Exit(0) +}) +``` diff --git a/vendor/github.com/gogs/minwinsvc/minwinsvc.go b/vendor/github.com/gogs/minwinsvc/minwinsvc.go new file mode 100644 index 00000000..057ba7f9 --- /dev/null +++ b/vendor/github.com/gogs/minwinsvc/minwinsvc.go @@ -0,0 +1,18 @@ +// Copyright 2015 Daniel Theophanes. +// Use of this source code is governed by a zlib-style +// license that can be found in the LICENSE file.package service + +// Minimal non-invasive windows only service stub. +// +// Import to allow running as a windows service. +// import _ "github.com/kardianos/minwinsvc" +// This will detect if running as a windows service +// and install required callbacks for windows. +package minwinsvc + +// SetOnExit sets the function to be called when the windows service +// requests an exit. If this is not called, or if it is called where +// f == nil, then it defaults to calling "os.Exit(0)". +func SetOnExit(f func()) { + setOnExit(f) +} diff --git a/vendor/github.com/gogs/minwinsvc/svc_other.go b/vendor/github.com/gogs/minwinsvc/svc_other.go new file mode 100644 index 00000000..197d3002 --- /dev/null +++ b/vendor/github.com/gogs/minwinsvc/svc_other.go @@ -0,0 +1,11 @@ +// Copyright 2015 Daniel Theophanes. +// Use of this source code is governed by a zlib-style +// license that can be found in the LICENSE file.package service + +//+build !windows + +package minwinsvc + +func setOnExit(f func()) { + // Nothing. +} diff --git a/vendor/github.com/gogs/minwinsvc/svc_windows.go b/vendor/github.com/gogs/minwinsvc/svc_windows.go new file mode 100644 index 00000000..e79755fa --- /dev/null +++ b/vendor/github.com/gogs/minwinsvc/svc_windows.go @@ -0,0 +1,72 @@ +// Copyright 2015 Daniel Theophanes. +// Use of this source code is governed by a zlib-style +// license that can be found in the LICENSE file.package service + +//+build windows + +package minwinsvc + +import ( + "os" + "sync" + + "golang.org/x/sys/windows/svc" +) + +var ( + onExit func() + guard sync.Mutex +) + +func init() { + interactive, err := svc.IsAnInteractiveSession() + if err != nil { + panic(err) + } + // While run as Windows service, it is not an interactive session, + // but we don't want hook execute to be treated as service, e.g. gogs.exe hook pre-receive. + if interactive || len(os.Getenv("SSH_ORIGINAL_COMMAND")) > 0 { + return + } + go func() { + _ = svc.Run("", runner{}) + + guard.Lock() + f := onExit + guard.Unlock() + + // Don't hold this lock in user code. + if f != nil { + f() + } + // Make sure we exit. + os.Exit(0) + }() +} + +func setOnExit(f func()) { + guard.Lock() + onExit = f + guard.Unlock() +} + +type runner struct{} + +func (runner) Execute(args []string, r <-chan svc.ChangeRequest, changes chan<- svc.Status) (bool, uint32) { + const cmdsAccepted = svc.AcceptStop | svc.AcceptShutdown + changes <- svc.Status{State: svc.StartPending} + + changes <- svc.Status{State: svc.Running, Accepts: cmdsAccepted} + for { + c := <-r + switch c.Cmd { + case svc.Interrogate: + changes <- c.CurrentStatus + case svc.Stop, svc.Shutdown: + changes <- svc.Status{State: svc.StopPending} + return false, 0 + } + } + + return false, 0 +} -- cgit v1.2.3