Avoid unnecessary updates to $GIT_DIR/description

If the application code tries to change the description file,
but its already set to the new description text, don't write
out the LockFile and commit it, instead leave things alone.
This avoids updating $GIT_DIR/description unless there will be
an actual content change.

Change-Id: I75613c49ad2f7d8e48e998229c37b23c9ad04675
Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
Shawn O. Pearce 2011-01-10 14:56:37 -08:00
parent 7c5d28a9a2
commit 3b0ecf4984

View File

@ -156,41 +156,48 @@ public class LocalDiskRepositoryManager implements GitRepositoryManager {
throws RepositoryNotFoundException, IOException {
final Repository e = openRepository(name);
try {
final File d = new File(e.getDirectory(), "description");
String description;
try {
description = RawParseUtils.decode(IO.readFully(d));
} catch (FileNotFoundException err) {
return null;
}
if (description != null) {
description = description.trim();
if (description.isEmpty()) {
description = null;
}
if (UNNAMED.equals(description)) {
description = null;
}
}
return description;
return getProjectDescription(e);
} finally {
e.close();
}
}
private String getProjectDescription(final Repository e) throws IOException {
final File d = new File(e.getDirectory(), "description");
String description;
try {
description = RawParseUtils.decode(IO.readFully(d));
} catch (FileNotFoundException err) {
return null;
}
if (description != null) {
description = description.trim();
if (description.isEmpty()) {
description = null;
}
if (UNNAMED.equals(description)) {
description = null;
}
}
return description;
}
public void setProjectDescription(final Project.NameKey name,
final String description) {
// Update git's description file, in case gitweb is being used
//
try {
final Repository e;
final LockFile f;
e = openRepository(name);
final Repository e = openRepository(name);
try {
f = new LockFile(new File(e.getDirectory(), "description"), FS.DETECTED);
final String old = getProjectDescription(e);
if ((old == null && description == null)
|| (old != null && old.equals(description))) {
return;
}
final LockFile f = new LockFile(new File(e.getDirectory(), "description"), FS.DETECTED);
if (f.lock()) {
String d = description;
if (d != null) {