From 9bbed4f265cc041638189ebac101a777d8b8c228 Mon Sep 17 00:00:00 2001 From: Sahan Kumarasinghe Date: Sat, 29 Aug 2020 20:46:12 -0400 Subject: [PATCH 1/3] Added amending status message --- gitgud/skills/user_messages.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/gitgud/skills/user_messages.py b/gitgud/skills/user_messages.py index 0fd2ca20..3adc9303 100644 --- a/gitgud/skills/user_messages.py +++ b/gitgud/skills/user_messages.py @@ -177,3 +177,26 @@ def display_entry(index, human_name, code_name, indent): code_name=item.name, indent=indent ) + + +def amending_message(before_ref, after_ref, show_hashes=True, show_files=True, show_refs=True): # noqa: E501 + file_operator = operations.get_operator() + display_data = [ + {"_name": "Before", "_commit": file_operator.repo.commit(before_ref)}, + {"_name": "After", "_commit": file_operator.repo.commit(after_ref)} + ] + + for snapshot in display_data: + commit = snapshot["_commit"] + snapshot["Message"] = commit.message + if show_hashes: + snapshot["Hash"] = commit.hexsha[:7] + if show_files: + files = file_operator.get_commit_content(commit) + snapshot["File"] = "Present" if files else "Missing" + + for snapshot in display_data: + print(snapshot["_name"] + ":") + for feature in ["Hash", "Message", "File"]: + print(feature, ": ", str(snapshot[feature]).strip()) + print() From d58e64062180d7b71f389fa3e2173c5ae7b646fa Mon Sep 17 00:00:00 2001 From: Sahan Kumarasinghe Date: Sun, 30 Aug 2020 00:42:05 -0400 Subject: [PATCH 2/3] Added branch displaying support to amending_message --- gitgud/skills/level_builder.py | 2 +- gitgud/skills/user_messages.py | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/gitgud/skills/level_builder.py b/gitgud/skills/level_builder.py index 42f67522..bdd2c5cd 100644 --- a/gitgud/skills/level_builder.py +++ b/gitgud/skills/level_builder.py @@ -18,7 +18,7 @@ from .user_messages import skill_complete from .user_messages import all_levels_complete from .user_messages import no_solutions_available - +from .user_messages import amending_message from gitgud import operations diff --git a/gitgud/skills/user_messages.py b/gitgud/skills/user_messages.py index 3adc9303..c78dc507 100644 --- a/gitgud/skills/user_messages.py +++ b/gitgud/skills/user_messages.py @@ -186,6 +186,18 @@ def amending_message(before_ref, after_ref, show_hashes=True, show_files=True, s {"_name": "After", "_commit": file_operator.repo.commit(after_ref)} ] + # Necessary for showing branches + tree = file_operator.get_current_tree() + referred_by = {} + for branch_name in tree['branches']: + target = tree['branches'][branch_name]['target'] + if target not in referred_by: + referred_by.update({target:[branch_name]}) + else: + referred_by[target].append(branch_name) + for target in referred_by: + referred_by[target] = ", ".join(referred_by[target]) + for snapshot in display_data: commit = snapshot["_commit"] snapshot["Message"] = commit.message @@ -196,7 +208,8 @@ def amending_message(before_ref, after_ref, show_hashes=True, show_files=True, s snapshot["File"] = "Present" if files else "Missing" for snapshot in display_data: - print(snapshot["_name"] + ":") - for feature in ["Hash", "Message", "File"]: - print(feature, ": ", str(snapshot[feature]).strip()) + print(snapshot["_name"] + " ({}):".format(referred_by[snapshot["_commit"].hexsha])) + for feature in snapshot: + if not feature.startswith("_"): + print(feature, ": ", str(snapshot[feature]).strip()) print() From 79477bb9a1c182bec8452372868b432ffe692c62 Mon Sep 17 00:00:00 2001 From: Sahan Kumarasinghe Date: Wed, 9 Sep 2020 16:54:24 -0400 Subject: [PATCH 3/3] Added configurable branch naming support --- gitgud/skills/level_builder.py | 2 +- gitgud/skills/user_messages.py | 29 +++++++++++++++++------------ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/gitgud/skills/level_builder.py b/gitgud/skills/level_builder.py index bdd2c5cd..42f67522 100644 --- a/gitgud/skills/level_builder.py +++ b/gitgud/skills/level_builder.py @@ -18,7 +18,7 @@ from .user_messages import skill_complete from .user_messages import all_levels_complete from .user_messages import no_solutions_available -from .user_messages import amending_message + from gitgud import operations diff --git a/gitgud/skills/user_messages.py b/gitgud/skills/user_messages.py index c78dc507..4f952f50 100644 --- a/gitgud/skills/user_messages.py +++ b/gitgud/skills/user_messages.py @@ -187,16 +187,17 @@ def amending_message(before_ref, after_ref, show_hashes=True, show_files=True, s ] # Necessary for showing branches - tree = file_operator.get_current_tree() - referred_by = {} - for branch_name in tree['branches']: - target = tree['branches'][branch_name]['target'] - if target not in referred_by: - referred_by.update({target:[branch_name]}) - else: - referred_by[target].append(branch_name) - for target in referred_by: - referred_by[target] = ", ".join(referred_by[target]) + if show_refs: + tree = file_operator.get_current_tree() + referred_by = {} + for branch_name in tree['branches']: + target = tree['branches'][branch_name]['target'] + if target not in referred_by: + referred_by.update({target: [branch_name]}) + else: + referred_by[target].append(branch_name) + for target in referred_by: + referred_by[target] = ", ".join(referred_by[target]) for snapshot in display_data: commit = snapshot["_commit"] @@ -208,8 +209,12 @@ def amending_message(before_ref, after_ref, show_hashes=True, show_files=True, s snapshot["File"] = "Present" if files else "Missing" for snapshot in display_data: - print(snapshot["_name"] + " ({}):".format(referred_by[snapshot["_commit"].hexsha])) + print(snapshot["_name"], end="") + if show_refs: + print(" ({}):".format(referred_by[snapshot["_commit"].hexsha])) + else: + print(":") for feature in snapshot: if not feature.startswith("_"): - print(feature, ": ", str(snapshot[feature]).strip()) + print(feature + ":", str(snapshot[feature]).strip()) print()