github.com/gitbundle/modules@v0.0.0-20231025071548-85b91c5c3b01/setting/git.go (about)

     1  // Copyright 2023 The GitBundle Inc. All rights reserved.
     2  // Copyright 2017 The Gitea Authors. All rights reserved.
     3  // Use of this source code is governed by a MIT-style
     4  // license that can be found in the LICENSE file.
     5  
     6  package setting
     7  
     8  import (
     9  	"path/filepath"
    10  	"time"
    11  
    12  	"github.com/gitbundle/modules/log"
    13  )
    14  
    15  // Git settings
    16  var Git = struct {
    17  	Path                      string
    18  	HomePath                  string
    19  	DisableDiffHighlight      bool
    20  	MaxGitDiffLines           int
    21  	MaxGitDiffLineCharacters  int
    22  	MaxGitDiffFiles           int
    23  	CommitsRangeSize          int // CommitsRangeSize the default commits range size
    24  	BranchesRangeSize         int // BranchesRangeSize the default branches range size
    25  	VerbosePush               bool
    26  	VerbosePushDelay          time.Duration
    27  	GCArgs                    []string `ini:"GC_ARGS" delim:" "`
    28  	EnableAutoGitWireProtocol bool
    29  	PullRequestPushMessage    bool
    30  	LargeObjectThreshold      int64
    31  	DisableCoreProtectNTFS    bool
    32  	DisablePartialClone       bool
    33  	Timeout                   struct {
    34  		Default int
    35  		Migrate int
    36  		Mirror  int
    37  		Clone   int
    38  		Pull    int
    39  		GC      int `ini:"GC"`
    40  	} `ini:"git.timeout"`
    41  }{
    42  	DisableDiffHighlight:      false,
    43  	MaxGitDiffLines:           1000,
    44  	MaxGitDiffLineCharacters:  5000,
    45  	MaxGitDiffFiles:           100,
    46  	CommitsRangeSize:          50,
    47  	BranchesRangeSize:         20,
    48  	VerbosePush:               true,
    49  	VerbosePushDelay:          5 * time.Second,
    50  	GCArgs:                    []string{},
    51  	EnableAutoGitWireProtocol: true,
    52  	PullRequestPushMessage:    true,
    53  	LargeObjectThreshold:      1024 * 1024,
    54  	DisablePartialClone:       false,
    55  	Timeout: struct {
    56  		Default int
    57  		Migrate int
    58  		Mirror  int
    59  		Clone   int
    60  		Pull    int
    61  		GC      int `ini:"GC"`
    62  	}{
    63  		Default: 360,
    64  		Migrate: 600,
    65  		Mirror:  300,
    66  		Clone:   300,
    67  		Pull:    300,
    68  		GC:      60,
    69  	},
    70  }
    71  
    72  func newGit() {
    73  	sec := Cfg.Section("git")
    74  
    75  	if err := sec.MapTo(&Git); err != nil {
    76  		log.Fatal("Failed to map Git settings: %v", err)
    77  	}
    78  
    79  	Git.HomePath = sec.Key("HOME_PATH").MustString("home")
    80  	if !filepath.IsAbs(Git.HomePath) {
    81  		Git.HomePath = filepath.Join(AppDataPath, Git.HomePath)
    82  	} else {
    83  		Git.HomePath = filepath.Clean(Git.HomePath)
    84  	}
    85  }