Skip to content

Commit 46e1b65

Browse files
committed
prevent uploading a revision that already exists to a different branch
1 parent 9eb1f6c commit 46e1b65

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

codespeed/admin.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class RevisionAdmin(admin.ModelAdmin):
5555
list_display = ('commitid', 'branch', 'tag', 'date')
5656
list_filter = ('branch__project', 'branch', 'tag', 'date')
5757
search_fields = ('commitid', 'tag')
58+
raw_id_fields = ('branch',)
5859

5960

6061
@admin.register(Executable)
@@ -87,6 +88,7 @@ class ResultAdmin(admin.ModelAdmin):
8788
list_display = ('revision', 'benchmark', 'executable', 'environment',
8889
'value', 'date')
8990
list_filter = ('environment', 'executable', 'date', 'benchmark')
91+
raw_id_fields = ('revision', 'benchmark', 'executable', 'environment')
9092

9193

9294
def recalculate_report(modeladmin, request, queryset):

codespeed/results.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,23 @@ def save_result(data, update_repo=True):
7777
try:
7878
rev = branch.revisions.get(commitid=data['commitid'].split(":")[-1])
7979
except Revision.DoesNotExist:
80+
commitid = data['commitid'].split(':')[-1]
81+
conflict = Revision.objects.filter(
82+
commitid=commitid, branch__project=p
83+
).exclude(branch=branch).first()
84+
if conflict:
85+
return (
86+
"Revision %s already exists on branch '%s'; "
87+
"refusing to add it to branch '%s'" % (
88+
commitid, conflict.branch.name, data['branch'])
89+
), True
8090
rev_date = data.get("revision_date")
8191
# "None" (as string) can happen when we urlencode the POST data
8292
if not rev_date or rev_date in ["", "None"]:
8393
rev_date = datetime.today()
8494
# Only take the hash of a mercurial nnn:xxxhash commitid
8595
rev = Revision(branch=branch, project=p,
86-
commitid=data['commitid'].split(':')[-1],
96+
commitid=commitid,
8797
date=rev_date)
8898
try:
8999
rev.full_clean()

0 commit comments

Comments
 (0)