[damned-lies] Delete and recreate checkout when module.vcs_root changes
- From: Claude Paroz <claudep src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies] Delete and recreate checkout when module.vcs_root changes
- Date: Thu, 15 Oct 2015 19:23:41 +0000 (UTC)
commit 6d1619d99f44f86678110e26097a006a3527afdb
Author: Claude Paroz <claude 2xlibre net>
Date: Thu Oct 15 21:21:15 2015 +0200
Delete and recreate checkout when module.vcs_root changes
Fixes bug #754406.
stats/admin.py | 22 ++++++++++++++++++++++
stats/models.py | 11 +++++------
2 files changed, 27 insertions(+), 6 deletions(-)
---
diff --git a/stats/admin.py b/stats/admin.py
index b7a31bf..5fecec3 100644
--- a/stats/admin.py
+++ b/stats/admin.py
@@ -17,6 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
+from django import forms
from django.core.exceptions import PermissionDenied
from django.contrib import admin
from django.contrib.admin import helpers
@@ -65,7 +66,28 @@ class DomainInline(admin.StackedInline):
return super(DomainInline, self).formfield_for_foreignkey(db_field, request, **kwargs)
+class ModuleForm(forms.ModelForm):
+ class Meta:
+ model = Module
+ fields = '__all__'
+
+ def save(self, **kwargs):
+ must_renew_checkout = 'vcs_root' in self.changed_data and not self.instance._state.adding and not
self.errors
+ if must_renew_checkout:
+ old_module = Module.objects.get(pk=self.instance.pk)
+ # Delete checkout(s)
+ for branch in old_module.get_branches(reverse=True): # head branch last
+ branch.delete_checkout()
+ instance = super(ModuleForm, self).save(**kwargs)
+ if must_renew_checkout:
+ for branch in instance.get_branches():
+ # Force checkout and updating stats
+ branch.save()
+ return instance
+
+
class ModuleAdmin(admin.ModelAdmin):
+ form = ModuleForm
fieldsets = (
(None, {
'fields': (('name','description'),
diff --git a/stats/models.py b/stats/models.py
index 3292199..f7e4110 100644
--- a/stats/models.py
+++ b/stats/models.py
@@ -24,6 +24,7 @@ from collections import Counter, OrderedDict
import fnmatch
import logging
import os, sys, re
+import shutil
import threading
from datetime import datetime
from functools import total_ordering
@@ -104,10 +105,6 @@ class Module(models.Model):
def get_absolute_url(self):
return ('stats.views.module', [self.name])
- def save(self, *args, **kwargs):
- super(Module, self).save(*args, **kwargs)
- #FIXME: delete and recreate branch if vcs_root changed?
-
def get_description(self):
return self.description and _(self.description) or self.name
@@ -237,7 +234,10 @@ class Branch(models.Model):
upd_thread.start()
def delete(self):
- import shutil # os.rmdir cannot delete non-empty dirs
+ self.delete_checkout()
+ super(Branch, self).delete()
+
+ def delete_checkout(self):
# Remove the repo checkout
if self.module.vcs_type in ('cvs', 'svn'):
if os.access(self.co_path(), os.W_OK):
@@ -255,7 +255,6 @@ class Branch(models.Model):
# Remove the pot/po generated files
if os.access(self.output_dir('ui'), os.W_OK):
shutil.rmtree(self.output_dir('ui'))
- super(Branch, self).delete()
def __eq__(self, other):
if not isinstance(other, self.__class__):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]