View Javadoc

1   /*
2    * #%L
3    * JavaHg
4    * %%
5    * Copyright (C) 2011 aragost Trifork ag
6    * %%
7    * Permission is hereby granted, free of charge, to any person obtaining a copy
8    * of this software and associated documentation files (the "Software"), to deal
9    * in the Software without restriction, including without limitation the rights
10   * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11   * copies of the Software, and to permit persons to whom the Software is
12   * furnished to do so, subject to the following conditions:
13   * 
14   * The above copyright notice and this permission notice shall be included in
15   * all copies or substantial portions of the Software.
16   * 
17   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23   * THE SOFTWARE.
24   * #L%
25   */
26  package com.aragost.javahg;
27  
28  import java.io.File;
29  import java.nio.charset.CharsetDecoder;
30  import java.util.List;
31  
32  import com.aragost.javahg.internals.ServerPool;
33  
34  /**
35   * This class represents a repository with an overlaid bundle
36   */
37  class OverlayRepository extends Repository {
38  
39      /**
40       * If not null this is the overlay bundle for the repository.
41       */
42      private Bundle bundle;
43  
44      private BaseRepository baseRepository;
45  
46      public OverlayRepository(BaseRepository repository, Bundle bundle) {
47          // Note that since the bundle has strong ref to changesets
48          // from the bundle even with weak or soft cache policy they
49          // will never be evicted
50          super(repository.getConfiguration().getCachePolicy());
51          this.baseRepository = repository;
52          this.bundle = bundle;
53          repository.getServerPool().incrementRefCount();
54      }
55  
56      public Bundle getBundle() {
57          return this.bundle;
58      }
59  
60      @Override
61      public File getDirectory() {
62          return getBaseRepository().getDirectory();
63      }
64  
65      public BaseRepository getBaseRepository() {
66          return baseRepository;
67      }
68  
69      @Override
70      public ServerPool getServerPool() {
71          return getBaseRepository().getServerPool();
72      }
73  
74      @Override
75      public void addToCommandLine(List<String> commandLine) {
76          super.addToCommandLine(commandLine);
77          commandLine.add("--repository");
78          commandLine.add(getBundle().getFile().getPath());
79      }
80  
81      @Override
82      public CharsetDecoder newDecoder() {
83          return baseRepository.newDecoder();
84      }
85  }