From 1207947afee4d7fbd2ee374339d5e84bb0528e9a Mon Sep 17 00:00:00 2001 From: James Moger Date: Wed, 12 Mar 2014 22:25:52 -0400 Subject: [PATCH] Fix TicketModel modList bug when a field was set multiple times --- .../com/gitblit/git/PatchsetReceivePack.java | 6 +++--- .../java/com/gitblit/models/TicketModel.java | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/gitblit/git/PatchsetReceivePack.java b/src/main/java/com/gitblit/git/PatchsetReceivePack.java index d3d0b1df..bdba8b91 100644 --- a/src/main/java/com/gitblit/git/PatchsetReceivePack.java +++ b/src/main/java/com/gitblit/git/PatchsetReceivePack.java @@ -163,11 +163,11 @@ public class PatchsetReceivePack extends GitblitReceivePack { /** Extracts the ticket id from the ref name */ private long getTicketId(String refName) { + if (refName.indexOf('%') > -1) { + refName = refName.substring(0, refName.indexOf('%')); + } if (refName.startsWith(Constants.R_FOR)) { String ref = refName.substring(Constants.R_FOR.length()); - if (ref.indexOf('%') > -1) { - ref = ref.substring(0, ref.indexOf('%')); - } try { return Long.parseLong(ref); } catch (Exception e) { diff --git a/src/main/java/com/gitblit/models/TicketModel.java b/src/main/java/com/gitblit/models/TicketModel.java index fa09ec59..aced6d78 100644 --- a/src/main/java/com/gitblit/models/TicketModel.java +++ b/src/main/java/com/gitblit/models/TicketModel.java @@ -785,7 +785,21 @@ public class TicketModel implements Serializable, Comparable { for (String item : items) { list.add(prefix + item); } - setField(field, join(list, ",")); + if (hasField(field)) { + String flat = getString(field); + if (isEmpty(flat)) { + // field is empty, use this list + setField(field, join(list, ",")); + } else { + // merge this list into the existing field list + Set set = new TreeSet(Arrays.asList(flat.split(","))); + set.addAll(list); + setField(field, join(set, ",")); + } + } else { + // does not have a list for this field + setField(field, join(list, ",")); + } } public String getId() { -- 2.39.5