pre-upload: silence some OWNERS line length complaints

lines with file names can get to be pretty long, and there's nothing
obvious that can be done to fix that.

BUG=chromium:982802
TEST=Tried to `repo upload` I25abfcf66bb0ba4abf6f581ad506d7e56e1a75bc
     again; no lint complaints

Change-Id: I0c555bb4de6392f3c0f7278b57e6ba6eabb7f3b9
Reviewed-on: https://chromium-review.googlesource.com/1695700
Tested-by: George Burgess <gbiv@chromium.org>
Commit-Ready: George Burgess <gbiv@chromium.org>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
diff --git a/pre-upload.py b/pre-upload.py
index a96f52e..2aedc8f 100755
--- a/pre-upload.py
+++ b/pre-upload.py
@@ -62,6 +62,7 @@
     # Other
     r".*\.java$", r".*\.mk$", r".*\.am$",
     r".*\.policy$", r".*\.conf$", r".*\.go$",
+    r"(^OWNERS|/OWNERS)",
 ]
 
 
@@ -463,9 +464,6 @@
   ]
 
   MAX_LEN = 80
-  SKIP_REGEXP = re.compile('|'.join([
-      r'https?://',
-      r'^#\s*(define|include|import|pragma|if|ifndef|endif)\b']))
 
   included, excluded = _parse_common_inclusion_options(options)
   files = _filter_files(_get_affected_files(commit),
@@ -474,9 +472,23 @@
 
   errors = []
   for afile in files:
+    skip_regexps = (
+        r'https?://',
+        r'^#\s*(define|include|import|pragma|if|ifndef|endif)\b',
+    )
+
+    if os.path.basename(afile).startswith('OWNERS'):
+      # File paths can get long, and there's no way to break them up into
+      # multiple lines.
+      skip_regexps += (
+          r'^include\b',
+          r'file:',
+      )
+
+    skip_regexps = [re.compile(x) for x in skip_regexps]
     for line_num, line in _get_file_diff(afile, commit):
       # Allow certain lines to exceed the maxlen rule.
-      if len(line) <= MAX_LEN or SKIP_REGEXP.search(line):
+      if len(line) <= MAX_LEN or any(x.search(line) for x in skip_regexps):
         continue
 
       errors.append('%s, line %s, %s chars' % (afile, line_num, len(line)))
diff --git a/pre-upload_unittest.py b/pre-upload_unittest.py
index 7d32d3b..1cb9fe0 100755
--- a/pre-upload_unittest.py
+++ b/pre-upload_unittest.py
@@ -77,6 +77,38 @@
                        for line in [3, 4, 8]],
                       failure.items)
 
+  def testCheckTreatsOwnersFilesSpecially(self):
+    affected_files = self.PatchObject(pre_upload, '_get_affected_files')
+
+    mock_files = (
+        ('foo-OWNERS', False),
+        ('OWNERS', True),
+        ('/path/to/OWNERS', True),
+        ('/path/to/OWNERS.foo', True),
+    )
+
+    mock_lines = (
+        (u'x' * 81, False),
+        (u'foo file:' + u'x' * 80, True),
+        (u'include ' + u'x' * 80, True),
+    )
+    assert all(len(line) > 80 for line, _ in mock_lines)
+
+    for file_name, is_owners in mock_files:
+      affected_files.return_value = [file_name]
+      for line, is_ok in mock_lines:
+        self.diff_mock.return_value = [(1, line)]
+        failure = pre_upload._check_no_long_lines(ProjectNamed('PROJECT'),
+                                                  'COMMIT')
+
+        assert_msg = 'file: %r; line: %r' % (file_name, line)
+        if is_owners and is_ok:
+          self.assertFalse(failure, assert_msg)
+        else:
+          self.assertTrue(failure, assert_msg)
+          self.assertIn('Found lines longer than 80 characters', failure.msg,
+                        assert_msg)
+
   def testIncludeOptions(self):
     self.PatchObject(pre_upload,
                      '_get_affected_files',