Skip to content

Commit 06bb9c5

Browse files
committed
#3296 git: skip first version if it matches the current content and always show diff to current note text
Signed-off-by: Patrizio Bekerle <patrizio@bekerle.com>
1 parent 56ef96b commit 06bb9c5

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/utils/git.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ QJSValue Utils::Git::getNoteVersions(QJSEngine &engine, const Note &note) {
359359
git_revwalk_push_head(walker);
360360

361361
git_oid oid;
362-
QString previousContent;
362+
const QString previousContent = note.getNoteText();
363363
bool isFirst = true;
364364
int versionIndex = 0;
365365

@@ -375,6 +375,14 @@ QJSValue Utils::Git::getNoteVersions(QJSEngine &engine, const Note &note) {
375375
const char *content = (const char *)git_blob_rawcontent(blob);
376376
QString currentContent = QString::fromUtf8(content);
377377

378+
if (isFirst && currentContent == previousContent) {
379+
// Skip the first version if it matches the current content
380+
git_blob_free(blob);
381+
git_tree_entry_free(entry);
382+
isFirst = false;
383+
continue;
384+
}
385+
378386
QJSValue version = engine.newObject();
379387

380388
// Get commit timestamp
@@ -390,18 +398,12 @@ QJSValue Utils::Git::getNoteVersions(QJSEngine &engine, const Note &note) {
390398
// Store the content
391399
version.setProperty("data", currentContent);
392400

393-
// Generate diff HTML if not the first version
394-
if (!isFirst) {
395-
QList<Diff> diffs = differ.diff_main(currentContent, previousContent);
396-
differ.diff_cleanupSemantic(diffs);
397-
QString diffHtml = differ.diff_prettyHtml(diffs);
398-
version.setProperty("diffHtml", diffHtml);
399-
} else {
400-
version.setProperty("diffHtml", "");
401-
isFirst = false;
402-
}
401+
// Generate diff HTML
402+
QList<Diff> diffs = differ.diff_main(previousContent, currentContent);
403+
differ.diff_cleanupSemantic(diffs);
404+
QString diffHtml = differ.diff_prettyHtml(diffs);
405+
version.setProperty("diffHtml", diffHtml);
403406

404-
previousContent = currentContent;
405407
versions.setProperty(versionIndex++, version);
406408
// versionsArray.setProperty(versionsArray.property("length").toInt(),
407409
// version);

0 commit comments

Comments
 (0)