Mercurial > hg4j
annotate src/org/tmatesoft/hg/internal/RevlogDelegate.java @ 696:5b5d199e2eb3
Replaced ganymed ssh2 library with trilead
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Mon, 05 Aug 2013 19:03:22 +0200 |
parents | 053bb4397bf9 |
children |
rev | line source |
---|---|
695
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
1 /* |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2013 TMate Software Ltd |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
3 * |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
6 * the Free Software Foundation; version 2 of the License. |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
7 * |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
8 * This program is distributed in the hope that it will be useful, |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
11 * GNU General Public License for more details. |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
12 * |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
13 * For information on how to redistribute this software under |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
14 * the terms of a license other than GNU General Public License |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
15 * contact TMate Software at support@hg4j.com |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
16 */ |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
17 package org.tmatesoft.hg.internal; |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
19 import org.tmatesoft.hg.core.Nodeid; |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
20 import org.tmatesoft.hg.internal.RevlogStream.Inspector; |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
21 import org.tmatesoft.hg.repo.HgRepository; |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
22 import org.tmatesoft.hg.repo.HgRuntimeException; |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
23 |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
24 /** |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
25 * Does almost nothing, facilitates chains of inspectors and sharing certain information between them |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
26 * |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
27 * @author Artem Tikhomirov |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
28 * @author TMate Software Ltd. |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
29 */ |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
30 public abstract class RevlogDelegate implements RevlogStream.Inspector { |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
31 |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
32 private final Inspector next; |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
33 private Nodeid nid; |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
34 private final RevlogDelegate nextAsRD; |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
35 |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
36 protected RevlogDelegate(RevlogStream.Inspector nextInChain) { |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
37 next = nextInChain; |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
38 if (nextInChain instanceof RevlogDelegate) { |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
39 // additional benefits |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
40 nextAsRD = (RevlogDelegate) nextInChain; |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
41 } else { |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
42 nextAsRD = null; |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
43 } |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
44 } |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
45 |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
46 /** |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
47 * iterates index only and ensures pre/post processing is invoked for the chain |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
48 */ |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
49 public void walk(HgRepository hgRepo, RevlogStream stream, int from, int to) { |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
50 // hgRepo is handy for present uses, but is generally not appropriate, |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
51 // it's ok to refactor and let subclasses get what they need through e.g. a cons |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
52 stream.iterate(from, to, false, this); |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
53 postWalk(hgRepo); |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
54 } |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
55 |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
56 // does nothing but gives a chance to delegate to handle the same |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
57 protected void postWalk(HgRepository hgRepo) { |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
58 if (nextAsRD != null) { |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
59 nextAsRD.postWalk(hgRepo); |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
60 } |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
61 } |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
62 |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
63 /** |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
64 * @return Nodeid of current revision if already known, or a new instance otherwise. |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
65 * The value will propagate to subsequent {@link RevlogDelegate RevlogDelegates}, if any |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
66 */ |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
67 protected Nodeid getRevision(byte[] nodeid) { |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
68 if (nid == null) { |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
69 nid = Nodeid.fromBinary(nodeid, 0); |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
70 } |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
71 return nid; |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
72 } |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
73 |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
74 protected void setRevision(Nodeid nodeid) { |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
75 nid = nodeid; |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
76 } |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
77 |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
78 public void next(int revisionIndex, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess data) throws HgRuntimeException { |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
79 if (next != null) { |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
80 if (nextAsRD != null) { |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
81 nextAsRD.setRevision(nid); // null is fine |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
82 } |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
83 next.next(revisionIndex, actualLen, baseRevision, linkRevision, parent1Revision, parent2Revision, nodeid, data); |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
84 } |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
85 nid = null; // forget it, get ready for the next iteration |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
86 } |
053bb4397bf9
Refactoring: nice Revlog.indexWalk() implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
87 } |