From 8857ce199011a158caba547738d0ba352f3ca69b Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Sun, 5 Dec 2021 10:11:47 -0800 Subject: [PATCH] Fix for comparing dict/list values, closes #32 --- git_history/cli.py | 4 ++-- git_history/utils.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/git_history/cli.py b/git_history/cli.py index 4d2dc87..2a78c31 100644 --- a/git_history/cli.py +++ b/git_history/cli.py @@ -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( @@ -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 diff --git a/git_history/utils.py b/git_history/utils.py index ea168e4..7045c44 100644 --- a/git_history/utils.py +++ b/git_history/utils.py @@ -1,3 +1,4 @@ +import json import re RESERVED = ( @@ -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)