package core /* Branch represents a named line of development. * Uses SVN-style global revision numbering - a branch is just a name, * revisions are still globally sequential (r123 on port, r124 on feature/x). */ type Branch struct { Name string `json:"name"` // "port", "feature/foo", "release/1.0" HeadRev int64 `json:"head_rev"` // current tip revision number CreatedAt int64 `json:"created_at"` // unix timestamp CreatedFrom int64 `json:"created_from"` // revision number this branch was created from } // DefaultBranchName is the default branch name (like SVN's trunk, but we call it "port") const DefaultBranchName = "port" // BranchNameValid checks if a branch name is valid func BranchNameValid(name string) bool { if len(name) == 0 || len(name) > 255 { return false } /* NOTE(kroot): branch names follow simple rules: * - no leading/trailing slashes * - no double slashes * - no special chars except / - _ . * - no reserved names */ for i, r := range name { switch { case r >= 'a' && r <= 'z': continue case r >= 'A' && r <= 'Z': continue case r >= '0' && r <= '9': continue case r == '-' || r == '_' || r == '.': continue case r == '/': /* no leading slash */ if i == 0 { return false } /* no trailing slash */ if i == len(name)-1 { return false } /* no double slashes */ if i > 0 && name[i-1] == '/' { return false } continue default: return false } } return true }