diff --git a/api/http/git_raw_handler.go b/api/http/git_raw_handler.go deleted file mode 100644 index 285f4bc6deac1e771b464ed0923d2da0957331bc..0000000000000000000000000000000000000000 --- a/api/http/git_raw_handler.go +++ /dev/null @@ -1,66 +0,0 @@ -package http - -import ( - "bytes" - "io" - "net/http" - "time" - - "github.com/gorilla/mux" - - "github.com/git-bug/git-bug/cache" -) - -// Serves raw blob content resolved by ref and path, e.g. -// /gitraw/{repo}/{ref}/{path:.*} -// -// This is used by the web UI to render images referenced in markdown -// files (READMEs etc.) without needing to know the blob hash upfront. -type gitRawHandler struct { - mrc *cache.MultiRepoCache -} - -func NewGitRawHandler(mrc *cache.MultiRepoCache) http.Handler { - return &gitRawHandler{mrc: mrc} -} - -func (h *gitRawHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request) { - var repo *cache.RepoCache - var err error - - repoVar := mux.Vars(r)["repo"] - if repoVar == "_" { - repo, err = h.mrc.DefaultRepo() - } else { - repo, err = h.mrc.ResolveRepo(repoVar) - } - if err != nil { - http.Error(rw, "invalid repo reference", http.StatusBadRequest) - return - } - - ref := mux.Vars(r)["ref"] - path := mux.Vars(r)["path"] - - if ref == "" || path == "" { - http.Error(rw, "ref and path are required", http.StatusBadRequest) - return - } - - rc, _, _, err := repo.BlobAtPath(ref, path) - if err != nil { - http.Error(rw, "file not found", http.StatusNotFound) - return - } - defer rc.Close() - - data, err := io.ReadAll(rc) - if err != nil { - http.Error(rw, err.Error(), http.StatusInternalServerError) - return - } - - // ServeContent handles Content-Type detection from the file extension, - // Range requests, and caching headers. - http.ServeContent(rw, r, path, time.Now(), bytes.NewReader(data)) -} diff --git a/cache/repo_cache.go b/cache/repo_cache.go index 8c69006955975da5326718165773fa57149a5867..c43cc0a1c7cd15066f699e0d0c3776f447954bab 100644 --- a/cache/repo_cache.go +++ b/cache/repo_cache.go @@ -41,7 +41,6 @@ type cacheMgmt interface { RegisterObserver(repoName string, observer Observer) UnregisterObserver(observer Observer) Close() error - SyncLocalRef(id entity.Id) error } // RepoCache is a cache for a Repository. This cache has multiple functions: diff --git a/cache/repo_cache_common.go b/cache/repo_cache_common.go index 5ed9e7a3b47b1055c7e18ecf831b53edf3e02da3..9abd9818bdfe1ca8a9bebdbbd0a57cf3b19ea393 100644 --- a/cache/repo_cache_common.go +++ b/cache/repo_cache_common.go @@ -2,7 +2,6 @@ package cache import ( "io" - "strings" "sync" "github.com/pkg/errors" @@ -82,13 +81,6 @@ func (c *RepoCache) ReadData(hash repository.Hash) (io.ReadCloser, error) { return c.repo.ReadData(hash) } -// BlobAtPath returns the raw content, byte size, and git object hash of the -// file at the given path within the tree of the given ref. -func (c *RepoCache) BlobAtPath(ref, path string) (io.ReadCloser, int64, repository.Hash, error) { - return c.repo.BlobAtPath(ref, path) -} - - // StoreData will store arbitrary data and return the corresponding hash func (c *RepoCache) StoreData(data []byte) (repository.Hash, error) { return c.repo.StoreData(data) @@ -254,22 +246,3 @@ func (c *RepoCache) GetUserIdentityExcerpt() (*IdentityExcerpt, error) { func (c *RepoCache) IsUserIdentitySet() (bool, error) { return identity.IsUserIdentitySet(c.repo) } - -// SyncLocalRefs updates the cache for each ref that was updated externally -// (e.g. after a git push). Each ref is matched against the subcaches by -// namespace and the corresponding entity is re-read from git. -func (c *RepoCache) SyncLocalRefs(refs []string) error { - for _, ref := range refs { - id := entity.RefToId(ref) - for _, subcache := range c.subcaches { - ns := subcache.GetNamespace() - if strings.Contains(ref, "/"+ns+"/") { - if err := subcache.SyncLocalRef(id); err != nil { - return err - } - break - } - } - } - return nil -} diff --git a/cache/subcache.go b/cache/subcache.go index 27b06890177247873d174d7d585dff4578eee516..c9aa5f68444d632dd2d951119d90e0760eb54626 100644 --- a/cache/subcache.go +++ b/cache/subcache.go @@ -613,9 +613,6 @@ func (sc *SubCache[EntityT, ExcerptT, CacheT]) MergeAll(remote string) <-chan en sc.cached[result.Id] = cached sc.mu.Unlock() sc.notifyObservers(EntityEventUpdated, result.Id) - - default: - // nothing } } @@ -680,50 +677,6 @@ func (sc *SubCache[EntityT, ExcerptT, CacheT]) updateExcerptAndIndex(id entity.I return sc.write() } -// SyncLocalRef re-reads the entity with the given id from git and updates the -// in-memory cache, search index, and on-disk excerpt cache. It is used to -// refresh an entity after its git ref was updated externally (e.g. by a push). -func (sc *SubCache[EntityT, ExcerptT, CacheT]) SyncLocalRef(id entity.Id) error { - sc.mu.Lock() - _, existed := sc.excerpts[id] - delete(sc.cached, id) - sc.lru.Remove(id) - sc.mu.Unlock() - - e, err := sc.actions.ReadWithResolver(sc.repo, sc.resolvers(), id) - if err != nil { - return err - } - - cached := sc.makeCached(e, sc.entityUpdated) - - sc.mu.Lock() - sc.excerpts[id] = sc.makeExcerpt(cached) - sc.cached[id] = cached - sc.lru.Add(id) - sc.mu.Unlock() - - sc.evictIfNeeded() - - index, err := sc.repo.GetIndex(sc.namespace) - if err != nil { - return err - } - if err = index.IndexOne(id.String(), sc.makeIndexData(cached)); err != nil { - return err - } - if err = sc.write(); err != nil { - return err - } - - if existed { - sc.notifyObservers(EntityEventUpdated, id) - } else { - sc.notifyObservers(EntityEventCreated, id) - } - return nil -} - // evictIfNeeded will evict an entity from the cache if needed func (sc *SubCache[EntityT, ExcerptT, CacheT]) evictIfNeeded() { sc.mu.Lock() diff --git a/repository/gogit.go b/repository/gogit.go index d5aea49995269dd7302874020284589b82043c56..1403eb8c196fddfe4be7e6aa979481246bb91a45 100644 --- a/repository/gogit.go +++ b/repository/gogit.go @@ -848,8 +848,6 @@ func (repo *GoGitRepo) ReadCommit(hash Hash) (Commit, error) { return result, nil } -var _ RepoBrowse = &GoGitRepo{} - func (repo *GoGitRepo) AllClocks() (map[string]lamport.Clock, error) { repo.clocksMutex.Lock() defer repo.clocksMutex.Unlock() diff --git a/repository/mock_repo.go b/repository/mock_repo.go index 121c09e96ce92922bac5e6c23173279a6e94b707..e13e18cfdfc2b314885c4513c60f5900fd3cc8dd 100644 --- a/repository/mock_repo.go +++ b/repository/mock_repo.go @@ -121,7 +121,6 @@ func (r *mockRepoCommon) GetRemotes() (map[string]string, error) { }, nil } - var _ RepoStorage = &mockRepoStorage{} type mockRepoStorage struct { diff --git a/repository/repo.go b/repository/repo.go index 3a9d0ddf639a707c795c45b7e491b55bc442dc9a..e081038a0d285304ba0c095e6c9a201aa6abdf6c 100644 --- a/repository/repo.go +++ b/repository/repo.go @@ -76,7 +76,6 @@ type RepoCommon interface { // GetRemotes returns the configured remotes repositories. GetRemotes() (map[string]string, error) - } type LocalStorage interface {