2018-03-22 16:40:33 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2018-06-01 05:20:49 +02:00
|
|
|
"fmt"
|
2018-08-02 17:05:43 +02:00
|
|
|
"sync"
|
2018-03-22 16:40:33 +01:00
|
|
|
"unicode"
|
|
|
|
)
|
|
|
|
|
2018-05-31 21:31:45 +02:00
|
|
|
const gitEmptyTree = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
|
|
|
|
|
2018-05-08 00:01:39 +02:00
|
|
|
type mapStringSet map[string]stringSet
|
|
|
|
|
2018-03-22 16:40:33 +01:00
|
|
|
type intRange struct {
|
|
|
|
min int
|
|
|
|
max int
|
|
|
|
}
|
|
|
|
|
|
|
|
func makeIntRange(min, max int) intRange {
|
|
|
|
return intRange{
|
|
|
|
min,
|
|
|
|
max,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r intRange) get(n int) bool {
|
|
|
|
return n >= r.min && n <= r.max
|
|
|
|
}
|
|
|
|
|
|
|
|
type intRanges []intRange
|
|
|
|
|
|
|
|
func (rs intRanges) get(n int) bool {
|
|
|
|
for _, r := range rs {
|
|
|
|
if r.get(n) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func min(a, b int) int {
|
|
|
|
if a < b {
|
|
|
|
return a
|
|
|
|
}
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
|
|
|
func max(a, b int) int {
|
|
|
|
if a < b {
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
return a
|
|
|
|
}
|
|
|
|
|
2018-05-08 00:01:39 +02:00
|
|
|
func (mss mapStringSet) Add(n string, v string) {
|
|
|
|
_, ok := mss[n]
|
2018-03-22 16:40:33 +01:00
|
|
|
if !ok {
|
2018-05-08 00:01:39 +02:00
|
|
|
mss[n] = make(stringSet)
|
2018-03-22 16:40:33 +01:00
|
|
|
}
|
2018-05-08 00:01:39 +02:00
|
|
|
mss[n].set(v)
|
2018-03-22 16:40:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func lessRunes(iRunes, jRunes []rune) bool {
|
|
|
|
max := len(iRunes)
|
|
|
|
if max > len(jRunes) {
|
|
|
|
max = len(jRunes)
|
|
|
|
}
|
|
|
|
|
|
|
|
for idx := 0; idx < max; idx++ {
|
|
|
|
ir := iRunes[idx]
|
|
|
|
jr := jRunes[idx]
|
|
|
|
|
|
|
|
lir := unicode.ToLower(ir)
|
|
|
|
ljr := unicode.ToLower(jr)
|
|
|
|
|
|
|
|
if lir != ljr {
|
|
|
|
return lir < ljr
|
|
|
|
}
|
|
|
|
|
|
|
|
// the lowercase runes are the same, so compare the original
|
|
|
|
if ir != jr {
|
|
|
|
return ir < jr
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return len(iRunes) < len(jRunes)
|
|
|
|
}
|
2018-05-08 06:06:25 +02:00
|
|
|
|
|
|
|
func stringSliceEqual(a, b []string) bool {
|
|
|
|
if a == nil && b == nil {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if a == nil || b == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(a) != len(b) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := 0; i < len(a); i++ {
|
|
|
|
if a[i] != b[i] {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
2018-06-01 05:20:49 +02:00
|
|
|
|
|
|
|
func removeInvalidTargets(targets []string) []string {
|
|
|
|
filteredTargets := make([]string, 0)
|
|
|
|
|
|
|
|
for _, target := range targets {
|
2019-02-04 17:56:02 +01:00
|
|
|
db, _ := splitDBFromName(target)
|
2018-06-01 05:20:49 +02:00
|
|
|
|
2018-09-14 21:18:59 +02:00
|
|
|
if db == "aur" && mode == modeRepo {
|
2018-06-01 05:20:49 +02:00
|
|
|
fmt.Printf("%s %s %s\n", bold(yellow(arrow)), cyan(target), bold("Can't use target with option --repo -- skipping"))
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2018-09-14 21:18:59 +02:00
|
|
|
if db != "aur" && db != "" && mode == modeAUR {
|
2018-06-01 05:20:49 +02:00
|
|
|
fmt.Printf("%s %s %s\n", bold(yellow(arrow)), cyan(target), bold("Can't use target with option --aur -- skipping"))
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
filteredTargets = append(filteredTargets, target)
|
|
|
|
}
|
|
|
|
|
|
|
|
return filteredTargets
|
|
|
|
}
|
2018-08-02 17:05:43 +02:00
|
|
|
|
|
|
|
type MultiError struct {
|
|
|
|
Errors []error
|
|
|
|
mux sync.Mutex
|
|
|
|
}
|
|
|
|
|
|
|
|
func (err *MultiError) Error() string {
|
|
|
|
str := ""
|
|
|
|
|
|
|
|
for _, e := range err.Errors {
|
2018-08-18 07:33:44 +02:00
|
|
|
str += e.Error() + "\n"
|
2018-08-02 17:05:43 +02:00
|
|
|
}
|
|
|
|
|
2018-08-18 07:33:44 +02:00
|
|
|
return str[:len(str)-1]
|
2018-08-02 17:05:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (err *MultiError) Add(e error) {
|
|
|
|
if e == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
err.mux.Lock()
|
|
|
|
err.Errors = append(err.Errors, e)
|
|
|
|
err.mux.Unlock()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (err *MultiError) Return() error {
|
|
|
|
if len(err.Errors) > 0 {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|