monotone-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Monotone-devel] Review of diff-p branch


From: Nathaniel Smith
Subject: [Monotone-devel] Review of diff-p branch
Date: Tue, 11 Jul 2006 03:27:43 -0700
User-agent: Mutt/1.5.11+cvs20060403

+/* Find, and write to ENCLOSER, the nearest line before POS which
matches
+ ENCLOSER_PATTERN.  We remember the last line scanned, and the
matched, to
+   avoid duplication of effort.  */
+   
+void
+hunk_consumer::find_encloser(size_t pos, string & encloser)
+{
+  typedef vector<string>::const_reverse_iterator riter;
+
+  if (!encloser_re)
+    return;
+
+  riter last = a.rbegin() + (a.size() - encloser_last_search);
+  encloser_last_search = pos;
+
+  for (riter i = a.rbegin() + (a.size() - pos); i != last; i++) {
+    if (boost::regex_search (*i, *encloser_re))
+      {
+        encloser_last_match = a.size() - (i - a.rbegin());
+        L(FL("find_encloser: from %u matching line %d, \"%s\"")
+          % pos % encloser_last_match % *i);
+
+        // the number 40 is chosen to match GNU diff.  it could safely be
+        // increased up to about 60 without overflowing the standard
+        // terminal width.
+        encloser = string(" ") + (*i).substr(0, 40);
+        return;
+      }
+  }
+
+  if (encloser_last_match)
+    {
+      ssize_t i = encloser_last_match;
+      L(FL("find_encloser: from %u matching cached %d, \"%s\"")
+        % pos % i % a[i]);
+      encloser = string(" ") + a[i].substr(0, 40);
+    }
+}
^^ I think I'd feel more comfortable here with some I()'s scattered
around here?  It is Clever, and involves Pointers, you see.


+        for (i = hunk.begin(); i != hunk.end(); i++)
+          if ((*i)[0] != ' ')
+            {
+              first_mod = i - hunk.begin();
+              break;
+            }
+        
+        find_encloser(a_begin + first_mod, encloser);
+        ost << " @@" << encloser << endl;
^^ The way the unidiff and context diff writers go back and parse
their own output seems a bit... well, odd, anyway?


The docs weren't fully updated when the code changed (and had a
weird formatting issue, with a line starting with a period).  I fixed
this.

Merged to mainline.

-- Nathaniel

-- 
Damn the Solar System.  Bad light; planets too distant; pestered with
comets; feeble contrivance; could make a better one myself.
  -- Lord Jeffrey




reply via email to

[Prev in Thread] Current Thread [Next in Thread]