aboutsummaryrefslogtreecommitdiff
path: root/models
diff options
context:
space:
mode:
Diffstat (limited to 'models')
-rw-r--r--models/git_diff.go61
-rw-r--r--models/pull.go8
-rw-r--r--models/repo.go2
-rw-r--r--models/user.go7
-rw-r--r--models/webhook.go2
5 files changed, 46 insertions, 34 deletions
diff --git a/models/git_diff.go b/models/git_diff.go
index 1913ec46..e8bfe610 100644
--- a/models/git_diff.go
+++ b/models/git_diff.go
@@ -51,7 +51,6 @@ type DiffLine struct {
RightIdx int
Type DiffLineType
Content string
- ParsedContent template.HTML
}
func (d *DiffLine) GetType() int {
@@ -112,42 +111,42 @@ func (diffSection *DiffSection) GetLine(lineType DiffLineType, idx int) *DiffLin
return nil
}
-// computes diff of each diff line and set the HTML on diffLine.ParsedContent
-func (diffSection *DiffSection) ComputeLinesDiff() {
- for _, diffLine := range diffSection.Lines {
- var compareDiffLine *DiffLine
- var diff1, diff2 string
+// computes inline diff for the given line
+func (diffSection *DiffSection) GetComputedInlineDiffFor(diffLine *DiffLine) template.HTML {
+ var compareDiffLine *DiffLine
+ var diff1, diff2 string
- diffLine.ParsedContent = template.HTML(html.EscapeString(diffLine.Content[1:]))
+ getDefaultReturn := func() template.HTML {
+ return template.HTML(html.EscapeString(diffLine.Content[1:]))
+ }
- // just compute diff for adds and removes
- if diffLine.Type != DIFF_LINE_ADD && diffLine.Type != DIFF_LINE_DEL {
- continue
- }
+ // just compute diff for adds and removes
+ if diffLine.Type != DIFF_LINE_ADD && diffLine.Type != DIFF_LINE_DEL {
+ return getDefaultReturn()
+ }
- // try to find equivalent diff line. ignore, otherwise
- if diffLine.Type == DIFF_LINE_ADD {
- compareDiffLine = diffSection.GetLine(DIFF_LINE_DEL, diffLine.RightIdx)
- if compareDiffLine == nil {
- continue
- }
- diff1 = compareDiffLine.Content
- diff2 = diffLine.Content
- } else {
- compareDiffLine = diffSection.GetLine(DIFF_LINE_ADD, diffLine.LeftIdx)
- if compareDiffLine == nil {
- continue
- }
- diff1 = diffLine.Content
- diff2 = compareDiffLine.Content
+ // try to find equivalent diff line. ignore, otherwise
+ if diffLine.Type == DIFF_LINE_ADD {
+ compareDiffLine = diffSection.GetLine(DIFF_LINE_DEL, diffLine.RightIdx)
+ if compareDiffLine == nil {
+ return getDefaultReturn()
+ }
+ diff1 = compareDiffLine.Content
+ diff2 = diffLine.Content
+ } else {
+ compareDiffLine = diffSection.GetLine(DIFF_LINE_ADD, diffLine.LeftIdx)
+ if compareDiffLine == nil {
+ return getDefaultReturn()
}
+ diff1 = diffLine.Content
+ diff2 = compareDiffLine.Content
+ }
- dmp := diffmatchpatch.New()
- diffRecord := dmp.DiffMain(diff1[1:], diff2[1:], true)
- diffRecord = dmp.DiffCleanupSemantic(diffRecord)
+ dmp := diffmatchpatch.New()
+ diffRecord := dmp.DiffMain(diff1[1:], diff2[1:], true)
+ diffRecord = dmp.DiffCleanupSemantic(diffRecord)
- diffLine.ParsedContent = diffToHTML(diffRecord, diffLine.Type)
- }
+ return diffToHTML(diffRecord, diffLine.Type)
}
type DiffFile struct {
diff --git a/models/pull.go b/models/pull.go
index 8497285e..47d80473 100644
--- a/models/pull.go
+++ b/models/pull.go
@@ -525,6 +525,14 @@ func AddTestPullRequestTask(repoID int64, branch string) {
}
}
+func ChangeUsernameInPullRequests(oldUserName, newUserName string) error {
+ pr := PullRequest{
+ HeadUserName: strings.ToLower(newUserName),
+ }
+ _, err := x.Cols("head_user_name").Where("head_user_name = ?", strings.ToLower(oldUserName)).Update(pr)
+ return err
+}
+
// checkAndUpdateStatus checks if pull request is possible to levaing checking status,
// and set to be either conflict or mergeable.
func (pr *PullRequest) checkAndUpdateStatus() {
diff --git a/models/repo.go b/models/repo.go
index e53d8065..8ce1f719 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -1602,7 +1602,7 @@ func GitFsck() {
repo := bean.(*Repository)
repoPath := repo.RepoPath()
if err := git.Fsck(repoPath, setting.Cron.RepoHealthCheck.Timeout, setting.Cron.RepoHealthCheck.Args...); err != nil {
- desc := fmt.Sprintf("Fail to health check repository(%s)", repoPath)
+ desc := fmt.Sprintf("Fail to health check repository (%s): %v", repoPath, err)
log.Warn(desc)
if err = CreateRepositoryNotice(desc); err != nil {
log.Error(4, "CreateRepositoryNotice: %v", err)
diff --git a/models/user.go b/models/user.go
index 5c43a23a..31ac1e22 100644
--- a/models/user.go
+++ b/models/user.go
@@ -599,7 +599,12 @@ func ChangeUserName(u *User, newUserName string) (err error) {
return ErrUserAlreadyExist{newUserName}
}
- return os.Rename(UserPath(u.LowerName), UserPath(newUserName))
+ err = ChangeUsernameInPullRequests(u.Name, newUserName)
+ if err != nil {
+ return fmt.Errorf("ChangeUsernameInPullRequests: %v", err)
+ }
+
+ return os.Rename(UserPath(u.Name), UserPath(newUserName))
}
func updateUser(e Engine, u *User) error {
diff --git a/models/webhook.go b/models/webhook.go
index f58cfbf5..27ac75fe 100644
--- a/models/webhook.go
+++ b/models/webhook.go
@@ -285,7 +285,7 @@ type HookTask struct {
HookID int64
UUID string
Type HookTaskType
- URL string
+ URL string `xorm:"TEXT"`
api.Payloader `xorm:"-"`
PayloadContent string `xorm:"TEXT"`
ContentType HookContentType