From 6852ab0dfc90ad978d8e733a48bd40922a9c1840 Mon Sep 17 00:00:00 2001 From: Tushar Makkar Date: Wed, 10 Aug 2016 20:12:48 +0530 Subject: [PATCH 1/3] Improved the commit message. Tests yet to check. --- AUTHORS | 1 + gitfs/worker/sync.py | 16 ++++++++++++---- tests/workers/test_sync.py | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/AUTHORS b/AUTHORS index 8b050972..84fc3705 100644 --- a/AUTHORS +++ b/AUTHORS @@ -6,5 +6,6 @@ to this project (in alphabetical order): * Emanuel Danci * Vlad Temian * Justus Perlwitz +* Tushar Makkar * Your name could stand here :) diff --git a/gitfs/worker/sync.py b/gitfs/worker/sync.py index 75bb81e1..ebdf1342 100644 --- a/gitfs/worker/sync.py +++ b/gitfs/worker/sync.py @@ -166,11 +166,19 @@ def commit(self, jobs): message = jobs[0]['params']['message'] else: updates = set([]) + number_of_removal = 0 + number_of_additions = 0 for job in jobs: - updates = updates | set(job['params']['add']) - updates = updates | set(job['params']['remove']) - - message = "Update {} items".format(len(updates)) + removal_set = set(job['params']['remove']) + addition_set = set(job['params']['add']) + number_of_removal += len(removal_set) + number_of_additions += len(addition_set) + updates = updates | removal_set | addition_set + + message = "Update {} items. Added {} items. " \ + "Removed {} items.".format(len(updates), + number_of_additions, + number_of_removal) old_head = self.repository.head.target new_commit = self.repository.commit(message, self.author, diff --git a/tests/workers/test_sync.py b/tests/workers/test_sync.py index 075549d9..f7cd0994 100644 --- a/tests/workers/test_sync.py +++ b/tests/workers/test_sync.py @@ -190,7 +190,7 @@ def test_commit_with_more_than_one_job(self): repository=mocked_repo) worker.commit(jobs) - asserted_message = "Update 2 items" + asserted_message = "Update 2 items. Added 2 items. Removed 1 items." mocked_repo.commit.assert_called_once_with(asserted_message, author, author) assert mocked_repo.commits.update.call_count == 1 From 78937b045c8e99a39049b134bf2176e46bb352d4 Mon Sep 17 00:00:00 2001 From: Tushar Makkar Date: Wed, 10 Aug 2016 20:38:27 +0530 Subject: [PATCH 2/3] Tests fixed --- tests/integrations/current/test_write.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/integrations/current/test_write.py b/tests/integrations/current/test_write.py index 818e351c..220a5412 100644 --- a/tests/integrations/current/test_write.py +++ b/tests/integrations/current/test_write.py @@ -59,7 +59,7 @@ def test_delete_a_directory(self, gitfs_log): shutil.rmtree("{}/a_directory/".format(self.current_path)) with pull(self.sh): - self.assert_commit_message("Update 2 items") + self.assert_commit_message("Update 2 items. Added 0 items. Removed 2 items.") self.assert_new_commit() assert os.path.exists(path) is False @@ -93,7 +93,7 @@ def test_link_a_file(self, gitfs_log): os.link(filename, link_name) with pull(self.sh): - self.assert_commit_message("Update 2 items") + self.assert_commit_message("Update 2 items. Added 2 items. Removed 0 items.") is_link = os.path.isfile(link_name) assert is_link is not False @@ -158,7 +158,7 @@ def test_create_embedded_directory(self, gitfs_log): assert os.path.exists(keep_file) self.assert_new_commit() - commit_msg = "Update 2 items" + commit_msg = "Update 2 items. Added 2 items. Removed 0 items." self.assert_commit_message(commit_msg) def test_create_directory_inside_an_already_existing_directory(self, gitfs_log): @@ -205,7 +205,7 @@ def test_create_embedded_directory_on_multiple_levels(self, gitfs_log): assert os.path.exists(keep_file) self.assert_new_commit() - commit_msg = "Update {} items".format(len(keep_files)) + commit_msg = "Update {} items. Added {} items. Removed 0 items.".format(len(keep_files), len(keep_files)) self.assert_commit_message(commit_msg) def test_create_embedded_directory_big_depth(self, gitfs_log): @@ -283,7 +283,7 @@ def test_fsync(self, gitfs_log): with pull(self.sh): self.assert_new_commit() - self.assert_commit_message("Update 1 items") + self.assert_commit_message("Update 1 items. Added 2 items. Removed 0 items.") def test_create(self, gitfs_log): filename = "{}/new_empty_file".format(self.current_path) @@ -357,7 +357,8 @@ def test_create_multiple_files(self, gitfs_log): self.assert_new_commit() with pull(self.sh): - self.assert_commit_message("Update {} items".format(no_of_files)) + self.assert_commit_message("Update {} items. Added {} items. Removed 0 items.".format(no_of_files, + no_of_files)) def test_delete_file(self, gitfs_log): filename = "{}/deletable_file".format(self.current_path) From 9b710d2253cee872e78b06fbe29bc1e0872c3ea8 Mon Sep 17 00:00:00 2001 From: Tushar Makkar Date: Thu, 11 Aug 2016 14:29:02 +0530 Subject: [PATCH 3/3] Removing the 0 items from commit message. --- gitfs/worker/sync.py | 11 ++++++----- tests/integrations/current/test_write.py | 13 ++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/gitfs/worker/sync.py b/gitfs/worker/sync.py index ebdf1342..75f05911 100644 --- a/gitfs/worker/sync.py +++ b/gitfs/worker/sync.py @@ -174,11 +174,12 @@ def commit(self, jobs): number_of_removal += len(removal_set) number_of_additions += len(addition_set) updates = updates | removal_set | addition_set - - message = "Update {} items. Added {} items. " \ - "Removed {} items.".format(len(updates), - number_of_additions, - number_of_removal) + message = "Update {} items. ".format(len(updates)) + if number_of_additions: + message += "Added {} items. ".format(number_of_additions) + if number_of_removal: + message += "Removed {} items. ".format(number_of_removal) + message = message.strip() old_head = self.repository.head.target new_commit = self.repository.commit(message, self.author, diff --git a/tests/integrations/current/test_write.py b/tests/integrations/current/test_write.py index 220a5412..ee0ceeac 100644 --- a/tests/integrations/current/test_write.py +++ b/tests/integrations/current/test_write.py @@ -59,7 +59,7 @@ def test_delete_a_directory(self, gitfs_log): shutil.rmtree("{}/a_directory/".format(self.current_path)) with pull(self.sh): - self.assert_commit_message("Update 2 items. Added 0 items. Removed 2 items.") + self.assert_commit_message("Update 2 items. Removed 2 items.") self.assert_new_commit() assert os.path.exists(path) is False @@ -93,7 +93,7 @@ def test_link_a_file(self, gitfs_log): os.link(filename, link_name) with pull(self.sh): - self.assert_commit_message("Update 2 items. Added 2 items. Removed 0 items.") + self.assert_commit_message("Update 2 items. Added 2 items.") is_link = os.path.isfile(link_name) assert is_link is not False @@ -158,7 +158,7 @@ def test_create_embedded_directory(self, gitfs_log): assert os.path.exists(keep_file) self.assert_new_commit() - commit_msg = "Update 2 items. Added 2 items. Removed 0 items." + commit_msg = "Update 2 items. Added 2 items." self.assert_commit_message(commit_msg) def test_create_directory_inside_an_already_existing_directory(self, gitfs_log): @@ -205,7 +205,7 @@ def test_create_embedded_directory_on_multiple_levels(self, gitfs_log): assert os.path.exists(keep_file) self.assert_new_commit() - commit_msg = "Update {} items. Added {} items. Removed 0 items.".format(len(keep_files), len(keep_files)) + commit_msg = "Update {} items. Added {} items.".format(len(keep_files), len(keep_files)) self.assert_commit_message(commit_msg) def test_create_embedded_directory_big_depth(self, gitfs_log): @@ -283,7 +283,7 @@ def test_fsync(self, gitfs_log): with pull(self.sh): self.assert_new_commit() - self.assert_commit_message("Update 1 items. Added 2 items. Removed 0 items.") + self.assert_commit_message("Update 1 items. Added 2 items.") def test_create(self, gitfs_log): filename = "{}/new_empty_file".format(self.current_path) @@ -357,8 +357,7 @@ def test_create_multiple_files(self, gitfs_log): self.assert_new_commit() with pull(self.sh): - self.assert_commit_message("Update {} items. Added {} items. Removed 0 items.".format(no_of_files, - no_of_files)) + self.assert_commit_message("Update {} items. Added {} items.".format(no_of_files, no_of_files)) def test_delete_file(self, gitfs_log): filename = "{}/deletable_file".format(self.current_path)