annotate src/org/tmatesoft/hg/internal/ChangelogEntryBuilder.java @ 713:661e77dc88ba tip

Mac support: respect Mac alternatives of command-line arguments for common unix tools
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Sun, 03 Aug 2014 18:09:00 +0200
parents fba85bc1dfb8
children
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
667
fba85bc1dfb8 Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
42 private final EncodingHelper encHelper;
384
4b97847d0b2d Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 private String user;
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 386
diff changeset
44 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
45 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
46 private Integer tzOffset;
4b97847d0b2d Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
47 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
48 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
49 private CharSequence comment;
384
4b97847d0b2d Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
50
667
fba85bc1dfb8 Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
51 ChangelogEntryBuilder(EncodingHelper encodingHelper) {
fba85bc1dfb8 Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
52 encHelper = encodingHelper;
fba85bc1dfb8 Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
53 }
fba85bc1dfb8 Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
54
384
4b97847d0b2d Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55 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
56 user = username;
4b97847d0b2d Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
57 return this;
4b97847d0b2d Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
58 }
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 public String user() {
4b97847d0b2d Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
61 if (user == null) {
4b97847d0b2d Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
62 // 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
63 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
64 }
4b97847d0b2d Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
65 return user;
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 setModified(Collection<Path> files) {
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 386
diff changeset
69 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
70 return this;
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
538
dd4f6311af52 Commit: first working version
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 386
diff changeset
73 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
74 if (modifiedFiles == null) {
4b97847d0b2d Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
75 return setModified(files);
4b97847d0b2d Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
76 }
4b97847d0b2d Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
77 modifiedFiles.addAll(files);
4b97847d0b2d Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
78 return this;
4b97847d0b2d Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
79 }
4b97847d0b2d Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
80
4b97847d0b2d Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
81 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
82 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
83 extrasMap.remove("branch");
4b97847d0b2d Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
84 } else {
4b97847d0b2d Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
85 extrasMap.put("branch", branchName);
4b97847d0b2d Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
86 }
4b97847d0b2d Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
87 return this;
4b97847d0b2d Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
88 }
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 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
91 extrasMap.clear();
4b97847d0b2d Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
92 extrasMap.putAll(extras);
4b97847d0b2d Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
93 return this;
4b97847d0b2d Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
94 }
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 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
97 csetTime = seconds;
4b97847d0b2d Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
98 tzOffset = timezoneOffset;
4b97847d0b2d Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
99 return this;
4b97847d0b2d Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
100 }
4b97847d0b2d Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
101
618
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 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
103 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
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 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
108 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
109 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
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 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
113 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
114 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
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
7c0d2ce340b8 Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
117 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
118 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
119 }
7c0d2ce340b8 Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
120
7c0d2ce340b8 Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
121 public byte[] build() {
667
fba85bc1dfb8 Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
122 ByteArrayOutputStream out = new ByteArrayOutputStream();
fba85bc1dfb8 Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
123 final int LF = '\n';
fba85bc1dfb8 Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
124 CharSequence extras = buildExtras();
fba85bc1dfb8 Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
125 CharSequence files = buildFiles();
fba85bc1dfb8 Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
126 byte[] manifestRevision = manifestRev.toString().getBytes();
fba85bc1dfb8 Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
127 byte[] username = encHelper.userToChangeset(user());
fba85bc1dfb8 Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
128 out.write(manifestRevision, 0, manifestRevision.length);
fba85bc1dfb8 Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
129 out.write(LF);
fba85bc1dfb8 Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
130 out.write(username, 0, username.length);
fba85bc1dfb8 Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
131 out.write(LF);
fba85bc1dfb8 Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
132 final long csetDate = csetTime();
fba85bc1dfb8 Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
133 byte[] date = String.format("%d %d", csetDate, csetTimezone(csetDate)).getBytes();
fba85bc1dfb8 Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
134 out.write(date, 0, date.length);
fba85bc1dfb8 Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
135 if (extras.length() > 0) {
fba85bc1dfb8 Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
136 out.write(' ');
fba85bc1dfb8 Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
137 byte[] b = extras.toString().getBytes();
618
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(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
139 }
667
fba85bc1dfb8 Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
140 out.write(LF);
fba85bc1dfb8 Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
141 byte[] b = encHelper.fileToChangeset(files);
fba85bc1dfb8 Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
142 out.write(b, 0, b.length);
fba85bc1dfb8 Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
143 out.write(LF);
fba85bc1dfb8 Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
144 out.write(LF);
fba85bc1dfb8 Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
145 byte[] cmt = encHelper.commentToChangeset(comment);
fba85bc1dfb8 Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
146 out.write(cmt, 0, cmt.length);
fba85bc1dfb8 Refactoring: move all encoding/decoding operations into single place, EncodingHelper
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
147 return out.toByteArray();
618
7c0d2ce340b8 Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
148 }
7c0d2ce340b8 Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
149
7c0d2ce340b8 Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
150 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
151 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
152 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
153 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
154 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
155 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
156 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
157 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
158 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
159 }
7c0d2ce340b8 Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
160 }
7c0d2ce340b8 Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
161 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
162 }
7c0d2ce340b8 Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
163
7c0d2ce340b8 Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
164 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
165 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
166 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
167 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
168 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
169 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
170 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
171 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
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 }
7c0d2ce340b8 Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
174 }
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 files;
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
7c0d2ce340b8 Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
178 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
179 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
180 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
181 }
7c0d2ce340b8 Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
182 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
183 }
7c0d2ce340b8 Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 538
diff changeset
184
384
4b97847d0b2d Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
185 private long csetTime() {
4b97847d0b2d Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
186 if (csetTime != null) {
4b97847d0b2d Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
187 return csetTime;
4b97847d0b2d Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
188 }
4b97847d0b2d Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
189 return System.currentTimeMillis() / 1000;
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
4b97847d0b2d Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
192 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
193 if (tzOffset != null) {
4b97847d0b2d Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
194 return tzOffset;
4b97847d0b2d Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
195 }
4b97847d0b2d Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
196 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
197 }
4b97847d0b2d Auxilary builders for manifest and changelog to create test repositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
198 }