Adjust side-by-side display of added/deleted files to be closer to the way diff programs show
Adjust side-by-side display of added/deleted files to be closer to the way diff programs show

--- a/css/gitphpskin.css
+++ b/css/gitphpskin.css
@@ -400,6 +400,40 @@
 	border-right: 1px solid #d9d8d1;
 }
 
+/*
+ * side-by-side commitdiff
+ */
+div.commitDiffSBS
+{
+	width: 100%;
+	border-top: 2px solid #edece6;
+}
+
+div.commitDiffSBS div.SBSTOC
+{
+	float: left;
+	width: 19%;
+	word-wrap: break-word;
+}
+
+div.commitDiffSBS div.SBSTOC ul
+{
+	margin-left: 5px;
+	padding-left: 5px;
+}
+
+div.commitDiffSBS .SBSContent
+{
+	float: right;
+	width: 80%;
+	border-left: 1px solid #edece6;
+}
+
+div.commitDiffSBS .SBSFooter
+{
+	clear: both;
+}
+
 
 /*
  * Blob/blame display

--- 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/commitdiff.tpl
+++ b/templates/commitdiff.tpl
@@ -31,8 +31,44 @@
      {$line|htmlspecialchars|buglink:$bugpattern:$bugurl}<br />
    {/foreach}
    <br />
+
+   {if $sidebyside && ($treediff->Count() > 1)}
+    <div class="commitDiffSBS">
+
+     <div class="SBSTOC">
+       <ul>
+       {foreach from=$treediff item=filediff}
+       <li>
+       <a href="#{$filediff->GetFromHash()}_{$filediff->GetToHash()}">
+       {if $filediff->GetStatus() == 'A'}
+         {if $filediff->GetToFile()}{$filediff->GetToFile()}{else}{$filediff->GetToHash()}{/if} {t}(new){/t}
+       {elseif $filediff->GetStatus() == 'D'}
+         {if $filediff->GetFromFile()}{$filediff->GetFromFile()}{else}{$filediff->GetToFile()}{/if} {t}(deleted){/t}
+       {elseif $filediff->GetStatus() == 'M'}
+         {if $filediff->GetFromFile()}
+	   {assign var=fromfilename value=$filediff->GetFromFile()}
+	 {else}
+	   {assign var=fromfilename value=$filediff->GetFromHash()}
+	 {/if}
+	 {if $filediff->GetToFile()}
+	   {assign var=tofilename value=$filediff->GetToFile()}
+	 {else}
+	   {assign var=tofilename value=$filediff->GetToHash()}
+	 {/if}
+	 {$fromfilename}{if $fromfilename != $tofilename} -&gt; {$tofilename}{/if}
+       {/if}
+       </a>
+       </li>
+       {/foreach}
+       </ul>
+     </div>
+
+     <div class="SBSContent">
+   {/if}
+
    {* Diff each file changed *}
    {foreach from=$treediff item=filediff}
+     <div class="diffBlob" id="{$filediff->GetFromHash()}_{$filediff->GetToHash()}">
      <div class="diff_info">
      {if ($filediff->GetStatus() == 'D') || ($filediff->GetStatus() == 'M')}
        {assign var=localfromtype value=$filediff->GetFromFileType(1)}
@@ -60,7 +96,17 @@
      {else}
         {include file='filediff.tpl' diff=$filediff->GetDiff('', true, true)}
      {/if}
+     </div>
    {/foreach}
+
+   {if $sidebyside && ($treediff->Count() > 1)}
+     </div>
+     <div class="SBSFooter"></div>
+
+    </div>
+   {/if}
+
+
  </div>
 
  {include file='footer.tpl'}

--- 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}&nbsp;{/if}</td>
-      <td>{if $lineinfo[2]}{$lineinfo[2]|escape}{else}&nbsp;{/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>&nbsp;</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">&nbsp;</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}&nbsp;{/if}</td>
+        <td>{if $lineinfo[2]}{$lineinfo[2]|escape}{else}&nbsp;{/if}</td>
+      </tr>
+    {/foreach}
+  {/if}
 </table>
 

comments