Skip to content

Commit b386df0

Browse files
vladakkahatlen
authored andcommitted
store changesets which changed file when it was named differently in extra table
1 parent b9a6d4c commit b386df0

File tree

2 files changed

+42
-15
lines changed

2 files changed

+42
-15
lines changed

src/org/opensolaris/opengrok/history/JDBCHistoryCache.java

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ private void initDB(Statement s) throws SQLException {
225225
s.execute(getQuery("createTableFilechanges"));
226226
}
227227

228+
if (!tableExists(dmd, SCHEMA, "FILEMOVES")) {
229+
s.execute(getQuery("createTableFilemoves"));
230+
}
231+
228232
// Derby has some performance problems with auto-generated identity
229233
// columns when multiple threads insert into the same table
230234
// concurrently. Therefore, we have our own light-weight id generators
@@ -617,6 +621,9 @@ public void store(History history, Repository repository)
617621

618622
private static final PreparedQuery ADD_FILECHANGE =
619623
new PreparedQuery(getQuery("addFilechange"));
624+
625+
private static final PreparedQuery ADD_FILEMOVE =
626+
new PreparedQuery(getQuery("addFilemove"));
620627

621628
/**
622629
* Get ID value for revision string by querying the DB.
@@ -646,6 +653,7 @@ private void storeHistory(ConnectionResource conn, History history,
646653
PreparedStatement addChangeset = null;
647654
PreparedStatement addDirchange = null;
648655
PreparedStatement addFilechange = null;
656+
PreparedStatement addFilemove = null;
649657
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
650658

651659
// return immediately when there is nothing to do
@@ -687,6 +695,10 @@ private void storeHistory(ConnectionResource conn, History history,
687695
addFilechange = conn.getStatement(ADD_FILECHANGE);
688696
}
689697

698+
if (addFilemove == null) {
699+
addFilemove = conn.getStatement(ADD_FILEMOVE);
700+
}
701+
690702
// Success! Break out of the loop.
691703
break;
692704

@@ -748,7 +760,6 @@ private void storeHistory(ConnectionResource conn, History history,
748760
file.substring(repodir.length() + 1))) {
749761
int fileId = files.get(fullPath);
750762
addFilechange.setInt(2, fileId);
751-
addFilechange.setInt(3, 0);
752763
addFilechange.executeUpdate();
753764
}
754765
String[] pathElts = splitPath(fullPath);
@@ -801,19 +812,22 @@ private void storeHistory(ConnectionResource conn, History history,
801812
for (int i = 0;; i++) {
802813
try {
803814
int changesetId = getIdForRevision(entry.getRevision());
804-
addFilechange.setInt(1, changesetId);
805-
addFilechange.setInt(2, fileId);
815+
806816
/*
807-
* If the file exists in the changeset, set its
808-
* moved value to 0 so it can be found when performing
809-
* historyget on directory.
817+
* If the file exists in the changeset, store it in
818+
* the table tracking moves of the file when it had
819+
* one of its precedent names so it can be found
820+
* when performing historyget on directory.
810821
*/
811822
if (entry.getFiles().contains(repo_path)) {
812-
addFilechange.setInt(3, 0);
823+
addFilechange.setInt(1, changesetId);
824+
addFilechange.setInt(2, fileId);
825+
addFilechange.executeUpdate();
813826
} else {
814-
addFilechange.setInt(3, 1);
827+
addFilemove.setInt(1, changesetId);
828+
addFilemove.setInt(2, fileId);
829+
addFilemove.executeUpdate();
815830
}
816-
addFilechange.executeUpdate();
817831

818832
conn.commit();
819833
break retry;

src/org/opensolaris/opengrok/history/JDBCHistoryCache_queries.properties

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,16 @@ createTableDirchanges=\
8686
REFERENCES OPENGROK.CHANGESETS ON DELETE CASCADE, \
8787
CONSTRAINT DIRCHANGES_PK PRIMARY KEY (DIRECTORY, CHANGESET))
8888

89+
createTableFilemoves=\
90+
CREATE TABLE OPENGROK.FILEMOVES (\
91+
FILE INT NOT NULL \
92+
CONSTRAINT FILEMOVES_FK_FILE \
93+
REFERENCES OPENGROK.FILES ON DELETE CASCADE, \
94+
CHANGESET INT NOT NULL \
95+
CONSTRAINT FILEMOVES_FK_CS \
96+
REFERENCES OPENGROK.CHANGESETS ON DELETE CASCADE, \
97+
CONSTRAINT FILEMOVES_PK PRIMARY KEY (FILE, CHANGESET))
98+
8999
createTableFilechanges=\
90100
CREATE TABLE OPENGROK.FILECHANGES (\
91101
FILE INT NOT NULL \
@@ -94,8 +104,7 @@ createTableFilechanges=\
94104
CHANGESET INT NOT NULL \
95105
CONSTRAINT FILECHANGES_FK_CS \
96106
REFERENCES OPENGROK.CHANGESETS ON DELETE CASCADE, \
97-
MOVED SMALLINT NOT NULL, \
98-
CONSTRAINT FILECHANGES_PK PRIMARY KEY (FILE, CHANGESET, MOVED))
107+
CONSTRAINT FILECHANGES_PK PRIMARY KEY (FILE, CHANGESET))
99108

100109
hasCacheForDirectory=\
101110
SELECT 1 FROM OPENGROK.REPOSITORIES R, OPENGROK.DIRECTORIES D \
@@ -105,7 +114,8 @@ getFileHistory=\
105114
SELECT CS.REVISION, A.NAME, CS.TIME, CS.MESSAGE, CS.ID \
106115
FROM \
107116
OPENGROK.CHANGESETS CS \
108-
JOIN OPENGROK.FILECHANGES FC ON CS.ID = FC.CHANGESET \
117+
JOIN (SELECT * FROM OPENGROK.FILECHANGES UNION \
118+
SELECT * FROM OPENGROK.FILEMOVES) as FC ON CS.ID = FC.CHANGESET \
109119
JOIN OPENGROK.FILES F ON FC.FILE = F.ID \
110120
JOIN OPENGROK.DIRECTORIES D ON D.ID = F.DIRECTORY \
111121
JOIN OPENGROK.AUTHORS A ON A.ID = CS.AUTHOR \
@@ -129,7 +139,7 @@ getDirHistory=\
129139
getFilesInChangeset=\
130140
SELECT D.PATH || '/' || F.NAME \
131141
FROM OPENGROK.DIRECTORIES D, OPENGROK.FILES F, OPENGROK.FILECHANGES FC \
132-
WHERE D.ID = F.DIRECTORY AND F.ID = FC.FILE AND FC.MOVED = 0 \
142+
WHERE D.ID = F.DIRECTORY AND F.ID = FC.FILE \
133143
AND FC.CHANGESET = ?
134144

135145
getRepository=SELECT ID FROM OPENGROK.REPOSITORIES WHERE PATH = ?
@@ -143,8 +153,11 @@ addChangeset=\
143153

144154
addDirchange=INSERT INTO OPENGROK.DIRCHANGES(CHANGESET, DIRECTORY) VALUES (?,?)
145155

146-
addFilechange=INSERT INTO OPENGROK.FILECHANGES(CHANGESET, FILE, MOVED) \
147-
VALUES (?,?,?)
156+
addFilechange=INSERT INTO OPENGROK.FILECHANGES(CHANGESET, FILE) \
157+
VALUES (?,?)
158+
159+
addFilemove=INSERT INTO OPENGROK.FILEMOVES(CHANGESET, FILE) \
160+
VALUES (?,?)
148161

149162
getAuthors=SELECT NAME, ID FROM OPENGROK.AUTHORS WHERE REPOSITORY = ?
150163

0 commit comments

Comments
 (0)