summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorDave Borowitz2011-10-19 18:55:14 (EDT)
committer Shawn O. Pearce2011-11-04 14:14:32 (EDT)
commit0f8e486a4d5f4e232c4a01119fec0e5d0148620d (patch)
tree11eea28088c35c47d69e25695ec0107a6697fa21
parentd55eb351061de32f208a924ce076bb8903e9c379 (diff)
downloadjgit-0f8e486a4d5f4e232c4a01119fec0e5d0148620d.zip
jgit-0f8e486a4d5f4e232c4a01119fec0e5d0148620d.tar.gz
jgit-0f8e486a4d5f4e232c4a01119fec0e5d0148620d.tar.bz2
Add a listener for changes to a DfsObjDatabase's pack filesrefs/changes/45/4545/3
Intended for cross-request use, so only refers to DfsRepositoryDescriptions rather than DfsRepositorys. Change-Id: I2633e472c9264d91d632069f608d53d4bdd0fc09
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsObjDatabase.java17
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPacksChangedEvent.java60
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPacksChangedListener.java57
3 files changed, 131 insertions, 3 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsObjDatabase.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsObjDatabase.java
index 5a6c630..286616e 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsObjDatabase.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsObjDatabase.java
@@ -147,7 +147,7 @@ public abstract class DfsObjDatabase extends ObjectDatabase {
}
/**
- * List all available pack files in the repository.
+ * Scan and list all available pack files in the repository.
*
* @return list of available packs. The returned array is shared with the
* implementation and must not be modified by the caller.
@@ -164,6 +164,16 @@ public abstract class DfsObjDatabase extends ObjectDatabase {
}
/**
+ * List currently known pack files in the repository, without scanning.
+ *
+ * @return list of available packs. The returned array is shared with the
+ * implementation and must not be modified by the caller.
+ */
+ public DfsPackFile[] getCurrentPacks() {
+ return packList.get().packs;
+ }
+
+ /**
* Generate a new unique name for a pack file.
*
* @param source
@@ -318,8 +328,8 @@ public abstract class DfsObjDatabase extends ObjectDatabase {
}
private PackList scanPacks(final PackList original) throws IOException {
+ PackList o, n;
synchronized (packList) {
- PackList o, n;
do {
o = packList.get();
if (o != original) {
@@ -332,8 +342,9 @@ public abstract class DfsObjDatabase extends ObjectDatabase {
if (n == o)
return n;
} while (!packList.compareAndSet(o, n));
- return n;
}
+ getRepository().fireEvent(new DfsPacksChangedEvent());
+ return n;
}
private PackList scanPacksImpl(PackList old) throws IOException {
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPacksChangedEvent.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPacksChangedEvent.java
new file mode 100644
index 0000000..1694222
--- /dev/null
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPacksChangedEvent.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2011, Google Inc.
+ * and other copyright owners as documented in the project's IP log.
+ *
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Distribution License v1.0 which
+ * accompanies this distribution, is reproduced below, and is
+ * available at http://www.eclipse.org/org/documents/edl-v10.php
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Eclipse Foundation, Inc. nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.eclipse.jgit.storage.dfs;
+
+import org.eclipse.jgit.events.RepositoryEvent;
+
+/** Describes a change to the list of packs in a {@link DfsRepository}. */
+public class DfsPacksChangedEvent
+ extends RepositoryEvent<DfsPacksChangedListener> {
+ @Override
+ public Class<DfsPacksChangedListener> getListenerType() {
+ return DfsPacksChangedListener.class;
+ }
+
+ @Override
+ public void dispatch(DfsPacksChangedListener listener) {
+ listener.onPacksChanged(this);
+ }
+}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPacksChangedListener.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPacksChangedListener.java
new file mode 100644
index 0000000..0ac43b5
--- /dev/null
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/dfs/DfsPacksChangedListener.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2011, Google Inc.
+ * and other copyright owners as documented in the project's IP log.
+ *
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Distribution License v1.0 which
+ * accompanies this distribution, is reproduced below, and is
+ * available at http://www.eclipse.org/org/documents/edl-v10.php
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Eclipse Foundation, Inc. nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.eclipse.jgit.storage.dfs;
+
+import org.eclipse.jgit.events.RepositoryListener;
+
+/** Receives {@link DfsPacksChangedEvent}s. */
+public interface DfsPacksChangedListener extends RepositoryListener {
+ /**
+ * Invoked when all packs in a repository are listed.
+ *
+ * @param event
+ * information about the packs.
+ */
+ void onPacksChanged(DfsPacksChangedEvent event);
+}