Skip to content

Commit

Permalink
mr show: Output commit ID hash on commit comments
Browse files Browse the repository at this point in the history
Output the commid ID hash on commit comments.

Note: The behavior of note.Position.BaseSHA has changed to point to the
commit just before the commented on commit, and note.Position.HeadSHA
has changed to point to the commented on commit.  This gives the ability
to output not only the commid ID hash, but the proper diff.

Signed-off-by: Prarit Bhargava <[email protected]>
  • Loading branch information
prarit committed Jul 1, 2021
1 parent f6b2f82 commit 66a1a41
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions cmd/show_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,17 @@ func displayDiff(diff string, chunkNum int, newLine int, oldLine int) {

func displayCommitDiscussion(idNum int, note *gitlab.Note) {

// The GitLab API only supports showing comments on the entire
// changeset and not per-commit. IOW, all diffs are shown against
// HEAD. This is confusing in some scenarios, however it's what the
// API provides.
// Previously, the GitLab API only supports showing comments on the
// entire changeset and not per-commit. IOW, all diffs were shown
// against HEAD. This was confusing in some scenarios, however it
// was what the API provided.
//
// At some point, note.Position.HeadSHA was changed to report the
// commit that was being commented on, and note.Position.BaseSHA
// points to the commit just before it. I cannot find the GitLab
// commit that changed this behaviour but it has changed.
//
// I am leaving this comment here in case it ever changes again.

// Get a unified diff for the entire file
diff, err := git.GetUnifiedDiff(note.Position.BaseSHA, note.Position.HeadSHA, note.Position.OldPath, note.Position.NewPath)
Expand All @@ -139,8 +146,10 @@ func displayCommitDiscussion(idNum int, note *gitlab.Note) {
// In general, only have to display the NewPath, however there
// are some unusual cases where the OldPath may be displayed
if note.Position.NewPath == note.Position.OldPath {
fmt.Println("commit:" + note.Position.HeadSHA)
fmt.Println("File:" + note.Position.NewPath)
} else {
fmt.Println("commit:" + note.Position.HeadSHA)
fmt.Println("Files[old:" + note.Position.OldPath + " new:" + note.Position.NewPath + "]")
}

Expand Down

0 comments on commit 66a1a41

Please sign in to comment.