Skip to content

Commit

Permalink
Fix for comparing dict/list values, closes #32
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Dec 5, 2021
1 parent b132142 commit 8857ce1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions git_history/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import sqlite_utils
import textwrap
from pathlib import Path
from .utils import fix_reserved_columns
from .utils import fix_reserved_columns, is_different


def iterate_file_versions(
Expand Down Expand Up @@ -382,7 +382,7 @@ def column_id(column):
key: value
for key, value in item.items()
if (key not in previous_item)
or previous_item[key] != value
or is_different(previous_item[key], value)
}
except IndexError:
# First version of this item
Expand Down
12 changes: 12 additions & 0 deletions git_history/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import re

RESERVED = (
Expand Down Expand Up @@ -28,3 +29,14 @@ def _fix_key(key):
return key + "_"
else:
return key


def _comparable(obj):
if isinstance(obj, (tuple, list, dict)):
return json.dumps(obj, default=repr)
return obj


def is_different(one, two):
"Compares values, including lists and dictionaries"
return _comparable(one) != _comparable(two)

0 comments on commit 8857ce1

Please sign in to comment.