summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTodd Zullinger <tmz@pobox.com>2010-09-08 10:12:31 -0400
committerJesse Keating <jkeating@redhat.com>2010-09-08 16:23:19 -0700
commit658937cded0f763e751bce4f2f60c49199fd14ce (patch)
tree1491745e64e6a1a6370aaf278a3071bdbe53c8b8
parent61b297252e5e468cb80ade9b72dcc62132373a8c (diff)
downloadfedora-packager-658937cded0f763e751bce4f2f60c49199fd14ce.zip
fedora-packager-658937cded0f763e751bce4f2f60c49199fd14ce.tar.gz
fedora-packager-658937cded0f763e751bce4f2f60c49199fd14ce.tar.xz
fedpkg: Try not to add redundant gitignore entries
If there is a entry which matches the filename we're about to add already in the gitignore file, we don't need to bother adding another entry. This adds a match() method to GitIgnore which uses fnmatch. Under the hood, this is what git uses. It doesn't catch some of the special cases git has, but it should simply fail to match in those cases and will add a potentially redundant entry -- no different than previously.
-rw-r--r--src/pyfedpkg/__init__.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/pyfedpkg/__init__.py b/src/pyfedpkg/__init__.py
index 65e64bc..62a5654 100644
--- a/src/pyfedpkg/__init__.py
+++ b/src/pyfedpkg/__init__.py
@@ -27,6 +27,7 @@ import ConfigParser
import stat
import StringIO
import OpenSSL
+import fnmatch
# Define some global variables, put them here to make it easy to change
@@ -840,6 +841,14 @@ class GitIgnore(object):
self.__lines.append(line)
self.modified = True
+ def match(self, line):
+ line = line.lstrip('/').rstrip('\n')
+ for entry in self.__lines:
+ entry = entry.lstrip('/').rstrip('\n')
+ if fnmatch.fnmatch(line, entry):
+ return True
+ return False
+
def write(self):
""" Write the new .gitignore file if any modifications were made. """
if self.modified:
@@ -1437,7 +1446,8 @@ class PackageModule:
sources_file.write("%s %s\n" % (file_hash, file_basename))
# Add this file to .gitignore if it's not already there:
- gitignore.add('/%s' % file_basename)
+ if not gitignore.match(file_basename):
+ gitignore.add('/%s' % file_basename)
if lookaside.file_exists(self.module, file_basename, file_hash):
# Already uploaded, skip it: