Mercurial > jhg
annotate src/org/tmatesoft/hg/internal/ChangelogEntryBuilder.java @ 619:868b2ffdcd5c
Close FIS, not FileChannel, to clear both references to FileDescriptor right away
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 17 May 2013 22:04:23 +0200 |
parents | 7c0d2ce340b8 |
children | 4e6179bde4fc |
rev | line source |
---|---|
384
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
1 /* |
618
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
2 * Copyright (c) 2012-2013 TMate Software Ltd |
384
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
3 * |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
6 * the Free Software Foundation; version 2 of the License. |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
7 * |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
8 * This program is distributed in the hope that it will be useful, |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
11 * GNU General Public License for more details. |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
12 * |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
13 * For information on how to redistribute this software under |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
14 * the terms of a license other than GNU General Public License |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
15 * contact TMate Software at support@hg4j.com |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
16 */ |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
386
diff
changeset
|
17 package org.tmatesoft.hg.internal; |
384
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 |
618
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
19 import java.io.ByteArrayOutputStream; |
384
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
20 import java.util.ArrayList; |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
386
diff
changeset
|
21 import java.util.Collection; |
384
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
22 import java.util.Collections; |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
23 import java.util.Iterator; |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
24 import java.util.LinkedHashMap; |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
25 import java.util.List; |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
26 import java.util.Map; |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
27 import java.util.Map.Entry; |
618
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
28 import java.util.TimeZone; |
384
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
29 |
618
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
30 import org.tmatesoft.hg.core.HgIOException; |
384
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
31 import org.tmatesoft.hg.core.Nodeid; |
618
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
32 import org.tmatesoft.hg.internal.DataSerializer.DataSource; |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
386
diff
changeset
|
33 import org.tmatesoft.hg.util.Path; |
384
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
34 |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
35 /** |
618
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
36 * Builds changelog entry |
384
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
37 * @author Artem Tikhomirov |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
38 * @author TMate Software Ltd. |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
39 */ |
618
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
40 public class ChangelogEntryBuilder implements DataSource { |
384
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
41 |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
42 private String user; |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
386
diff
changeset
|
43 private List<Path> modifiedFiles; |
384
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
44 private final Map<String, String> extrasMap = new LinkedHashMap<String, String>(); |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
45 private Integer tzOffset; |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
46 private Long csetTime; |
618
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
47 private Nodeid manifestRev; |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
48 private CharSequence comment; |
384
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
49 |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
50 public ChangelogEntryBuilder user(String username) { |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
51 user = username; |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
52 return this; |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
53 } |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
54 |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
55 public String user() { |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
56 if (user == null) { |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
57 // for our testing purposes anything but null is ok. no reason to follow Hg username lookup conventions |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
58 user = System.getProperty("user.name"); |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
59 } |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
60 return user; |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
61 } |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
62 |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
386
diff
changeset
|
63 public ChangelogEntryBuilder setModified(Collection<Path> files) { |
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
386
diff
changeset
|
64 modifiedFiles = new ArrayList<Path>(files == null ? Collections.<Path>emptyList() : files); |
384
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
65 return this; |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
66 } |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
67 |
538
dd4f6311af52
Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
386
diff
changeset
|
68 public ChangelogEntryBuilder addModified(Collection<Path> files) { |
384
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
69 if (modifiedFiles == null) { |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
70 return setModified(files); |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
71 } |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
72 modifiedFiles.addAll(files); |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
73 return this; |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
74 } |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
75 |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
76 public ChangelogEntryBuilder branch(String branchName) { |
386
73e875154afb
Do not fail with empty extras string in changeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
384
diff
changeset
|
77 if (branchName == null || "default".equals(branchName)) { |
384
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
78 extrasMap.remove("branch"); |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
79 } else { |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
80 extrasMap.put("branch", branchName); |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
81 } |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
82 return this; |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
83 } |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
84 |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
85 public ChangelogEntryBuilder extras(Map<String, String> extras) { |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
86 extrasMap.clear(); |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
87 extrasMap.putAll(extras); |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
88 return this; |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
89 } |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
90 |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
91 public ChangelogEntryBuilder date(long seconds, int timezoneOffset) { |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
92 csetTime = seconds; |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
93 tzOffset = timezoneOffset; |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
94 return this; |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
95 } |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
96 |
618
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
97 public ChangelogEntryBuilder manifest(Nodeid manifestRevision) { |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
98 manifestRev = manifestRevision; |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
99 return this; |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
100 } |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
101 |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
102 public ChangelogEntryBuilder comment(CharSequence commentString) { |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
103 comment = commentString; |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
104 return this; |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
105 } |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
106 |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
107 public void serialize(DataSerializer out) throws HgIOException { |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
108 byte[] b = build(); |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
109 out.write(b, 0, b.length); |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
110 } |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
111 |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
112 public int serializeLength() { |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
113 return -1; |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
114 } |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
115 |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
116 public byte[] build() { |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
117 ByteArrayOutputStream out = new ByteArrayOutputStream(); |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
118 final int LF = '\n'; |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
119 CharSequence extras = buildExtras(); |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
120 CharSequence files = buildFiles(); |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
121 byte[] manifestRevision = manifestRev.toString().getBytes(); |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
122 byte[] username = user().getBytes(EncodingHelper.getUTF8()); |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
123 out.write(manifestRevision, 0, manifestRevision.length); |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
124 out.write(LF); |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
125 out.write(username, 0, username.length); |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
126 out.write(LF); |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
127 final long csetDate = csetTime(); |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
128 byte[] date = String.format("%d %d", csetDate, csetTimezone(csetDate)).getBytes(); |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
129 out.write(date, 0, date.length); |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
130 if (extras.length() > 0) { |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
131 out.write(' '); |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
132 byte[] b = extras.toString().getBytes(); |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
133 out.write(b, 0, b.length); |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
134 } |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
135 out.write(LF); |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
136 byte[] b = files.toString().getBytes(); |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
137 out.write(b, 0, b.length); |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
138 out.write(LF); |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
139 out.write(LF); |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
140 byte[] cmt = comment.toString().getBytes(EncodingHelper.getUTF8()); |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
141 out.write(cmt, 0, cmt.length); |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
142 return out.toByteArray(); |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
143 } |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
144 |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
145 private CharSequence buildExtras() { |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
146 StringBuilder extras = new StringBuilder(); |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
147 for (Iterator<Entry<String, String>> it = extrasMap.entrySet().iterator(); it.hasNext();) { |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
148 final Entry<String, String> next = it.next(); |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
149 extras.append(encodeExtrasPair(next.getKey())); |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
150 extras.append(':'); |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
151 extras.append(encodeExtrasPair(next.getValue())); |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
152 if (it.hasNext()) { |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
153 extras.append('\00'); |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
154 } |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
155 } |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
156 return extras; |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
157 } |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
158 |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
159 private CharSequence buildFiles() { |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
160 StringBuilder files = new StringBuilder(); |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
161 if (modifiedFiles != null) { |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
162 Collections.sort(modifiedFiles); |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
163 for (Iterator<Path> it = modifiedFiles.iterator(); it.hasNext(); ) { |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
164 files.append(it.next()); |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
165 if (it.hasNext()) { |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
166 files.append('\n'); |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
167 } |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
168 } |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
169 } |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
170 return files; |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
171 } |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
172 |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
173 private final static CharSequence encodeExtrasPair(String s) { |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
174 if (s != null) { |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
175 return s.replace("\\", "\\\\").replace("\n", "\\n").replace("\r", "\\r").replace("\00", "\\0"); |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
176 } |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
177 return s; |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
178 } |
7c0d2ce340b8
Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
538
diff
changeset
|
179 |
384
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
180 private long csetTime() { |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
181 if (csetTime != null) { |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
182 return csetTime; |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
183 } |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
184 return System.currentTimeMillis() / 1000; |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
185 } |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
186 |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
187 private int csetTimezone(long time) { |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
188 if (tzOffset != null) { |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
189 return tzOffset; |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
190 } |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
191 return -(TimeZone.getDefault().getOffset(time) / 1000); |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
192 } |
4b97847d0b2d
Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
193 } |