Skip to content

Commit

Permalink
trivial:coding-style: Add curly braces around blocks modified recently
Browse files Browse the repository at this point in the history
timwarrior coding standard is for there to be curly braces around all code
blocks.

See GothenburgBitFactory#269 (comment)
  • Loading branch information
sruffell committed Jan 18, 2020
1 parent ac578ba commit afac583
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/Database.cpp
Expand Up @@ -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 ;

Expand Down
12 changes: 12 additions & 0 deletions src/commands/CmdContinue.cpp
Expand Up @@ -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 ();

Expand All @@ -56,18 +58,24 @@ 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 ();
}
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;
}
Expand Down Expand Up @@ -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);
Expand All @@ -106,7 +116,9 @@ int CmdContinue (
journal.endTransaction ();

if (verbose)
{
std::cout << intervalSummarize (database, rules, to_copy);
}

return 0;
}
Expand Down
4 changes: 4 additions & 0 deletions src/commands/CmdDelete.cpp
Expand Up @@ -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 ();

Expand All @@ -52,7 +54,9 @@ int CmdDelete (
database.deleteInterval (interval);

if (rules.getBoolean ("verbose"))
{
std::cout << "Deleted @" << interval.id << '\n';
}
}

journal.endTransaction ();
Expand Down
6 changes: 6 additions & 0 deletions src/commands/CmdLengthen.cpp
Expand Up @@ -44,15 +44,19 @@ 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;

for (auto& arg : cli._args)
{
if (arg.hasTag ("FILTER") &&
arg._lextype == Lexer::Type::duration)
{
delta = arg.attribute ("raw");
}
}

journal.startTransaction ();
Expand All @@ -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);

Expand Down
20 changes: 20 additions & 0 deletions src/commands/CmdModify.cpp
Expand Up @@ -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};
Expand All @@ -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 ();

Expand Down
6 changes: 6 additions & 0 deletions src/commands/CmdMove.cpp
Expand Up @@ -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);
Expand All @@ -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));
Expand Down
6 changes: 6 additions & 0 deletions src/commands/CmdResize.cpp
Expand Up @@ -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 ();
Expand All @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions src/commands/CmdShorten.cpp
Expand Up @@ -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 ();
Expand All @@ -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))
Expand All @@ -79,7 +85,9 @@ int CmdShorten (
database.addInterval (interval, verbose);

if (verbose)
{
std::cout << "Shortened @" << interval.id << " by " << dur.formatHours () << '\n';
}
}

journal.endTransaction ();
Expand Down
4 changes: 4 additions & 0 deletions src/commands/CmdSplit.cpp
Expand Up @@ -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 ();

Expand Down Expand Up @@ -79,7 +81,9 @@ int CmdSplit (
database.addInterval (second, verbose);

if (verbose)
{
std::cout << "Split @" << interval.id << '\n';
}
}

journal.endTransaction ();
Expand Down
2 changes: 2 additions & 0 deletions src/commands/CmdTag.cpp
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/commands/CmdUntag.cpp
Expand Up @@ -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);
Expand Down
13 changes: 12 additions & 1 deletion src/data.cpp
Expand Up @@ -26,7 +26,6 @@

#include <deque>

#include <cassert>
#include <cmake.h>
#include <shared.h>
#include <format.h>
Expand Down Expand Up @@ -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"));
}
}
}
}
Expand Down Expand Up @@ -379,7 +380,9 @@ std::vector <Interval> getIntervalsByIds (
for (auto& interval : synthetic)
{
if (id_it == id_end)
{
break;
}

if (interval.id == *id_it)
{
Expand All @@ -396,7 +399,9 @@ std::vector <Interval> getIntervalsByIds (
++current_id;

if (id_it == id_end)
{
break;
}

if (current_id == *id_it)
{
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit afac583

Please sign in to comment.