From 661c24dca6da17caaa71366f350c7b4c52b94e96 Mon Sep 17 00:00:00 2001 From: Marco Villegas Date: Mon, 3 Nov 2014 23:46:33 -0500 Subject: [PATCH 1/2] New table for notes last state. --- versioncontrol_git.install | 55 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/versioncontrol_git.install b/versioncontrol_git.install index bc9ba38..380a382 100644 --- a/versioncontrol_git.install +++ b/versioncontrol_git.install @@ -269,6 +269,30 @@ function versioncontrol_git_schema() { ), ); + $schema['versioncontrol_git_notes'] = array( + 'description' => 'Representation of last state of git note refs.', + 'fields' => array( + 'label_id' => array( + 'description' => 'Foreign key to {versioncontrol_labels}.label_id.', + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + ), + 'vc_op_id' => array( + 'description' => 'Foreign key to {versioncontrol_operations}.vc_op_id.', + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + ), + 'message' => array( + 'description' => 'Note message.', + 'type' => 'text', + 'not null' => FALSE, + ), + ), + 'primary key' => array('label_id', 'vc_op_id'), + ); + // @fixme Use new schema field binary key for this. // Wait until we have a D7 release with it(7.13). // Details on http://drupal.org/node/1237252. @@ -594,3 +618,34 @@ function versioncontrol_git_update_7101() { return t('Created repository manager queue items to update invalid default branches.'); } + +/** + * Creates {versioncontrol_git_notes} table. + */ +function versioncontrol_git_update_7102() { + $schema = array( + 'description' => 'Representation of last state of git note refs.', + 'fields' => array( + 'label_id' => array( + 'description' => 'Foreign key to {versioncontrol_labels}.label_id.', + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + ), + 'vc_op_id' => array( + 'description' => 'Foreign key to {versioncontrol_operations}.vc_op_id.', + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + ), + 'message' => array( + 'description' => 'Note message.', + 'type' => 'text', + 'not null' => FALSE, + ), + ), + 'primary key' => array('label_id', 'vc_op_id'), + ); + db_create_table('versioncontrol_git_notes', $schema); + return t('Created a table for git notes last state.'); +} -- 1.7.10.4 From 2bc3a444e3d0d1dc8398422b293e0cb7c89c4300 Mon Sep 17 00:00:00 2001 From: Marco Villegas Date: Tue, 4 Nov 2014 02:06:39 -0500 Subject: [PATCH 2/2] Start implementation, see fixmes --- ...tRepositoryHistorySynchronizerDefault.class.php | 55 ++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/includes/plugins/reposync/VersioncontrolGitRepositoryHistorySynchronizerDefault.class.php b/includes/plugins/reposync/VersioncontrolGitRepositoryHistorySynchronizerDefault.class.php index dccafd0..2af10ce 100644 --- a/includes/plugins/reposync/VersioncontrolGitRepositoryHistorySynchronizerDefault.class.php +++ b/includes/plugins/reposync/VersioncontrolGitRepositoryHistorySynchronizerDefault.class.php @@ -127,6 +127,9 @@ class VersioncontrolGitRepositoryHistorySynchronizerDefault implements Versionco $this->parseAndInsertCommit($hash, $branches_db, $tags_in_db_by_name, $options); } + // 4. Process notes. + $this->parseAndInsertNotes(); + $this->finalize(); return TRUE; @@ -580,6 +583,9 @@ class VersioncontrolGitRepositoryHistorySynchronizerDefault implements Versionco return $commit_hashes; } + /** + * @todo Support git notes. + */ public function syncEvent(VersioncontrolEvent $event, $options) { if (!$this->verify() || !$this->prepare()) { return FALSE; @@ -770,4 +776,53 @@ class VersioncontrolGitRepositoryHistorySynchronizerDefault implements Versionco return $match[1]; } + + /** + * Retrieve all notes and add them to database. + * + * Re-add all data. + * @fixme parse notes history to be able to map. + * @todo If this approach is performant enough, do the same than in other + * objects. + */ + protected function parseAndInsertNotes() { + db_query('DELETE n FROM versioncontrol_git_notes n INNER JOIN versioncontrol_operations o ON n.vc_op_id = o.vc_op_id WHERE repo_id = :repo_id', array(':repo_id' => $this->repository->repo_id))->execute(); + $refs = $this->execute('show-ref'); + while (($line = next($refs)) !== FALSE) { + list($hash, $ref) = explode(' ', $line); + if (strpos($ref, 'refs/notes/') === FALSE) { + // Not a note. + continue; + } + $notes_list_command = 'notes --ref ' . escapeshellarg($ref) . ' list'; + $notes_list = $this->execute($notes_list_command); + while (($note = next($notes_list)) !== FALSE) { + // @todo is it possible to have notes on non-commit object? + list($note_hash, $object_hash) = explode(' ', $note); + $vc_op_id = db_query('SELECT vc_op_id WHERE repo_id = !repo_id AND revision = !revision', array('!repo_id' => $this->repository->repo_id, '!revision' => $object_hash))->fetchField(); + $note_output_command = 'cat-file -p ' . escapeshellarg($note_hash); + $note_output = $this->execute($note_output_command); + $note_message = ''; + // @todo test multiple-lines note. + while (($note_line = next($note_output)) !== FALSE) { + $note_message .= $note_line; + } + var_dump(array( + $ref, + $note_hash, + $object_hash, + $note_message, + )); + // Store it. + //db_insert('versioncontrol_git_notes') + //->fields(array( + //'label_id' => , + //'vc_op_id' => , + //'message' => $note_message, + //)) + //->execute(); + } + } + } + } -- 1.7.10.4