From 8f243563f434dae41c3a6026024646af67fe72c0 Mon Sep 17 00:00:00 2001
From: Mark Carver <mark.carver@me.com>
Date: Tue, 13 Nov 2012 11:24:34 -0600
Subject: [PATCH] Fixes [#1566688] - Separate and style git format-patch

---
 dreditor.user.js | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/dreditor.user.js b/dreditor.user.js
index 70ce274..ea15b15 100644
--- a/dreditor.user.js
+++ b/dreditor.user.js
@@ -1147,6 +1147,16 @@ Drupal.dreditor.patchReview.behaviors.setup = function (context, code) {
   var $diffstat = $('<div id="diffstat"></div>').appendTo('#dreditor #bar');
   var diffstat = { files: 0, insertions: 0, deletions: 0 };
 
+  // Detect a git format-patch.
+  var gitFormat = code.match(/(From.*(?:\n|.)*?---)(.*(?:\n|.)*?(?:deletion|insertion)s?\((-|\+)\))$/im);
+  if (gitFormat && gitFormat.length) {
+    gitFormat[1] = gitFormat[1].replace('\n\n---', '');
+    gitFormat[1] = gitFormat[1].replace(/\n/g, '<br />');
+    gitFormat[2] = gitFormat[2].replace(/\n/g, '<br />');
+    $('#dreditor-content', context).append('<div id="git-format">' + gitFormat[1] + '<div class="file-stats">' + gitFormat[2] + '</div></div>');
+    code = code.replace(/(From.*(?:\n|.)*?---)(.*(?:\n|.)*?(?:deletion|insertion)s?\((-|\+)\))$/im, '');
+  }
+
   code = code.split('\n');
   in_comment = false;
   for (var n in code) {
@@ -2340,6 +2350,7 @@ table .dreditor-button { display: inline !important; margin-left: 1em; } \
 #dreditor .form-textarea { width: 100%; height: 12em; font: 12px 'Monaco','Courier New',monospace,courier,'lucida console'; color: #000; } \
 #dreditor-content { margin-left: 250px; overflow: auto; height: 100%; } \
 #dreditor-content, pre { font: 12px 'Monaco','Courier New',monospace,courier,'lucida console'; } \
+#dreditor #git-format { background: #eaf2f5; border: 1px solid #bedce7; margin: 10px 10px 10px 0; position: relative; padding: 5px; } \
 #dreditor #code { background: #f8f8f8; border: 1px solid #d8d8d8; margin: 10px 10px 10px 0; overflow: auto; position: relative; padding: 10px 0; } \
 #dreditor #code #code-delimiter { position: absolute; top: 0; height: 100%; width: 0.5em; left: 50.7em; background-color: #7a7a7a; filter: alpha(opacity=10); opacity: 0.1; z-index: 1; } \
 #dreditor #code pre { background-color: transparent; border: 0; margin: 0; padding: 0 10px; white-space: pre; } \
-- 
1.7.11.5

