From 1fe6e4da57d92cb1d827d42fa709fb8bc9374352 Mon Sep 17 00:00:00 2001 From: Brian Stinson Date: Jul 25 2015 00:39:31 +0000 Subject: reimplement the unused-patches command for the CentOS layout --- diff --git a/src/centpkg/__init__.py b/src/centpkg/__init__.py index 0935933..adb3adc 100644 --- a/src/centpkg/__init__.py +++ b/src/centpkg/__init__.py @@ -291,6 +291,28 @@ class Commands(Commands): def prep(self, *args, **kwargs): raise NotImplementedError("prep is not yet implemented in centpkg") - def unused_patches(self, *args, **kwargs): - raise NotImplementedError("unused_patches is not yet implemented in centpkg") + def unused_patches(self): + """Discover patches checked into source control that are not used + + Returns a list of unused patches, which may be empty. + """ + + # Create a list for unused patches + unused = [] + # Get the content of spec into memory for fast searching + spec = open(self.spec, 'r').read() + # Replace %{name} with the package name + spec = spec.replace("%{name}", self.module_name) + # Replace %{version} with the package version + spec = spec.replace("%{version}", self.ver) + + # Get a list of files tracked in source control + files = self.repo.git.ls_files('--exclude-standard').split() + for file in map(os.path.basename, files): + # throw out non patches + if not file.endswith(('.patch', '.diff')): + continue + if file not in spec: + unused.append(file) + return unused