From 658937cded0f763e751bce4f2f60c49199fd14ce Mon Sep 17 00:00:00 2001 From: Todd Zullinger Date: Wed, 8 Sep 2010 10:12:31 -0400 Subject: 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. --- src/pyfedpkg/__init__.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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: -- cgit