Skip to content

Commit

Permalink
CopyCommitReference: use authorTime of commits
Browse files Browse the repository at this point in the history
As per documentation of 'git log':

    reference

    <abbrev-hash> (<title-line>, <short-author-date>)

    This format is used to refer to another commit in a commit message
    and is the same as --pretty='format:%C(auto)%h (%s, %ad)'. By default,
    the date is formatted with --date=short unless another --date option is
    explicitly specified. As with any format: with format placeholders, its
    output is not affected by other options like --decorate and
    --walk-reflogs.

the format 'reference' specifically shows the "author date" of a commit,
as opposed to "commit date".[1]  By default 'git log' shows the author
date, and that's why 'reference' format uses the author date as well.

Function `commitReference` in CopyCommitReference.kt uses method
getTimestamp of interface com.intellij.vcs.log.graph.GraphCommit via
intrerface com.intellij.vcs.log.VcsCommitMetadata.  All implementations
of this interface use commit date for the timestamp, which means that
the plugin can produce misleading dates in the references.

Use method `getAuthorTime` of com.intellij.vcs.log.VcsShortCommitDetails
to include the correct date in the references produced by the plugin.

[1] These dates can be different, for example, if a commit is
    cherry-picked a week after it had been authored, i.e. created.
  • Loading branch information
rybak committed Aug 10, 2023
1 parent be8c627 commit 2e94095
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
## [Unreleased]

### Fixed
- The plugin sometimes produced references with a slightly incorrect date, which has been corrected.
- Incorrect usage of background thread has been fixed to reduce probability of concurrency issues in context menu of annotations.

## [1.1.0] - 2023-07-30
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fun copyCommitReference(project: Project, listOfMetadata: List<VcsCommitMetadata
}

private fun commitReference(metadata: VcsCommitMetadata): String {
return commitReference(metadata.id.asString(), metadata.subject, Instant.ofEpochMilli(metadata.timestamp))
return commitReference(metadata.id.asString(), metadata.subject, Instant.ofEpochMilli(metadata.authorTime))
}

private fun commitReference(hash: String, subject: String, timestamp: Instant): String {
Expand Down

0 comments on commit 2e94095

Please sign in to comment.