Skip to content

Commit 07d6ce9

Browse files
Merge branch 'master' into release
2 parents 605fe46 + 70b7185 commit 07d6ce9

File tree

11 files changed

+133
-55
lines changed

11 files changed

+133
-55
lines changed

docs/ug/cli.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ This flag overrides the `Ignore file size limit` field in the CSV config file.
172172
<box type="info" seamless>
173173

174174
* If both start date and end date are not specified, the date of generating the report will be taken as the end date.
175+
* May analyze the incorrect date range if used with `--since d1`. The program will throw a warning.
175176
* Cannot be used with both `--since` and `--until`. The program will throw an exception.
176177
</box>
177178
<!-- ------------------------------------------------------------------------------------------------------ -->
@@ -216,7 +217,8 @@ Cannot be used with `--last-modified-date`. This may result in an incorrect last
216217
<box type="info" seamless>
217218

218219
* If the start date is not specified, only commits made one month before the end date (if specified) or the date of generating the report, will be captured and analyzed.
219-
* If `d1` is specified as the start date (`--since d1` or `-s d1`), then the earliest commit date of all repositories will be taken as the start date.
220+
* If `d1` is specified as the start date (`--since d1` or `-s d1`), then the program will search for the earliest commit date of all repositories and use that as the start date.
221+
* If `d1` is specified together with `--period`, then the program will warn that the date range being analyzed may be incorrect.
220222
</box>
221223
<!-- ------------------------------------------------------------------------------------------------------ -->
222224

frontend/src/app.vue

+4-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
<template lang="pug">
22
#app
33
loading-overlay.overlay-loader(
4-
v-cloak,
5-
v-bind:active.sync="isLoadingOverlayEnabled",
6-
v-bind:opacity='loadingOverlayOpacity',
7-
v-bind:is-full-page="true"
4+
v-bind:active='loadingOverlayCount > 0',
5+
v-bind:opacity='loadingOverlayOpacity'
86
)
97
template(v-slot:default)
108
i.overlay-loading-icon.fa.fa-spinner.fa-spin()
@@ -99,7 +97,6 @@ const app = {
9997
users: [],
10098
userUpdated: false,
10199
102-
isLoadingOverlayEnabled: false,
103100
loadingOverlayOpacity: 1,
104101
105102
tabType: 'empty',
@@ -118,9 +115,6 @@ const app = {
118115
'$store.state.tabAuthorshipInfo': function () {
119116
this.activateTab('authorship');
120117
},
121-
'$store.state.loadingOverlayCount': function () {
122-
this.isLoadingOverlayEnabled = this.$store.state.loadingOverlayCount > 0;
123-
},
124118
},
125119
methods: {
126120
// model functions //
@@ -145,9 +139,9 @@ const app = {
145139
},
146140
147141
async updateReportView() {
148-
this.$store.commit('incrementLoadingOverlayCount', 1);
149142
this.$store.commit('updateLoadingOverlayMessage', loadingResourcesMessage);
150143
this.userUpdated = false;
144+
await this.$store.dispatch('incrementLoadingOverlayCountForceReload', 1);
151145
try {
152146
const {
153147
creationDate,
@@ -296,7 +290,7 @@ const app = {
296290
},
297291
298292
computed: {
299-
...mapState(['loadingOverlayMessage', 'isTabActive']),
293+
...mapState(['loadingOverlayCount', 'loadingOverlayMessage', 'isTabActive']),
300294
},
301295
302296
components: {

frontend/src/store/store.js

+11
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,15 @@ export default createStore({
4545
window.encodeHash();
4646
},
4747
},
48+
actions: {
49+
// Actions are called with dispatch
50+
51+
async incrementLoadingOverlayCountForceReload({ commit }, increment) {
52+
commit('incrementLoadingOverlayCount', increment);
53+
await new Promise(window.requestAnimationFrame);
54+
await new Promise(window.requestAnimationFrame);
55+
// Needed as browsers render lazily by default
56+
// https://stackoverflow.com/a/44146560
57+
},
58+
},
4859
});

frontend/src/views/v-authorship.vue

+12-14
Original file line numberDiff line numberDiff line change
@@ -535,20 +535,18 @@ export default {
535535
window.encodeHash();
536536
},
537537
538-
updateSelectedFiles(setIsLoaded = false) {
539-
this.$store.commit('incrementLoadingOverlayCount', 1);
540-
setTimeout(() => {
541-
this.selectedFiles = this.files.filter(
542-
(file) => ((this.selectedFileTypes.includes(file.fileType) && !file.isBinary && !file.isIgnored)
543-
|| (file.isBinary && this.isBinaryFilesChecked) || (file.isIgnored && this.isIgnoredFilesChecked))
544-
&& minimatch(file.path, this.searchBarValue || '*', { matchBase: true, dot: true }),
545-
)
546-
.sort(this.sortingFunction);
547-
if (setIsLoaded) {
548-
this.isLoaded = true;
549-
}
550-
this.$store.commit('incrementLoadingOverlayCount', -1);
551-
});
538+
async updateSelectedFiles(setIsLoaded = false) {
539+
await this.$store.dispatch('incrementLoadingOverlayCountForceReload', 1);
540+
this.selectedFiles = this.files.filter(
541+
(file) => ((this.selectedFileTypes.includes(file.fileType) && !file.isBinary && !file.isIgnored)
542+
|| (file.isBinary && this.isBinaryFilesChecked) || (file.isIgnored && this.isIgnoredFilesChecked))
543+
&& minimatch(file.path, this.searchBarValue || '*', { matchBase: true, dot: true }),
544+
)
545+
.sort(this.sortingFunction);
546+
if (setIsLoaded) {
547+
this.isLoaded = true;
548+
}
549+
this.$store.commit('incrementLoadingOverlayCount', -1);
552550
},
553551
554552
indicateSearchBar() {

frontend/src/views/v-summary.vue

+6-10
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,7 @@ export default {
179179
}
180180
const { allGroupsMerged } = this;
181181
182-
this.$store.commit('incrementLoadingOverlayCount', 1);
183-
setTimeout(() => {
182+
this.$store.dispatch('incrementLoadingOverlayCountForceReload', 1).then(() => {
184183
this.getFilteredRepos();
185184
this.updateMergedGroup(allGroupsMerged);
186185
this.$store.commit('incrementLoadingOverlayCount', -1);
@@ -407,17 +406,14 @@ export default {
407406
this.getFiltered();
408407
},
409408
410-
getFiltered() {
409+
async getFiltered() {
411410
this.setSummaryHash();
412411
window.deactivateAllOverlays();
413412
414-
this.$store.commit('incrementLoadingOverlayCount', 1);
415-
// Use setTimeout() to force this.filtered to update only after loading screen is displayed.
416-
setTimeout(() => {
417-
this.getFilteredRepos();
418-
this.getMergedRepos();
419-
this.$store.commit('incrementLoadingOverlayCount', -1);
420-
});
413+
await this.$store.dispatch('incrementLoadingOverlayCountForceReload', 1);
414+
this.getFilteredRepos();
415+
this.getMergedRepos();
416+
this.$store.commit('incrementLoadingOverlayCount', -1);
421417
},
422418
423419
getFilteredRepos() {

src/main/java/reposense/commits/CommitResultAggregator.java

+6-8
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,14 @@
1414
import reposense.commits.model.CommitResult;
1515
import reposense.model.Author;
1616
import reposense.model.RepoConfiguration;
17-
import reposense.parser.SinceDateArgumentType;
1817
import reposense.report.ReportGenerator;
18+
import reposense.util.TimeUtil;
1919

2020
/**
2121
* Uses the commit analysis results to generate the summary information of a repository.
2222
*/
2323
public class CommitResultAggregator {
2424
private static final int DAYS_IN_MS = 24 * 60 * 60 * 1000;
25-
private static final ZonedDateTime ARBITRARY_FIRST_COMMIT_DATE_UTC =
26-
ZonedDateTime.of(SinceDateArgumentType.ARBITRARY_FIRST_COMMIT_DATE, ZoneId.of("Z"));
2725

2826
/**
2927
* Returns the {@link CommitContributionSummary} generated from aggregating the {@code commitResults}.
@@ -33,7 +31,7 @@ public static CommitContributionSummary aggregateCommitResults(
3331
RepoConfiguration config, List<CommitResult> commitResults) {
3432
LocalDateTime startDate;
3533
ZoneId zoneId = ZoneId.of(config.getZoneId());
36-
startDate = (config.getSinceDate().equals(SinceDateArgumentType.ARBITRARY_FIRST_COMMIT_DATE))
34+
startDate = (TimeUtil.isEqualToArbitraryFirstDateConverted(config.getSinceDate(), zoneId))
3735
? getStartOfDate(getStartDate(commitResults, zoneId), zoneId)
3836
: config.getSinceDate();
3937
ReportGenerator.setEarliestSinceDate(startDate);
@@ -157,11 +155,11 @@ private static void addDailyContributionForNewDate(
157155
/**
158156
* Gets the starting point of the {@code current} date.
159157
*
160-
* @return the {@code current} date if it is equal to the {@code ARBITRARY_FIRST_COMMIT_DATE_UTC} adjusted to the
158+
* @return the {@code current} date if it is equal to the {@code ARBITRARY_FIRST_COMMIT_DATE} adjusted to the
161159
* timezone given by {@code zoneId}. Otherwise, return a {@link LocalDateTime} adjusted to have a time of 00:00:00.
162160
*/
163161
private static LocalDateTime getStartOfDate(LocalDateTime current, ZoneId zoneId) {
164-
if (current.equals(ARBITRARY_FIRST_COMMIT_DATE_UTC.withZoneSameInstant(zoneId).toLocalDateTime())) {
162+
if (TimeUtil.isEqualToArbitraryFirstDateConverted(current, zoneId)) {
165163
return current;
166164
}
167165

@@ -172,11 +170,11 @@ private static LocalDateTime getStartOfDate(LocalDateTime current, ZoneId zoneId
172170
* Gets the earliest commit date from {@code commitInfos}.
173171
*
174172
* @return First commit date if there is at least one {@link CommitResult}. Otherwise, return
175-
* the {@code ARBITRARY_FIRST_COMMIT_DATE_UTC} converted to the timezone given by {@code zoneId}.
173+
* the {@code ARBITRARY_FIRST_COMMIT_DATE} converted to the timezone given by {@code zoneId}.
176174
*/
177175
private static LocalDateTime getStartDate(List<CommitResult> commitInfos, ZoneId zoneId) {
178176
return (commitInfos.isEmpty())
179-
? ARBITRARY_FIRST_COMMIT_DATE_UTC.withZoneSameInstant(zoneId).toLocalDateTime()
177+
? TimeUtil.getArbitraryFirstCommitDateConverted(zoneId)
180178
: commitInfos.get(0).getTime();
181179
}
182180
}

src/main/java/reposense/parser/ArgsParser.java

+12
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ public class ArgsParser {
7474
"Config path not provided, using the config folder as default.";
7575
private static final String MESSAGE_INVALID_CONFIG_PATH = "%s is malformed.";
7676
private static final String MESSAGE_INVALID_CONFIG_JSON = "%s Ignoring the report config provided.";
77+
private static final String MESSAGE_SINCE_D1_WITH_PERIOD = "You may be using --since d1 with the --period flag. "
78+
+ "This may result in an incorrect date range being analysed.";
7779
private static final Path EMPTY_PATH = Paths.get("");
7880
private static final Path DEFAULT_CONFIG_PATH = Paths.get(System.getProperty("user.dir")
7981
+ File.separator + "config" + File.separator);
@@ -280,6 +282,7 @@ public static CliArguments parse(String[] args) throws HelpScreenException, Pars
280282
boolean isSinceDateProvided = cliSinceDate.isPresent();
281283
boolean isUntilDateProvided = cliUntilDate.isPresent();
282284
boolean isPeriodProvided = cliPeriod.isPresent();
285+
boolean isUsingArbitraryDate = false;
283286
if (isSinceDateProvided && isUntilDateProvided && isPeriodProvided) {
284287
throw new ParseException(MESSAGE_HAVE_SINCE_DATE_UNTIL_DATE_AND_PERIOD);
285288
}
@@ -290,6 +293,11 @@ public static CliArguments parse(String[] args) throws HelpScreenException, Pars
290293

291294
if (isSinceDateProvided) {
292295
sinceDate = TimeUtil.getSinceDate(cliSinceDate.get());
296+
// For --since d1, need to adjust the arbitrary date based on timezone
297+
if (TimeUtil.isEqualToArbitraryFirstDateUtc(sinceDate)) {
298+
isUsingArbitraryDate = true;
299+
sinceDate = TimeUtil.getArbitraryFirstCommitDateConverted(zoneId);
300+
}
293301
} else {
294302
if (isUntilDateProvided) {
295303
sinceDate = isPeriodProvided
@@ -303,6 +311,10 @@ public static CliArguments parse(String[] args) throws HelpScreenException, Pars
303311

304312
}
305313

314+
if (isPeriodProvided && isUsingArbitraryDate) {
315+
logger.warning(MESSAGE_SINCE_D1_WITH_PERIOD);
316+
}
317+
306318
if (isUntilDateProvided) {
307319
untilDate = TimeUtil.getUntilDate(cliUntilDate.get());
308320
} else {

src/main/java/reposense/parser/SinceDateArgumentType.java

+24-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.time.Instant;
44
import java.time.LocalDateTime;
55
import java.time.ZoneId;
6+
import java.time.ZonedDateTime;
67
import java.util.Optional;
78

89
import net.sourceforge.argparse4j.inf.Argument;
@@ -16,14 +17,17 @@
1617
public class SinceDateArgumentType extends DateArgumentType {
1718
/*
1819
* When user specifies "d1", arbitrary first commit date will be returned.
20+
* This date is equivalent to 1970-01-01 00:00:00 in UTC time.
1921
* Then, ReportGenerator will replace the arbitrary since date with the earliest commit date.
2022
*/
21-
public static final LocalDateTime ARBITRARY_FIRST_COMMIT_DATE = LocalDateTime.ofInstant(
22-
Instant.ofEpochMilli(Long.MIN_VALUE), ZoneId.of("Z"));
2323
public static final String FIRST_COMMIT_DATE_SHORTHAND = "d1";
24+
private static final ZonedDateTime ARBITRARY_FIRST_COMMIT_DATE_UTC = ZonedDateTime.ofInstant(
25+
Instant.ofEpochMilli(0), ZoneId.of("Z"));
26+
private static final LocalDateTime ARBITRARY_FIRST_COMMIT_DATE_LOCAL = ARBITRARY_FIRST_COMMIT_DATE_UTC
27+
.toLocalDateTime();
2428

2529
/**
26-
* Returns an arbitrary year {@link SinceDateArgumentType#ARBITRARY_FIRST_COMMIT_DATE} if user specifies
30+
* Returns an arbitrary year {@link SinceDateArgumentType#ARBITRARY_FIRST_COMMIT_DATE_LOCAL} if user specifies
2731
* {@link SinceDateArgumentType#FIRST_COMMIT_DATE_SHORTHAND} in {@code value}, or attempts to return the
2832
* desired date otherwise.
2933
*
@@ -33,9 +37,25 @@ public class SinceDateArgumentType extends DateArgumentType {
3337
public Optional<LocalDateTime> convert(ArgumentParser parser, Argument arg, String value)
3438
throws ArgumentParserException {
3539
if (FIRST_COMMIT_DATE_SHORTHAND.equals(value)) {
36-
return Optional.of(ARBITRARY_FIRST_COMMIT_DATE);
40+
return Optional.of(ARBITRARY_FIRST_COMMIT_DATE_LOCAL);
3741
}
3842
String sinceDate = TimeUtil.extractDate(value);
3943
return super.convert(parser, arg, sinceDate + " 00:00:00");
4044
}
45+
46+
/**
47+
* Returns the {@link SinceDateArgumentType#ARBITRARY_FIRST_COMMIT_DATE_LOCAL}, which is the
48+
* {@link LocalDateTime} of {@link SinceDateArgumentType#ARBITRARY_FIRST_COMMIT_DATE_UTC}.
49+
*/
50+
public static LocalDateTime getArbitraryFirstCommitDateLocal() {
51+
return ARBITRARY_FIRST_COMMIT_DATE_LOCAL;
52+
}
53+
54+
/**
55+
* Returns the {@link SinceDateArgumentType#ARBITRARY_FIRST_COMMIT_DATE_UTC} adjusted for the time zone based on
56+
* {@code toZoneId} and converted to a {@link LocalDateTime} object.
57+
*/
58+
public static LocalDateTime getArbitraryFirstCommitDateConverted(ZoneId toZoneId) {
59+
return ARBITRARY_FIRST_COMMIT_DATE_UTC.withZoneSameInstant(toZoneId).toLocalDateTime();
60+
}
4161
}

src/main/java/reposense/report/ReportGenerator.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@
4646
import reposense.model.RepoLocation;
4747
import reposense.model.ReportConfiguration;
4848
import reposense.model.StandaloneConfig;
49-
import reposense.parser.SinceDateArgumentType;
5049
import reposense.parser.StandaloneConfigJsonParser;
5150
import reposense.report.exception.NoAuthorsWithCommitsFoundException;
5251
import reposense.system.LogsManager;
5352
import reposense.util.FileUtil;
5453
import reposense.util.ProgressTracker;
54+
import reposense.util.TimeUtil;
5555

5656
/**
5757
* Contains report generation related functionalities.
@@ -160,7 +160,7 @@ public static List<Path> generateReposReport(List<RepoConfiguration> configs, St
160160
List<Path> reportFoldersAndFiles = cloneAndAnalyzeRepos(configs, outputPath,
161161
numCloningThreads, numAnalysisThreads, shouldFreshClone);
162162

163-
LocalDateTime reportSinceDate = (cliSinceDate.equals(SinceDateArgumentType.ARBITRARY_FIRST_COMMIT_DATE))
163+
LocalDateTime reportSinceDate = (TimeUtil.isEqualToArbitraryFirstDateConverted(cliSinceDate, zoneId))
164164
? earliestSinceDate : cliSinceDate;
165165

166166
Optional<Path> summaryPath = FileUtil.writeJsonFile(

src/main/java/reposense/util/TimeUtil.java

+30-6
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,8 @@ public static String getElapsedTimeMessage() {
6666

6767
/**
6868
* Returns a {@link LocalDateTime} that is set to midnight for the given {@code sinceDate}.
69-
* If {@code sinceDate} is {@link SinceDateArgumentType#ARBITRARY_FIRST_COMMIT_DATE}, it is simply returned
70-
* as such.
7169
*/
7270
public static LocalDateTime getSinceDate(LocalDateTime sinceDate) {
73-
if (sinceDate.equals(SinceDateArgumentType.ARBITRARY_FIRST_COMMIT_DATE)) {
74-
return sinceDate;
75-
}
76-
7771
return sinceDate.withHour(0).withMinute(0).withSecond(0);
7872
}
7973

@@ -114,6 +108,36 @@ public static LocalDateTime getCurrentDate(ZoneId zoneId) {
114108
return LocalDateTime.now(zoneId).withHour(23).withMinute(59).withSecond(59).withNano(0);
115109
}
116110

111+
/**
112+
* Returns the {@link LocalDateTime} of {@code ARBITRARY_FIRST_COMMIT_DATE} in the UTC time zone.
113+
*/
114+
public static LocalDateTime getArbitraryFirstCommitDateLocal() {
115+
return SinceDateArgumentType.getArbitraryFirstCommitDateLocal();
116+
}
117+
118+
/**
119+
* Returns the {@link LocalDateTime} of {@code ARBITRARY_FIRST_COMMIT_DATE} adjusted for the time zone based on
120+
* {@code toZoneId}.
121+
*/
122+
public static LocalDateTime getArbitraryFirstCommitDateConverted(ZoneId toZoneId) {
123+
return SinceDateArgumentType.getArbitraryFirstCommitDateConverted(toZoneId);
124+
}
125+
126+
/**
127+
* Checks whether the given {@code dateTime} is the {@code ARBITRARY_FIRST_COMMIT_DATE} in UTC time.
128+
*/
129+
public static boolean isEqualToArbitraryFirstDateUtc(LocalDateTime dateTime) {
130+
return dateTime.equals(getArbitraryFirstCommitDateLocal());
131+
}
132+
133+
/**
134+
* Checks whether the given {@code dateTime} is the {@code ARBITRARY_FIRST_COMMIT_DATE} in the time zone given by
135+
* {@code zoneId}.
136+
*/
137+
public static boolean isEqualToArbitraryFirstDateConverted(LocalDateTime dateTime, ZoneId zoneId) {
138+
return dateTime.equals(getArbitraryFirstCommitDateConverted(zoneId));
139+
}
140+
117141
/**
118142
* Verifies that {@code sinceDate} is earlier than {@code untilDate}.
119143
*

0 commit comments

Comments
 (0)