1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/oschina-git-repo-clean

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Клонировать/Скачать
git.go 2.7 КБ
Копировать Редактировать Web IDE Исходные данные Просмотреть построчно История
Li Linchao Отправлено 20.07.2022 05:40 c6cc9c5
package main
import (
"os"
"os/exec"
"path/filepath"
"github.com/cli/safeexec"
)
// Global OID and ID tables
var (
IDs = NewIDs()
ID_HASH = make(map[int32]string)
)
/*Ids*/
type Ids struct {
next_id int32
translations map[int32]int32
}
// create Ids object instance
func NewIDs() Ids {
return Ids{
next_id: 1,
translations: make(map[int32]int32),
}
}
// return current next_id, then next_id + 1
func (ids *Ids) New() int32 {
id := ids.next_id
ids.next_id += 1
return id
}
// record map: old_id => new_id
func (ids *Ids) record_rename(old_id, new_id int32) {
if old_id != new_id {
ids.translations[old_id] = new_id
}
}
func (ids Ids) has_renames() bool {
return len(ids.translations) == 0
}
// query from translations map, if find return new_id, else return old_id
func (ids *Ids) translate(old_id int32) int32 {
if new_id, ok := ids.translations[old_id]; ok {
return new_id
} else {
return old_id
}
}
// Git element basically contain type and dumped field
type GitElements struct {
types string
dumped bool
}
// return element types and dump status
func NewGitElement() GitElements {
return GitElements{
types: "none",
dumped: true, // true means to dump out, which is the default behavior
}
}
func (ele GitElements) skip() {
ele.dumped = false // false means to skip it
}
// base represents type and dumped,
// id represents int32 short mark id,
// old_id represents previous short mark id
type GitElementsWithID struct {
base *GitElements
id int32 // mark id
old_id int32 // previous mark id
}
// new Git element has new mark id, and its previous id is 0 as default,
// but will set properly on the other place
func NewGitElementsWithID() GitElementsWithID {
ele := NewGitElement()
return GitElementsWithID{
base: &ele,
id: IDs.New(),
old_id: 0, // mark id must > 0, so 0 just means it haven't initialized
}
}
func (ele GitElementsWithID) skip(new_id int32) {
ele.base.dumped = false
if ele.old_id != 0 {
IDs.record_rename(ele.old_id, new_id)
} else {
IDs.record_rename(ele.id, new_id)
}
}
func findGitBin() (string, error) {
gitBin, err := safeexec.LookPath("git")
if err != nil {
return "", err
}
gitBin, err = filepath.Abs(gitBin)
if err != nil {
return "", err
}
return gitBin, nil
}
func (repo Repository) GitCommand(callerArgs ...string) *exec.Cmd {
args := []string{
"--no-replace-objects",
"-c",
"advice.graftFileDeprecated=false",
"-C",
repo.context.workDir,
}
args = append(args, callerArgs...)
cmd := exec.Command(repo.context.gitBin, args...)
cmd.Env = append(
os.Environ(),
// "GIT_DIR"+repo.gitDir, // fix Windows issue
// Disable grafts when running our commands:
"GIT_GRAFT_FILE="+os.DevNull,
)
return cmd
}

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://api.gitlife.ru/oschina-mirror/oschina-git-repo-clean.git
git@api.gitlife.ru:oschina-mirror/oschina-git-repo-clean.git
oschina-mirror
oschina-git-repo-clean
oschina-git-repo-clean
main