Adjust side-by-side display of added/deleted files to be closer to the way diff programs show
--- a/include/git/FileDiff.class.php
+++ b/include/git/FileDiff.class.php
@@ -351,6 +351,38 @@
}
/**
+ * GetFromBlob
+ *
+ * Gets the from file blob
+ *
+ * @access public
+ * @return mixed blob object
+ */
+ public function GetFromBlob()
+ {
+ if (empty($this->fromHash))
+ return null;
+
+ return $this->project->GetBlob($this->fromHash);
+ }
+
+ /**
+ * GetToBlob
+ *
+ * Gets the to file blob
+ *
+ * @access public
+ * @return mixed blob object
+ */
+ public function GetToBlob()
+ {
+ if (empty($this->toHash))
+ return null;
+
+ return $this->project->GetBlob($this->toHash);
+ }
+
+ /**
* GetStatus
*
* Gets the status of the change
@@ -556,7 +588,7 @@
$toName = null;
if ((empty($this->status)) || ($this->status == 'D') || ($this->status == 'M')) {
- $fromBlob = $this->project->GetBlob($this->fromHash);
+ $fromBlob = $this->GetFromBlob();
$fromTmpFile = 'gitphp_' . $pid . '_from';
$tmpdir->AddFile($fromTmpFile, $fromBlob->GetData());
@@ -571,7 +603,7 @@
}
if ((empty($this->status)) || ($this->status == 'A') || ($this->status == 'M')) {
- $toBlob = $this->project->GetBlob($this->toHash);
+ $toBlob = $this->GetToBlob();
$toTmpFile = 'gitphp_' . $pid . '_to';
$tmpdir->AddFile($toTmpFile, $toBlob->GetData());
--- a/templates/filediffsidebyside.tpl
+++ b/templates/filediffsidebyside.tpl
@@ -10,19 +10,37 @@
* @subpackage Template
*}
<table class="diffTable">
- {foreach from=$diffsplit item=lineinfo}
- {if $lineinfo[0]=='added'}
- <tr class="diff-added">
- {elseif $lineinfo[0]=='deleted'}
- <tr class="diff-deleted">
- {elseif $lineinfo[0]=='modified'}
- <tr class="diff-modified">
- {else}
- <tr>
- {/if}
- <td class="diff-left">{if $lineinfo[1]}{$lineinfo[1]|escape}{else} {/if}</td>
- <td>{if $lineinfo[2]}{$lineinfo[2]|escape}{else} {/if}</td>
- </tr>
- {/foreach}
+ {if $filediff->GetStatus() == 'D'}
+ {assign var=delblob value=$filediff->GetFromBlob()}
+ {foreach from=$delblob->GetData(true) item=blobline}
+ <tr class="diff-deleted">
+ <td class="diff-left">{$blobline|escape}</td>
+ <td> </td>
+ </tr>
+ {/foreach}
+ {elseif $filediff->GetStatus() == 'A'}
+ {assign var=newblob value=$filediff->GetToBlob()}
+ {foreach from=$newblob->GetData(true) item=blobline}
+ <tr class="diff-added">
+ <td class="diff-left"> </td>
+ <td>{$blobline|escape}</td>
+ </tr>
+ {/foreach}
+ {else}
+ {foreach from=$diffsplit item=lineinfo}
+ {if $lineinfo[0]=='added'}
+ <tr class="diff-added">
+ {elseif $lineinfo[0]=='deleted'}
+ <tr class="diff-deleted">
+ {elseif $lineinfo[0]=='modified'}
+ <tr class="diff-modified">
+ {else}
+ <tr>
+ {/if}
+ <td class="diff-left">{if $lineinfo[1]}{$lineinfo[1]|escape}{else} {/if}</td>
+ <td>{if $lineinfo[2]}{$lineinfo[2]|escape}{else} {/if}</td>
+ </tr>
+ {/foreach}
+ {/if}
</table>