MCPcopy Create free account
hub / github.com/git-bug/git-bug / runBridgePull

Function runBridgePull

commands/bridge/bridge_pull.go:49–145  ·  view source on GitHub ↗
(env *execenv.Env, opts bridgePullOptions, args []string)

Source from the content-addressed store, hash-verified

47}
48
49func runBridgePull(env *execenv.Env, opts bridgePullOptions, args []string) error {
50 if opts.noResume && opts.importSince != "" {
51 return fmt.Errorf("only one of --no-resume and --since flags should be used")
52 }
53
54 var b *core.Bridge
55 var err error
56
57 if len(args) == 0 {
58 b, err = bridge.DefaultBridge(env.Backend)
59 } else {
60 b, err = bridge.LoadBridge(env.Backend, args[0])
61 }
62
63 if err != nil {
64 return err
65 }
66
67 parentCtx := context.Background()
68 ctx, cancel := context.WithCancel(parentCtx)
69 defer cancel()
70
71 // buffered channel to avoid send block at the end
72 done := make(chan struct{}, 1)
73
74 var mu sync.Mutex
75 interruptCount := 0
76 interrupt.RegisterCleaner(func() error {
77 mu.Lock()
78 if interruptCount > 0 {
79 env.Err.Println("Received another interrupt before graceful stop, terminating...")
80 os.Exit(0)
81 }
82
83 interruptCount++
84 mu.Unlock()
85
86 env.Err.Println("Received interrupt signal, stopping the import...\n(Hit ctrl-c again to kill the process.)")
87
88 // send signal to stop the importer
89 cancel()
90
91 // block until importer gracefully shutdown
92 <-done
93 return nil
94 })
95
96 var events <-chan core.ImportResult
97 switch {
98 case opts.noResume:
99 events, err = b.ImportAllSince(ctx, time.Time{})
100 case opts.importSince != "":
101 since, err2 := parseSince(opts.importSince)
102 if err2 != nil {
103 return errors.Wrap(err2, "import time parsing")
104 }
105 events, err = b.ImportAllSince(ctx, since)
106 default:

Callers 1

newBridgePullCommandFunction · 0.85

Calls 12

ImportAllSinceMethod · 0.95
ImportAllMethod · 0.95
DefaultBridgeFunction · 0.92
LoadBridgeFunction · 0.92
RegisterCleanerFunction · 0.92
parseSinceFunction · 0.85
closeFunction · 0.85
ErrorfMethod · 0.80
LockMethod · 0.65
PrintlnMethod · 0.65
StringMethod · 0.65
PrintfMethod · 0.65

Tested by

no test coverage detected