Skip to content

Commit

Permalink
fix: parsing git timestamp offsets
Browse files Browse the repository at this point in the history
When git reports its timestamp, its localized with the provided offset
and as chalk wasnt accounting for that, in some cases, commit timestamps
would show up as future timestamps which is very confusing

Now all timestamps are normalized with the provided offset.

In addition all date reporting was changed to use consistent output
format of ISO-8601.
  • Loading branch information
miki725 committed Dec 10, 2024
1 parent c5ada18 commit d3c3b11
Show file tree
Hide file tree
Showing 11 changed files with 242 additions and 101 deletions.
9 changes: 7 additions & 2 deletions src/chalk_common.nim
Original file line number Diff line number Diff line change
Expand Up @@ -455,13 +455,18 @@ const
techStackConfig* = staticRead(techStackConfName)
linguistConfig* = staticRead(linguistConfName)
ioConfig* = staticRead(ioConfName)
defaultConfig* = staticRead(defCfgFname) #& commentC4mCode(ioConfig)
defaultConfig* = staticRead(defCfgFname)
attestConfig* = staticRead(attestConfName)
coConfig* = staticRead(coConfName)
commitID* = staticexec("git rev-parse HEAD")
commitID* = staticexec("git log -n1 --pretty=format:%H")
archStr* = staticexec("uname -m")
osStr* = staticexec("uname -o")
stdinIndicator* = ":stdin:"
# various time formats
timesDateFormat* = "yyyy-MM-dd"
timesTimeFormat* = "HH:mm:ss'.'fff"
timesTzFormat* = "zzz"
timesIso8601Format* = timesDateFormat & "'T'" & timesTimeFormat & timesTzFormat

# Make sure that ARTIFACT_TYPE fields are consistently named. I'd love
# these to be const, but nim doesn't seem to be able to handle that :(
Expand Down
97 changes: 91 additions & 6 deletions src/configs/base_keyspecs.c4m
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,22 @@ keyspec DATE_AUTHORED {
since: "0.1.2"
shortdoc: "Human readable timestamp of the author's commit"
doc: """
The date of the authored commit in the same format as `git log`: 3-letter week-day, 3-letter month, day of month, HH:mm:ss <time-zone-offset>
The date when commit was authored as full ISO-8601 string.
Note that git commit and author dates might be different.
For example `git rebase` adjusts dates.
"""
}

keyspec TIMESTAMP_AUTHORED {
kind: ChalkTimeArtifact
type: string
standard: true
since: "0.4.15"
shortdoc: "Unix timestamp of the author's commit"
doc: """
The date when commit was authored as ms since Unix epoch.
Note that git commit and author dates might be different.
For example `git rebase` adjusts dates.
"""
}

Expand All @@ -718,7 +733,22 @@ keyspec DATE_COMMITTED {
since: "0.1.2"
shortdoc: "Human readable timestamp of most recent commit"
doc: """
The date of the authored commit in the same format as `git log`: 3-letter week-day, 3-letter month, day of month, HH:mm:ss <time-zone-offset>
The date when commit was created as full ISO-8601 string.
Note that git commit and author dates might be different.
For example `git rebase` adjusts dates.
"""
}

keyspec TIMESTAMP_COMMITTED {
kind: ChalkTimeArtifact
type: string
standard: true
since: "0.1.2"
shortdoc: "Unix timestamp of most recent commit"
doc: """
The date when commit was created as ms since Unix epoch.
Note that git commit and author dates might be different.
For example `git rebase` adjusts dates.
"""
}

Expand Down Expand Up @@ -794,12 +824,24 @@ keyspec DATE_TAGGED {
since: "0.3.0"
shortdoc: "Human readable timestamp of most recent tag"
doc: """
The date of the annotated tag in the same format as `git log`: 3-letter week-day, 3-letter month, day of month, HH:mm:ss <time-zone-offset>
The date when the annotated was created as full ISO-8601 string.

Annotated tags are created with `git tag -a -m "comment"`.
"""
}

keyspec TIMESTAMP_TAGGED {
kind: ChalkTimeArtifact
type: string
standard: true
since: "0.4.15"
shortdoc: "Unix timestamp of most recent tag"
doc: """
The date when the annotated was created in ms since Unix epoch.

Annotated tags are created with `git tag -a -m "comment"`.
"""
}
keyspec TAG_MESSAGE {
kind: ChalkTimeArtifact
type: string
Expand Down Expand Up @@ -872,7 +914,22 @@ keyspec _DATE_AUTHORED {
since: "0.4.0"
shortdoc: "Human readable timestamp of the author's commit"
doc: """
The date of the authored commit in the same format as `git log`: 3-letter week-day, 3-letter month, day of month, HH:mm:ss <time-zone-offset>
The date when commit was authored as full ISO-8601 string.
Note that git commit and author dates might be different.
For example `git rebase` adjusts dates.
"""
}

keyspec _TIMESTAMP_AUTHORED {
kind: RunTimeHost
type: string
standard: true
since: "0.4.15"
shortdoc: "Unix timestamp of the author's commit"
doc: """
The date when commit was authored as ms since Unix epoch.
Note that git commit and author dates might be different.
For example `git rebase` adjusts dates.
"""
}

Expand All @@ -894,7 +951,22 @@ keyspec _DATE_COMMITTED {
since: "0.4.0"
shortdoc: "Human readable timestamp of most recent commit"
doc: """
The date of the authored commit in the same format as `git log`: 3-letter week-day, 3-letter month, day of month, HH:mm:ss <time-zone-offset>
The date when commit was created as full ISO-8601 string.
Note that git commit and author dates might be different.
For example `git rebase` adjusts dates.
"""
}

keyspec _TIMESTAMP_COMMITTED {
kind: RunTimeHost
type: string
standard: true
since: "0.4.15"
shortdoc: "Unix timestamp of most recent commit"
doc: """
The date when commit was created as ms since Unix epoch.
Note that git commit and author dates might be different.
For example `git rebase` adjusts dates.
"""
}

Expand Down Expand Up @@ -976,6 +1048,19 @@ Annotated tags are created with `git tag -a -m "comment"`.
"""
}

keyspec _TIMESTAMP_TAGGED {
kind: RunTimeHost
type: string
standard: true
since: "0.4.15"
shortdoc: "Unix timestamp of most recent tag"
doc: """
The date when the annotated was created in ms since Unix epoch.

Annotated tags are created with `git tag -a -m "comment"`.
"""
}

keyspec _TAG_MESSAGE {
kind: RunTimeHost
type: string
Expand Down Expand Up @@ -5891,7 +5976,7 @@ keyspec _CHALK_RUN_TIME {
doc: """
Calculates the amount of time between the start of a chalk executable
and when a report is generated. It's an integer with resolution of
1/1000000th of a second.
1e-6 of a second (millisecond).
"""
}

Expand Down
12 changes: 6 additions & 6 deletions src/configs/base_plugins.c4m
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ plugin vctl_git {
enabled: true
pre_chalk_keys: ["COMMIT_ID", "COMMIT_SIGNED",
"BRANCH", "ORIGIN_URI",
"AUTHOR", "DATE_AUTHORED",
"COMMITTER", "DATE_COMMITTED", "COMMIT_MESSAGE",
"TAG", "TAG_SIGNED", "TAGGER", "DATE_TAGGED",
"AUTHOR", "DATE_AUTHORED", "TIMESTAMP_AUTHORED",
"COMMITTER", "DATE_COMMITTED", "TIMESTAMP_COMMITTED", "COMMIT_MESSAGE",
"TAG", "TAG_SIGNED", "TAGGER", "DATE_TAGGED", "TIMESTAMP_TAGGED",
"TAG_MESSAGE", "VCS_DIR_WHEN_CHALKED"]
post_run_keys: ["_COMMIT_ID", "_COMMIT_SIGNED",
"_BRANCH", "_ORIGIN_URI",
"_AUTHOR", "_DATE_AUTHORED",
"_COMMITTER", "_DATE_COMMITTED", "_COMMIT_MESSAGE",
"_TAG", "_TAG_SIGNED", "_TAGGER", "_DATE_TAGGED",
"_AUTHOR", "_DATE_AUTHORED", "_TIMESTAMP_AUTHORED",
"_COMMITTER", "_DATE_COMMITTED", "_TIMESTAMP_COMMITTED", "_COMMIT_MESSAGE",
"_TAG", "_TAG_SIGNED", "_TAGGER", "_DATE_TAGGED", "_TIMESTAMP_TAGGED",
"_TAG_MESSAGE"]
doc: """
This plugin collects version control information from .git directories
Expand Down
36 changes: 36 additions & 0 deletions src/configs/base_report_templates.c4m
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,14 @@ report and subtract from it.
key.COMMIT_SIGNED.use = true
key.AUTHOR.use = true
key.DATE_AUTHORED.use = true
key.TIMESTAMP_AUTHORED.use = true
key.COMMITTER.use = true
key.DATE_COMMITTED.use = true
key.TIMESTAMP_COMMITTED.use = true
key.COMMIT_MESSAGE.use = true
key.TAGGER.use = true
key.DATE_TAGGED.use = true
key.TIMESTAMP_TAGGED.use = true
key.TAG_MESSAGE.use = true
key._ORIGIN_URI.use = true
key._BRANCH.use = true
Expand All @@ -73,11 +76,14 @@ report and subtract from it.
key._COMMIT_SIGNED.use = true
key._AUTHOR.use = true
key._DATE_AUTHORED.use = true
key._TIMESTAMP_AUTHORED.use = true
key._COMMITTER.use = true
key._DATE_COMMITTED.use = true
key._TIMESTAMP_COMMITTED.use = true
key._COMMIT_MESSAGE.use = true
key._TAGGER.use = true
key._DATE_TAGGED.use = true
key._TIMESTAMP_TAGGED.use = true
key._TAG_MESSAGE.use = true
key.ARTIFACT_VERSION.use = true
key.STORE_URI.use = true
Expand Down Expand Up @@ -650,11 +656,14 @@ doc: """
key.COMMIT_SIGNED.use = true
key.AUTHOR.use = true
key.DATE_AUTHORED.use = true
key.TIMESTAMP_AUTHORED.use = true
key.COMMITTER.use = true
key.DATE_COMMITTED.use = true
key.TIMESTAMP_COMMITTED.use = true
key.COMMIT_MESSAGE.use = true
key.TAGGER.use = true
key.DATE_TAGGED.use = true
key.TIMESTAMP_TAGGED.use = true
key.TAG_MESSAGE.use = true
key._ORIGIN_URI.use = true
key._BRANCH.use = true
Expand All @@ -664,11 +673,14 @@ doc: """
key._COMMIT_SIGNED.use = true
key._AUTHOR.use = true
key._DATE_AUTHORED.use = true
key._TIMESTAMP_AUTHORED.use = true
key._COMMITTER.use = true
key._DATE_COMMITTED.use = true
key._TIMESTAMP_COMMITTED.use = true
key._COMMIT_MESSAGE.use = true
key._TAGGER.use = true
key._DATE_TAGGED.use = true
key._TIMESTAMP_TAGGED.use = true
key._TAG_MESSAGE.use = true
key.ARTIFACT_VERSION.use = true
key.STORE_URI.use = true
Expand Down Expand Up @@ -1124,11 +1136,14 @@ container.
key.COMMIT_SIGNED.use = true
key.AUTHOR.use = true
key.DATE_AUTHORED.use = true
key.TIMESTAMP_AUTHORED.use = true
key.COMMITTER.use = true
key.DATE_COMMITTED.use = true
key.TIMESTAMP_COMMITTED.use = true
key.COMMIT_MESSAGE.use = true
key.TAGGER.use = true
key.DATE_TAGGED.use = true
key.TIMESTAMP_TAGGED.use = true
key.TAG_MESSAGE.use = true
key._ORIGIN_URI.use = true
key._BRANCH.use = true
Expand All @@ -1138,11 +1153,14 @@ container.
key._COMMIT_SIGNED.use = true
key._AUTHOR.use = true
key._DATE_AUTHORED.use = true
key._TIMESTAMP_AUTHORED.use = true
key._COMMITTER.use = true
key._DATE_COMMITTED.use = true
key._TIMESTAMP_COMMITTED.use = true
key._COMMIT_MESSAGE.use = true
key._TAGGER.use = true
key._DATE_TAGGED.use = true
key._TIMESTAMP_TAGGED.use = true
key._TAG_MESSAGE.use = true
key.ARTIFACT_VERSION.use = true
key.STORE_URI.use = true
Expand Down Expand Up @@ -1598,11 +1616,14 @@ and keep the run-time key.
key.COMMIT_SIGNED.use = true
key.AUTHOR.use = true
key.DATE_AUTHORED.use = true
key.TIMESTAMP_AUTHORED.use = true
key.COMMITTER.use = true
key.DATE_COMMITTED.use = true
key.TIMESTAMP_COMMITTED.use = true
key.COMMIT_MESSAGE.use = true
key.TAGGER.use = true
key.DATE_TAGGED.use = true
key.TIMESTAMP_TAGGED.use = true
key.TAG_MESSAGE.use = true
key._ORIGIN_URI.use = true
key._BRANCH.use = true
Expand All @@ -1612,11 +1633,14 @@ and keep the run-time key.
key._COMMIT_SIGNED.use = true
key._AUTHOR.use = true
key._DATE_AUTHORED.use = true
key._TIMESTAMP_AUTHORED.use = true
key._COMMITTER.use = true
key._DATE_COMMITTED.use = true
key._TIMESTAMP_COMMITTED.use = true
key._COMMIT_MESSAGE.use = true
key._TAGGER.use = true
key._DATE_TAGGED.use = true
key._TIMESTAMP_TAGGED.use = true
key._TAG_MESSAGE.use = true
key.ARTIFACT_VERSION.use = true
key.STORE_URI.use = true
Expand Down Expand Up @@ -1994,11 +2018,14 @@ running insert commands.
key.COMMIT_SIGNED.use = true
key.AUTHOR.use = true
key.DATE_AUTHORED.use = true
key.TIMESTAMP_AUTHORED.use = true
key.COMMITTER.use = true
key.DATE_COMMITTED.use = true
key.TIMESTAMP_COMMITTED.use = true
key.COMMIT_MESSAGE.use = true
key.TAGGER.use = true
key.DATE_TAGGED.use = true
key.TIMESTAMP_TAGGED.use = true
key.TAG_MESSAGE.use = true
key._ORIGIN_URI.use = true
key._BRANCH.use = true
Expand All @@ -2008,11 +2035,14 @@ running insert commands.
key._COMMIT_SIGNED.use = true
key._AUTHOR.use = true
key._DATE_AUTHORED.use = true
key._TIMESTAMP_AUTHORED.use = true
key._COMMITTER.use = true
key._DATE_COMMITTED.use = true
key._TIMESTAMP_COMMITTED.use = true
key._COMMIT_MESSAGE.use = true
key._TAGGER.use = true
key._DATE_TAGGED.use = true
key._TIMESTAMP_TAGGED.use = true
key._TAG_MESSAGE.use = true
key.EMBEDDED_CHALK.use = true
key.ERR_INFO.use = true
Expand Down Expand Up @@ -2084,11 +2114,14 @@ running commands that do NOT insert chalk marks.
key.COMMIT_SIGNED.use = true
key.AUTHOR.use = true
key.DATE_AUTHORED.use = true
key.TIMESTAMP_AUTHORED.use = true
key.COMMITTER.use = true
key.DATE_COMMITTED.use = true
key.TIMESTAMP_COMMITTED.use = true
key.COMMIT_MESSAGE.use = true
key.TAGGER.use = true
key.DATE_TAGGED.use = true
key.TIMESTAMP_TAGGED.use = true
key.TAG_MESSAGE.use = true
key._ORIGIN_URI.use = true
key._BRANCH.use = true
Expand All @@ -2098,11 +2131,14 @@ running commands that do NOT insert chalk marks.
key._COMMIT_SIGNED.use = true
key._AUTHOR.use = true
key._DATE_AUTHORED.use = true
key._TIMESTAMP_AUTHORED.use = true
key._COMMITTER.use = true
key._DATE_COMMITTED.use = true
key._TIMESTAMP_COMMITTED.use = true
key._COMMIT_MESSAGE.use = true
key._TAGGER.use = true
key._DATE_TAGGED.use = true
key._TIMESTAMP_TAGGED.use = true
key._TAG_MESSAGE.use = true
key.EMBEDDED_CHALK.use = true
key.ERR_INFO.use = true
Expand Down
Loading

0 comments on commit d3c3b11

Please sign in to comment.