diff options
author | Mario Lubenka <mario.lubenka@googlemail.com> | 2019-10-04 21:58:54 +0200 |
---|---|---|
committer | techknowlogick <techknowlogick@gitea.io> | 2019-10-04 15:58:54 -0400 |
commit | f92a0b68fed81128fa278e82aa0e3d49d74ffdf6 (patch) | |
tree | 41a6a7cd2a8a6153046851b5ab3a9c5aacb0cdfd /routers/repo/compare.go | |
parent | de8a0a3938e811ffaa6800a771d7f09fd6428608 (diff) | |
download | gitea-f92a0b68fed81128fa278e82aa0e3d49d74ffdf6.tar.gz gitea-f92a0b68fed81128fa278e82aa0e3d49d74ffdf6.zip |
Bugfix for image compare and minor improvements to image compare (#8289)
* Resolve error when comparing images
Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
* Check blob existence instead of git-ls when checking if file exists
Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
* Show file metadata also when a file was newly added
Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
* Fixes error in commit view
Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
* Excludes assigning path and image infos for compare routers to service package
Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
* Removes nil default and fixes import order
Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
* Adds missing comments
Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
* Moves methods for assigning compare data to context into repo router package
Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
* Show image compare for deleted images as well. Simplify check if image should be displayed
Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
Diffstat (limited to 'routers/repo/compare.go')
-rw-r--r-- | routers/repo/compare.go | 77 |
1 files changed, 42 insertions, 35 deletions
diff --git a/routers/repo/compare.go b/routers/repo/compare.go index 7c55dfca30..f8534f68b7 100644 --- a/routers/repo/compare.go +++ b/routers/repo/compare.go @@ -5,6 +5,7 @@ package repo import ( + "fmt" "path" "strings" @@ -21,6 +22,45 @@ const ( tplCompare base.TplName = "repo/diff/compare" ) +// setPathsCompareContext sets context data for source and raw paths +func setPathsCompareContext(ctx *context.Context, base *git.Commit, head *git.Commit, headTarget string) { + sourcePath := setting.AppSubURL + "/%s/src/commit/%s" + rawPath := setting.AppSubURL + "/%s/raw/commit/%s" + + ctx.Data["SourcePath"] = fmt.Sprintf(sourcePath, headTarget, head.ID) + ctx.Data["RawPath"] = fmt.Sprintf(rawPath, headTarget, head.ID) + if base != nil { + baseTarget := path.Join(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name) + ctx.Data["BeforeSourcePath"] = fmt.Sprintf(sourcePath, baseTarget, base.ID) + ctx.Data["BeforeRawPath"] = fmt.Sprintf(rawPath, baseTarget, base.ID) + } +} + +// setImageCompareContext sets context data that is required by image compare template +func setImageCompareContext(ctx *context.Context, base *git.Commit, head *git.Commit) { + ctx.Data["IsImageFileInHead"] = head.IsImageFile + ctx.Data["IsImageFileInBase"] = base.IsImageFile + ctx.Data["ImageInfoBase"] = func(name string) *git.ImageMetaData { + if base == nil { + return nil + } + result, err := base.ImageInfo(name) + if err != nil { + log.Error("ImageInfo failed: %v", err) + return nil + } + return result + } + ctx.Data["ImageInfo"] = func(name string) *git.ImageMetaData { + result, err := head.ImageInfo(name) + if err != nil { + log.Error("ImageInfo failed: %v", err) + return nil + } + return result + } +} + // ParseCompareInfo parse compare info between two commit for preparing comparing references func ParseCompareInfo(ctx *context.Context) (*models.User, *models.Repository, *git.Repository, *git.CompareInfo, string, string) { baseRepo := ctx.Repo.Repository @@ -291,43 +331,10 @@ func PrepareCompareDiff( ctx.Data["title"] = title ctx.Data["Username"] = headUser.Name ctx.Data["Reponame"] = headRepo.Name - ctx.Data["IsImageFile"] = headCommit.IsImageFile - ctx.Data["ImageInfo"] = func(name string) *git.ImageMetaData { - result, err := headCommit.ImageInfo(name) - if err != nil { - log.Error("ImageInfo failed: %v", err) - return nil - } - return result - } - ctx.Data["FileExistsInBaseCommit"] = func(filename string) bool { - result, err := baseCommit.HasFile(filename) - if err != nil { - log.Error( - "Error while checking if file \"%s\" exists in base commit \"%s\" (repo: %s): %v", - filename, - baseCommit, - baseGitRepo.Path, - err) - return false - } - return result - } - ctx.Data["ImageInfoBase"] = func(name string) *git.ImageMetaData { - result, err := baseCommit.ImageInfo(name) - if err != nil { - log.Error("ImageInfo failed: %v", err) - return nil - } - return result - } + setImageCompareContext(ctx, baseCommit, headCommit) headTarget := path.Join(headUser.Name, repo.Name) - baseTarget := path.Join(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name) - ctx.Data["SourcePath"] = setting.AppSubURL + "/" + path.Join(headTarget, "src", "commit", headCommitID) - ctx.Data["RawPath"] = setting.AppSubURL + "/" + path.Join(headTarget, "raw", "commit", headCommitID) - ctx.Data["BeforeSourcePath"] = setting.AppSubURL + "/" + path.Join(baseTarget, "src", "commit", baseCommitID) - ctx.Data["BeforeRawPath"] = setting.AppSubURL + "/" + path.Join(baseTarget, "raw", "commit", baseCommitID) + setPathsCompareContext(ctx, baseCommit, headCommit, headTarget) return false } |