Commit graph

2844 commits

Author SHA1 Message Date
Shaun Ruffell
c75d9fefad test: Remove unused variables from DatetimeParser.t
Quiets the following warnings when building the test:

  test/DatetimeParser.t.cpp: In function ‘int main(int, char**)’:
  test/DatetimeParser.t.cpp:163:7: warning: unused variable ‘hm’ [-Wunused-variable]
     int hm  = (12 * 3600) + (34 * 60);      // The time 12:34:00 in seconds.
         ^~
  test/DatetimeParser.t.cpp:164:7: warning: unused variable ‘z’ [-Wunused-variable]
     int z   = 3600;                         // TZ offset.
         ^
  test/DatetimeParser.t.cpp:317:7: warning: unused variable ‘t8a’ [-Wunused-variable]
     int t8a   = (8 * 3600);
         ^~~
  test/DatetimeParser.t.cpp:318:7: warning: unused variable ‘t830a’ [-Wunused-variable]
     int t830a = (8 * 3600) + (30 * 60);
         ^~~~~
  test/DatetimeParser.t.cpp:319:7: warning: unused variable ‘t8p’ [-Wunused-variable]
     int t8p   = (20 * 3600);
         ^~~
  test/DatetimeParser.t.cpp:320:7: warning: unused variable ‘t830p’ [-Wunused-variable]
     int t830p = (20 * 3600) + (30 * 60);
         ^~~~~
  test/DatetimeParser.t.cpp:321:7: warning: unused variable ‘t12p’ [-Wunused-variable]
     int t12p  = (12 * 3600);
         ^~~~
  test/DatetimeParser.t.cpp:322:7: warning: unused variable ‘t1p’ [-Wunused-variable]
     int t1p   = (13 * 3600);
         ^~~
  test/DatetimeParser.t.cpp:325:7: warning: variable ‘adjust’ set but not used [-Wunused-but-set-variable]
     int adjust = (time_now.hour () > 10 || (time_now.hour () == 10 && time_now.minute () > 30)) ? 86400 : 0;
         ^~~~~~

Signed-off-by: Shaun Ruffell <sruffell@sruffell.net>
2020-08-11 10:39:34 +02:00
Shaun Ruffell
a87117db09 Remove undo file if empty
Signed-off-by: Shaun Ruffell <sruffell@sruffell.net>
2020-08-10 22:24:52 +02:00
Shaun Ruffell
b0efdbc9ee Datafile: Remove empty files
If calling undo on an operation the removes many entries from the
datafiles, there would be many 0 length size files remaining in the data
directory. Now they will be removed if they are empty so they will not
longer need to be checked when parsing the database.

Signed-off-by: Shaun Ruffell <sruffell@sruffell.net>
2020-08-10 22:24:52 +02:00
Shaun Ruffell
b2a8fe6f55 test: Add tests for -1, 0, 1, and 2 'journal.size' settings
Signed-off-by: Shaun Ruffell <sruffell@sruffell.net>
2020-08-10 22:24:52 +02:00
Shaun Ruffell
a1e2def1a8 Introduce 'journal.size' config setting.
Allows the user to specify a maximum number of entries to store in the
undo file. By default the behavior is unchanged, and the file will grow
unbounded without user intervention.

journal.size = 0 will disable storing any entries, journal.size < 0
indicates that the size of the journal should be unlimited (the
default), otherwise it indicates the number of entries to store.

Signed-off-by: Shaun Ruffell <sruffell@sruffell.net>
2020-08-10 22:24:52 +02:00
Shaun Ruffell
0a4644bfc7 AtomicFile: Add size() and remove() methods
Signed-off-by: Shaun Ruffell <sruffell@sruffell.net>
2020-08-10 22:24:52 +02:00
Shaun Ruffell
cea2e5d13f Only show tag in chart if utf8 character width is within the width
- Closes #309

Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-07-17 21:44:22 +02:00
Thomas Lauf
06a4235b10 Move start of transaction down to actual database methods
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-07-17 17:53:59 +02:00
Thomas Lauf
b5aec4db8b Remove flattening of database in CmdContinue
- Should now be done during overlap resolution in `validate.cpp`

Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-07-17 17:53:04 +02:00
Thomas Lauf
6bf708dbeb Use dynamic test data for interval enclosing a month border in delete.t
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-07-17 13:59:05 +02:00
Thomas Lauf
90b5b1085e Adapt delete.t and move.t as today is now interpreted as a range
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-07-15 17:22:32 +02:00
Thomas Lauf
c35a08719f Move handling of starting a interval with identical tag set as the current tracking to standard overlap resolution
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-07-14 13:58:54 +02:00
Thomas Lauf
6618231002 CmdStart shall not accept ranges as input
- This also handles the case when it is called with the `:all` hint
- When called with a range, the `track` command is recommended
- There is no forwarding to `track`

Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-07-14 13:57:15 +02:00
Thomas Lauf
91c246c42f CmdStart should not redirect to CmdTrack but issue an error message when called with range
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-07-13 16:40:37 +02:00
Shaun Ruffell
cc82f468e1 CmdStart: Honor the :adjust flag when overwriting a currently open interval
Move the adjustment of a new open interval that is enclosed by the
current open interval into the validation processing, where the other
overlap resolution takes place.

This will allow the start command to honor the :adjust flag when
starting a new interval that predates the current open interval.

Closes #326

Signed-off-by: Shaun Ruffell <sruffell@sruffell.net>
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-07-12 12:27:31 +02:00
Thomas Lauf
1c1066ae6c Adapt standard overlap resolution
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-07-12 12:18:54 +02:00
Shaun Ruffell
4aacba47df CmdStart: Do not assume :all hint means now
Signed-off-by: Shaun Ruffell <sruffell@sruffell.net>
2020-07-08 21:28:41 +02:00
Shaun Ruffell
6a52a412ba CmdStart: Do not silently fail if tags match
It was possible previously to start an interval with a filter earlier
than the current filter, and if the tags matched, the command would
report success without actually moving the start time.

Signed-off-by: Shaun Ruffell <sruffell@sruffell.net>
2020-07-08 21:28:41 +02:00
Shaun Ruffell
356f20c9de Remove getOverlaps function
Since the Intervals are all in order, we can use getTracked directly to
get overlapping intervals without the need to copy the Intervals into
another vector.

Signed-off-by: Shaun Ruffell <sruffell@sruffell.net>
2020-07-08 21:28:41 +02:00
Thomas Lauf
7bc511bc73 Update tests for TagInfoDatabase
- Add tests for JSON output
- Separate different test scenarios
- Optimize JSON output in `TagInfoDatabase::toJson ()`

- Closes #325

Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-07-02 22:42:45 +02:00
Quazgar
ca10d52927 ENH: tags.data writes one entry per line.
This makes it easier to compare and merge the tags file from different machines.

Signed-off-by: Quazgar <quazgar@posteo.de>
2020-07-02 22:38:51 +02:00
Thomas Lauf
13a116a301 Update documentation of 'timew-continue'
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-07-02 19:59:47 +02:00
Thomas Lauf
d99872eb90 Finish implementation of 'continue by tag'
- This adds the last bits to the PR started by Christian Roesch:
- Some code formatting
- Specifying both id(s) and tag(s) is an error
- Clear range for tag filter: The range is meant to set the new interval's range, not the filter's
- Added tests
- Overhauled test using relative times and testing exported intervals instead of command line output
- Closes #241

Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-07-02 19:59:47 +02:00
Christian Rösch
3def4b10c4 Refactor code as suggested and add tests. 2020-07-01 16:16:58 +02:00
Christian Rösch
f3280966e0 Allow continue by tag. 2020-07-01 16:16:58 +02:00
Thomas Lauf
6db29f1df5 Move overlap resolution from CmdContinue to function autoAdjust
- Only an open interval can truncate another open interval.
  Otherwise the `:adjust` hint has to be applied

Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-07-01 08:12:04 +02:00
Thomas Lauf
c6598b9ac8 Convert to early return
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-06-30 21:17:51 +02:00
Thomas Lauf
07a6dfe313 Use functions is_started() and is_ended() instead of querying start/end directly
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-06-29 22:09:00 +02:00
Thomas Lauf
4637cd3d4e Do not manipulate filter in getTracked
- Filter shall be taken as is, not changed
- If there is a problem, the functions consuming the filter have to be adapted, not the filter

Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-06-29 22:07:35 +02:00
Thomas Lauf
63f230013a Detect whether a date is meant as range
- Add DatetimeParser::parse_range: If a date contains no time, it is assumed to be a fixed range, else an open range starting at given datetime
- Add tests for summary with named dates 'yesterday' and 'today'
- Remove closing of filter in CmdSummary.cpp
- Closes #333

Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-06-28 20:52:43 +02:00
Thomas Lauf
2906f36830 Add test for command summary with :all hint
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-06-22 22:21:27 +02:00
George Buckingham
90081afb97 Update docs links from taskwarrior.org to timewarrior.net
Signed-off-by: George Buckingham <george.buckingham@gmail.com>
2020-06-14 15:12:57 +02:00
Shaun Ruffell
59d0f1263f Mask signals while updating database
In order to keep the database consistent, we really want all the
AtomicFiles to be finalized as a group. This will prevent an inopportune
signal from interrupting this process.

Signed-off-by: Shaun Ruffell <sruffell@sruffell.net>
2020-06-03 21:31:01 +02:00
Thomas Lauf
83ec55cdc6 Remove unused filter
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-06-03 18:44:36 +02:00
Thomas Lauf
c9eec956e4 Add hint :all
- Closes #206

Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-06-03 18:44:36 +02:00
Thomas Lauf
6117ce1a84 Introduce default range parameter when requesting filter from CLI
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-06-03 17:47:14 +02:00
Thomas Lauf
7e11fde992 Remove template.t from test folder
- This file was development only, now any other test file can serve as template for new tests
- Closes #303

Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-05-22 09:16:08 +02:00
Thomas Lauf
c71eeb6dfd Add DOM-query for ids
- Closes #126

Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-05-10 21:44:30 +02:00
Thomas Lauf
2169e8e928 Add/update descriptive comments
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-05-10 21:44:30 +02:00
Thomas Lauf
a508dd21ea Get and use filter from CLI when processing DOM references
- Closes #188

Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-05-10 21:44:30 +02:00
Thomas Lauf
13f1de2c49 Identify DOM references by their prefix ('dom.<...>') and mark them as such when analyzing the command line
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-05-10 21:44:30 +02:00
Thomas Lauf
9ae3ace109 Make getFilter(cli) a method of CLI 2020-05-10 21:44:30 +02:00
Thomas Lauf
547bda5ef8 Extract filter so it can be injected
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-05-10 21:44:30 +02:00
Thomas Lauf
6e5236d472 Add DOM query dom.tracked.tags
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-05-10 21:44:30 +02:00
Thomas Lauf
5c234c95f9 Move test setup to the test methods
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-05-10 21:44:30 +02:00
Thomas Lauf
422e49bacb Extract function getDomReferences and move it to CLI
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-05-10 21:44:30 +02:00
Shaun Ruffell
29cc9e8a0a Fix another place where json::parse() result was leaked
Signed-off-by: Shaun Ruffell <sruffell@sruffell.net>
2020-05-10 21:33:31 +02:00
Shaun Ruffell
42ede4104c Remove naked pointer in initializeTagDatabase
The json::object pointer was allocated in the parse function but never
freed.

The way timwarrior is used currently, this leak does not cause any
problems, but...

Signed-off-by: Shaun Ruffell <sruffell@sruffell.net>
2020-05-10 21:33:31 +02:00
Shaun Ruffell
85d991704b Speed up deserialization of Intervals
When the Lexer breaks a line into tokens, it also wants to return the
type of the token. This information isn't used by the IntervalFactory
and it slows down the operation since dates end up being parsed at least
twice, once by the Lexer to determine that the string is a date, then
again in the IntervalFactory to actually construct the Date.

Before are the before and after results when exporting a database with
100 lines. The number of instructions executed went from roughly 31,552,467 to
12,952,372 on debug builds. Release builds saw a change from around 14K
to 7K instructions.

Before:

  $ rm -fr ~/.timewarrior; src/timew :yes >/dev/null; for x in {100..1}; do src/timew start ${x}sec ago proj_${x} >/dev/null; done;
  $ sudo chrt -f 99 valgrind --tool=callgrind --callgrind-out-file=callgrind.out src/timew export >/dev/null
  ==20888== Callgrind, a call-graph generating cache profiler
  ==20888== Copyright (C) 2002-2017, and GNU GPL'd, by Josef Weidendorfer et al.
  ==20888== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
  ==20888== Command: src/timew export
  ==20888==
  ==20888== For interactive control, run 'callgrind_control -h'.
  ==20888==
  ==20888== Events    : Ir
  ==20888== Collected : 31552467
  ==20888==
  ==20888== I   refs:      31,552,467

After:

  $ sudo chrt -f 99 valgrind --tool=callgrind --callgrind-out-file=callgrind.out src/timew export >/dev/null
  ==24088== Callgrind, a call-graph generating cache profiler
  ==24088== Copyright (C) 2002-2017, and GNU GPL'd, by Josef Weidendorfer et al.
  ==24088== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
  ==24088== Command: src/timew export
  ==24088==
  ==24088== For interactive control, run 'callgrind_control -h'.
  ==24088==
  ==24088== Events    : Ir
  ==24088== Collected : 12952372
  ==24088==
  ==24088== I   refs:      12,952,372

Signed-off-by: Shaun Ruffell <sruffell@sruffell.net>
2020-05-10 21:16:08 +02:00
Thomas Lauf
3de53d7599 Bump project version to 1.3.0
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-04-19 17:38:40 +02:00