mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-06-26 10:54:28 +02:00
trivial:coding-style: Add curly braces around blocks modified recently
timwarrior coding standard is for there to be curly braces around all code blocks. See https://github.com/GothenburgBitFactory/timewarrior/pull/269#discussion_r367937920
This commit is contained in:
parent
f45734efe0
commit
2fcca6f949
13 changed files with 90 additions and 1 deletions
|
@ -451,7 +451,9 @@ void Database::initializeTagDatabase ()
|
|||
auto end = Database::end ();
|
||||
|
||||
if (it == end)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
std::cout << "Tag info database does not exist. Recreating from interval data..." << std::endl ;
|
||||
|
||||
|
|
|
@ -42,7 +42,9 @@ int CmdContinue (
|
|||
std::set <int> ids = cli.getIds();
|
||||
|
||||
if (ids.size() > 1)
|
||||
{
|
||||
throw std::string ("You can only specify one ID to continue.");
|
||||
}
|
||||
|
||||
journal.startTransaction ();
|
||||
|
||||
|
@ -56,7 +58,9 @@ int CmdContinue (
|
|||
auto intervals = getIntervalsByIds (database, rules, ids);
|
||||
|
||||
if (intervals.size () == 0)
|
||||
{
|
||||
throw format ("ID '@{1}' does not correspond to any tracking.", *ids.begin ());
|
||||
}
|
||||
|
||||
assert (intervals.size () == 1);
|
||||
to_copy = intervals.front ();
|
||||
|
@ -64,10 +68,14 @@ int CmdContinue (
|
|||
else
|
||||
{
|
||||
if (latest.empty ())
|
||||
{
|
||||
throw std::string ("There is no previous tracking to continue.");
|
||||
}
|
||||
|
||||
if (latest.is_open ())
|
||||
{
|
||||
throw std::string ("There is already active tracking.");
|
||||
}
|
||||
|
||||
to_copy = latest;
|
||||
}
|
||||
|
@ -97,7 +105,9 @@ int CmdContinue (
|
|||
modified.end = start_time;
|
||||
database.modifyInterval(latest, modified, verbose);
|
||||
if (verbose)
|
||||
{
|
||||
std::cout << '\n' << intervalSummarize (database, rules, modified);
|
||||
}
|
||||
}
|
||||
|
||||
validate (cli, rules, database, to_copy);
|
||||
|
@ -106,7 +116,9 @@ int CmdContinue (
|
|||
journal.endTransaction ();
|
||||
|
||||
if (verbose)
|
||||
{
|
||||
std::cout << intervalSummarize (database, rules, to_copy);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -40,7 +40,9 @@ int CmdDelete (
|
|||
std::set <int> ids = cli.getIds ();
|
||||
|
||||
if (ids.empty ())
|
||||
{
|
||||
throw std::string ("IDs must be specified. See 'timew help delete'.");
|
||||
}
|
||||
|
||||
journal.startTransaction ();
|
||||
|
||||
|
@ -52,7 +54,9 @@ int CmdDelete (
|
|||
database.deleteInterval (interval);
|
||||
|
||||
if (rules.getBoolean ("verbose"))
|
||||
{
|
||||
std::cout << "Deleted @" << interval.id << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
journal.endTransaction ();
|
||||
|
|
|
@ -44,7 +44,9 @@ int CmdLengthen (
|
|||
std::set <int> ids = cli.getIds ();
|
||||
|
||||
if (ids.empty ())
|
||||
{
|
||||
throw std::string ("IDs must be specified. See 'timew help lengthen'.");
|
||||
}
|
||||
|
||||
std::string delta;
|
||||
|
||||
|
@ -52,7 +54,9 @@ int CmdLengthen (
|
|||
{
|
||||
if (arg.hasTag ("FILTER") &&
|
||||
arg._lextype == Lexer::Type::duration)
|
||||
{
|
||||
delta = arg.attribute ("raw");
|
||||
}
|
||||
}
|
||||
|
||||
journal.startTransaction ();
|
||||
|
@ -64,7 +68,9 @@ int CmdLengthen (
|
|||
for (auto& interval : intervals)
|
||||
{
|
||||
if (interval.is_open ())
|
||||
{
|
||||
throw format ("Cannot lengthen open interval @{1}", interval.id);
|
||||
}
|
||||
|
||||
database.deleteInterval (interval);
|
||||
|
||||
|
|
|
@ -44,31 +44,47 @@ int CmdModify (
|
|||
bool verbose = rules.getBoolean ("verbose");
|
||||
|
||||
if (words.empty())
|
||||
{
|
||||
throw std::string ("Must specify start|end command to modify. See 'timew help modify'.");
|
||||
}
|
||||
|
||||
if (words.at (0) == "start")
|
||||
{
|
||||
op = MODIFY_START;
|
||||
}
|
||||
else if (words.at (0) == "end")
|
||||
{
|
||||
op = MODIFY_END;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw format ("Must specify start|end command to modify. See 'timew help modify'.", words.at (0));
|
||||
}
|
||||
|
||||
if (ids.empty ())
|
||||
{
|
||||
throw std::string ("ID must be specified. See 'timew help modify'.");
|
||||
}
|
||||
|
||||
if (ids.size () > 1)
|
||||
{
|
||||
throw std::string ("Only one ID may be specified. See 'timew help modify'.");
|
||||
}
|
||||
|
||||
int id = *ids.begin();
|
||||
|
||||
flattenDatabase (database, rules);
|
||||
auto intervals = getIntervalsByIds (database, rules, ids);
|
||||
if (intervals.size () == 0)
|
||||
{
|
||||
throw format ("ID '@{1}' does not correspond to any tracking.", id);
|
||||
}
|
||||
|
||||
assert (intervals.size () == 1);
|
||||
if (filter.start.toEpoch () == 0)
|
||||
{
|
||||
throw std::string ("No updated time specified. See 'timew help modify'.");
|
||||
}
|
||||
|
||||
const Interval interval = intervals.at (0);
|
||||
Interval modified {interval};
|
||||
|
@ -80,13 +96,17 @@ int CmdModify (
|
|||
|
||||
case MODIFY_END:
|
||||
if (interval.is_open ())
|
||||
{
|
||||
throw format ("Cannot modify end of open interval @{1}.", id);
|
||||
}
|
||||
modified.end = filter.start;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!modified.is_open () && (modified.start > modified.end))
|
||||
{
|
||||
throw format ("Cannot modify interval @{1} where start is after end.", id);
|
||||
}
|
||||
|
||||
journal.startTransaction ();
|
||||
|
||||
|
|
|
@ -61,7 +61,9 @@ int CmdMove (
|
|||
for (auto& arg : cli._args)
|
||||
{
|
||||
if (arg.hasTag ("FILTER") && arg._lextype == Lexer::Type::date)
|
||||
{
|
||||
new_start = arg.attribute ("raw");
|
||||
}
|
||||
}
|
||||
|
||||
std::vector <Interval> intervals = getIntervalsByIds (database, rules, ids);
|
||||
|
@ -84,14 +86,18 @@ int CmdMove (
|
|||
auto delta = start - interval.start;
|
||||
interval.start = start;
|
||||
if (! interval.is_open ())
|
||||
{
|
||||
interval.end += delta;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
auto delta = interval.start - start;
|
||||
interval.start = start;
|
||||
if (! interval.is_open ())
|
||||
{
|
||||
interval.end -= delta;
|
||||
}
|
||||
}
|
||||
|
||||
database.deleteInterval (intervals.at (0));
|
||||
|
|
|
@ -43,14 +43,18 @@ int CmdResize (
|
|||
std::set <int> ids = cli.getIds ();
|
||||
|
||||
if (ids.empty ())
|
||||
{
|
||||
throw std::string ("IDs must be specified. See 'timew help resize'.");
|
||||
}
|
||||
|
||||
std::string delta;
|
||||
for (auto& arg : cli._args)
|
||||
{
|
||||
if (arg.hasTag ("FILTER") &&
|
||||
arg._lextype == Lexer::Type::duration)
|
||||
{
|
||||
delta = arg.attribute ("raw");
|
||||
}
|
||||
}
|
||||
|
||||
journal.startTransaction ();
|
||||
|
@ -61,7 +65,9 @@ int CmdResize (
|
|||
for (auto& interval : intervals)
|
||||
{
|
||||
if (interval.is_open ())
|
||||
{
|
||||
throw format ("Cannot resize open interval @{1}", interval.id);
|
||||
}
|
||||
|
||||
Duration dur (delta);
|
||||
database.deleteInterval (interval);
|
||||
|
|
|
@ -43,14 +43,18 @@ int CmdShorten (
|
|||
std::set <int> ids = cli.getIds ();
|
||||
|
||||
if (ids.empty ())
|
||||
{
|
||||
throw std::string ("IDs must be specified. See 'timew help shorten'.");
|
||||
}
|
||||
|
||||
std::string delta;
|
||||
for (auto& arg : cli._args)
|
||||
{
|
||||
if (arg.hasTag ("FILTER") &&
|
||||
arg._lextype == Lexer::Type::duration)
|
||||
{
|
||||
delta = arg.attribute ("raw");
|
||||
}
|
||||
}
|
||||
|
||||
journal.startTransaction ();
|
||||
|
@ -62,7 +66,9 @@ int CmdShorten (
|
|||
for (auto& interval : intervals)
|
||||
{
|
||||
if (interval.is_open ())
|
||||
{
|
||||
throw format ("Cannot shorten open interval @{1}", interval.id);
|
||||
}
|
||||
|
||||
Duration dur (delta);
|
||||
if (dur > (interval.end - interval.start))
|
||||
|
@ -79,7 +85,9 @@ int CmdShorten (
|
|||
database.addInterval (interval, verbose);
|
||||
|
||||
if (verbose)
|
||||
{
|
||||
std::cout << "Shortened @" << interval.id << " by " << dur.formatHours () << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
journal.endTransaction ();
|
||||
|
|
|
@ -43,7 +43,9 @@ int CmdSplit (
|
|||
std::set <int> ids = cli.getIds ();
|
||||
|
||||
if (ids.empty ())
|
||||
{
|
||||
throw std::string ("IDs must be specified. See 'timew help split'.");
|
||||
}
|
||||
|
||||
journal.startTransaction ();
|
||||
|
||||
|
@ -79,7 +81,9 @@ int CmdSplit (
|
|||
database.addInterval (second, verbose);
|
||||
|
||||
if (verbose)
|
||||
{
|
||||
std::cout << "Split @" << interval.id << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
journal.endTransaction ();
|
||||
|
|
|
@ -78,7 +78,9 @@ int CmdTag (
|
|||
Interval modified {interval};
|
||||
|
||||
for (auto& tag : tags)
|
||||
{
|
||||
modified.tag (tag);
|
||||
}
|
||||
|
||||
//TODO validate (cli, rules, database, i);
|
||||
database.modifyInterval (interval, modified, verbose);
|
||||
|
|
|
@ -77,7 +77,9 @@ int CmdUntag (
|
|||
Interval modified {interval};
|
||||
|
||||
for (auto& tag : tags)
|
||||
{
|
||||
modified.untag (tag);
|
||||
}
|
||||
|
||||
//TODO validate (cli, rules, database, i);
|
||||
database.modifyInterval (interval, modified, verbose);
|
||||
|
|
13
src/data.cpp
13
src/data.cpp
|
@ -26,7 +26,6 @@
|
|||
|
||||
#include <deque>
|
||||
|
||||
#include <cassert>
|
||||
#include <cmake.h>
|
||||
#include <shared.h>
|
||||
#include <format.h>
|
||||
|
@ -325,7 +324,9 @@ void flattenDatabase (Database& database, const Rules& rules)
|
|||
// Update database.
|
||||
database.deleteInterval (latest);
|
||||
for (auto& interval : flatten (modified, exclusions))
|
||||
{
|
||||
database.addInterval (interval, rules.getBoolean ("verbose"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -379,7 +380,9 @@ std::vector <Interval> getIntervalsByIds (
|
|||
for (auto& interval : synthetic)
|
||||
{
|
||||
if (id_it == id_end)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (interval.id == *id_it)
|
||||
{
|
||||
|
@ -396,7 +399,9 @@ std::vector <Interval> getIntervalsByIds (
|
|||
++current_id;
|
||||
|
||||
if (id_it == id_end)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (current_id == *id_it)
|
||||
{
|
||||
|
@ -423,8 +428,12 @@ std::vector <Interval> subset (
|
|||
{
|
||||
std::vector <Interval> all;
|
||||
for (auto& interval : intervals)
|
||||
{
|
||||
if (matchesFilter (interval, filter))
|
||||
{
|
||||
all.push_back (interval);
|
||||
}
|
||||
}
|
||||
|
||||
return all;
|
||||
}
|
||||
|
@ -731,7 +740,9 @@ std::vector <Interval> getTracked (
|
|||
|
||||
// Assign an ID to each interval.
|
||||
for (unsigned int i = 0; i < intervals.size (); ++i)
|
||||
{
|
||||
intervals[i].id = intervals.size () - i + id_skip;
|
||||
}
|
||||
|
||||
debug (format ("Loaded {1} tracked intervals", intervals.size ()));
|
||||
return subset (filter, intervals);
|
||||
|
|
|
@ -91,9 +91,13 @@ std::string intervalSummarize (
|
|||
{
|
||||
Interval current = IntervalFactory::fromSerialization (line);
|
||||
if (interval.tags () == current.tags ())
|
||||
{
|
||||
total_recorded += current.total ();
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Duration total (total_recorded);
|
||||
|
@ -103,7 +107,9 @@ std::string intervalSummarize (
|
|||
for (auto& tag : interval.tags ())
|
||||
{
|
||||
if (! tags.empty ())
|
||||
{
|
||||
tags += " ";
|
||||
}
|
||||
|
||||
tags += tagColor (rules, tag).colorize (quoteIfNeeded (tag));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue