Split file history into one pre tag per commit

This commit is contained in:
Akbar Rahman 2021-08-21 03:04:59 +01:00
parent 7e85e2a1fa
commit 56688b26f5
3 changed files with 21 additions and 5 deletions

View File

@ -55,12 +55,28 @@ def git_filehistory(working_dir, filename):
stdout=subprocess.PIPE stdout=subprocess.PIPE
) )
filehistory = f"File history not available: git log returned code {git_response.returncode}." filehistory = [f"File history not available: git log returned code {git_response.returncode}."
"\nIf this is not a git repository, this is not a problem." "\nIf this is not a git repository, this is not a problem."]
if git_response.returncode == 0: if git_response.returncode == 0:
filehistory = git_response.stdout.decode('utf-8') filehistory = git_response.stdout.decode('utf-8')
temp = re.split(
r'(commit [a-f0-9]{40})',
filehistory,
flags=re.IGNORECASE
)
for t in temp:
if t == '':
temp.remove(t)
filehistory = []
for i in range(0, len(temp)-1, 2):
filehistory.append(f"{temp[i]}{temp[i+1]}")
if filehistory == "": if filehistory == "":
filehistory = "This file has no history (it may not be part of the git repository)." filehistory = ["This file has no history (it may not be part of the git repository)."]
filehistory = "<pre>\n" + "</pre><pre>\n".join(filehistory) + "</pre>"
return filehistory return filehistory

View File

@ -20,7 +20,7 @@
<summary class="smallText"> <summary class="smallText">
Commit log (file history) Commit log (file history)
</summary> </summary>
<pre>$filehistory$</pre> $filehistory$
</details> </details>
<div> <div>
$body$ $body$

View File

@ -13,7 +13,7 @@
<summary class="smallText"> <summary class="smallText">
Commit log (file history) Commit log (file history)
</summary> </summary>
<pre>$filehistory$</pre> $filehistory$
</details> </details>
</div> </div>
<h1>$title$</h1> <h1>$title$</h1>