summaryrefslogtreecommitdiff
path: root/platform/dvcs-api/src/com/intellij/dvcs/repo/Repository.java
blob: 47cc17866c08962acc6ba585d3d80c23d106fcfc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
 * Copyright 2000-2013 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intellij.dvcs.repo;

import com.intellij.openapi.Disposable;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vcs.AbstractVcs;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
 * <p>
 * Repository is a representation of a Git repository stored under the specified directory.
 * It stores the information about the repository, which is frequently requested by other plugin components.
 * All get-methods (like {@link #getCurrentRevision()}) are just getters of the correspondent fields and thus are very fast.
 * </p>
 * <p>
 * The Repository is updated "externally" by the appropriate Updater class}, when correspondent {@code .git/ or .hg/} service files
 * change.
 * </p>
 * <p>
 * To force asynchronous update, it is enough to call {@link VirtualFile#refresh(boolean, boolean) refresh} on the root directory.
 * </p>
 * <p>
 * To make a synchronous update of the repository call {@link #update()}.
 * Updating requires reading from disk, so it may take some time, however, updating the whole community repository took ~10 ms at the time
 * of measurement, so must be fast enough. Better not to be called in AWT though.
 * <p/>
 * <p>
 * Getters and setters (update...()-methods) are not synchronized intentionally - to avoid live- and deadlocks.
 * GitRepository is updated asynchronously,
 * so even if the getters would have been synchronized, it wouldn't guarantee that they return actual values (as they are in .git).
 * <br/>
 * If one needs a really 100 % up-to-date value, one should call {@link #update()} and then get...().
 * update() is a synchronous read from repository file (.git or .hg), so it is guaranteed to query the real value.
 * </p>
 *
 * @author Nadya Zabrodina
 */
public interface Repository extends Disposable {


  /**
   * Current state of the repository.
   */
  enum State {
    /**
     * HEAD is on branch, no merge process is in progress (and no rebase as well).
     */
    NORMAL,
    /**
     * During merge (for instance, merge failed with conflicts that weren't immediately resolved).
     */
    MERGING {
      @Override
      public String toString() {
        return "Merging";
      }
    },
    /**
     * During rebase.
     */
    REBASING {
      @Override
      public String toString() {
        return "Rebasing";
      }
    },
    /**
     * Detached HEAD state, but not during rebase (for example, manual checkout of a commit hash).
     */
    DETACHED
  }

  @NotNull
  VirtualFile getRoot();

  @NotNull
  String getPresentableUrl();

  @NotNull
  Project getProject();

  @NotNull
  State getState();

  @Nullable
  AbstractVcs getVcs();

  /**
   * Returns the hash of the revision, which HEAD currently points to.
   * Returns null only in the case of a fresh repository, when no commit have been made.
   */
  @Nullable
  String getCurrentRevision();

  /**
   * @return true if current repository is "fresh", i.e. if no commits have been made yet.
   */
  boolean isFresh();

  /**
   * Synchronously updates the Repository by reading information about it from disk (e.g. for Git: from .git/config and .git/refs/...)
   */
  void update();

  /**
   * Returns a detailed String representation suitable for logging purposes.
   */
  @NotNull
  String toLogString();
}