/[drupal]/contributions/modules/versioncontrol_svn/versioncontrol_svn.log.inc
ViewVC logotype

Contents of /contributions/modules/versioncontrol_svn/versioncontrol_svn.log.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.9 - (show annotations) (download) (as text)
Sat Jun 20 10:09:29 2009 UTC (5 months, 1 week ago) by jpetso
Branch: MAIN
CVS Tags: HEAD
Changes since 1.8: +10 -10 lines
File MIME type: text/x-php
#491544 by chrono325: Uncomment log insertion lines.

This allows the repository log database to be updated.

Signed-off-by: Dan Hackney <chrono325@gmail.com>
1 <?php
2 // $Id: versioncontrol_svn.log.inc,v 1.8 2009-05-10 02:04:46 sdboyer Exp $
3 /**
4 * @file
5 * Subversion backend for Version Control API - Provides Subversion commit
6 * information and account management as a pluggable backend.
7 *
8 * This file provides functionality to parse the output of 'svn log' (with
9 * support from 'svn info') and transform it into Version Control API commits.
10 *
11 * Copyright 2007, 2008 by Jakob Petsovits ("jpetso", http://drupal.org/user/56020)
12 * Copyright 2008, 2009 by Sam Boyer ("sdboyer", http://drupal.org/user/146719)
13 */
14
15 require_once(drupal_get_path('module', 'versioncontrol_svn') .'/logparser.inc');
16
17 /**
18 * Actually update the repository by fetching commits and other stuff
19 * directly from the repository, invoking the svn executable.
20 *
21 * @return
22 * TRUE if the logs were updated, NULL if no new entries were fetched
23 * (without errors, though), or FALSE if fetching and updating the logs
24 * failed because of an error.
25 */
26 function _versioncontrol_svn_log_update_repository(&$repository) {
27 $svnlib_mapping = array(
28 'actions' => array(
29 VERSIONCONTROL_SVN_ACTION_ADD => VERSIONCONTROL_ACTION_ADDED,
30 VERSIONCONTROL_SVN_ACTION_MODIFY => VERSIONCONTROL_ACTION_MODIFIED,
31 VERSIONCONTROL_SVN_ACTION_REPLACE => VERSIONCONTROL_ACTION_MODIFIED,
32 VERSIONCONTROL_SVN_ACTION_REPLACE_INPLACE => VERSIONCONTROL_ACTION_ADDED,
33 VERSIONCONTROL_SVN_ACTION_MOVE => VERSIONCONTROL_ACTION_MOVED,
34 VERSIONCONTROL_SVN_ACTION_COPY => VERSIONCONTROL_ACTION_COPIED,
35 VERSIONCONTROL_SVN_ACTION_DELETE_SIMPLE => VERSIONCONTROL_ACTION_DELETED,
36 VERSIONCONTROL_SVN_ACTION_DELETE_UGLY => VERSIONCONTROL_ACTION_DELETED,
37 ),
38 'types' => array(
39 'file' => VERSIONCONTROL_ITEM_FILE,
40 'dir' => VERSIONCONTROL_ITEM_DIRECTORY,
41 ),
42 );
43
44 // $repository['repo'] = svnlib_get_repository($repository['root']);
45 $repo = &$repository['repo'];
46 if (!empty($repository['svn_specific']['auth_username'])) {
47 $repo->username($repository['svn_specific']['auth_username']);
48 $repo->password($repository['svn_specific']['auth_password']);
49 }
50
51 $latest_rev = $repo->getLatestRev();
52 $last_revision = $repository['svn_specific']['last_revision'];
53 // Don't try to update if there's nothing to update.
54 if ($last_revision == $latest_rev) {
55 // Anyways, we want to remember the time when we tried that.
56 $repository['svn_specific']['updated'] = time();
57 db_query('UPDATE {versioncontrol_svn_repositories}
58 SET updated = %d WHERE repo_id = %d',
59 $repository['svn_specific']['updated'], $repository['repo_id']);
60
61 return t('No new log entries to fetch.');
62 }
63
64 // Defaults to using --xml and the basic svnlog xml output parser.
65 $revisions = $repo->svn('log')
66 ->setParser(new VersioncontrolSvnLogHandler($repo, $last_revision + 1, $latest_rev))
67 ->target('.')->revision($last_revision + 1, $latest_rev)->verbose()
68 ->execute();
69
70 foreach ($revisions as $revision) { // processing the oldest revision first
71 // $actions = svnlib_more_log_info($revision, $repo);
72 $operation = array(
73 'type' => VERSIONCONTROL_OPERATION_COMMIT,
74 'repository' => $repository,
75 'date' => $revision['time_t'],
76 'username' => $revision['author'],
77 'message' => $revision['msg'],
78 'revision' => (string) $revision['rev'],
79 'labels' => array(), // no branch/tag emulation support yet
80 );
81 if (empty($operation['username'])) { // commit inserted by cvs2svn, for example
82 $operation['username'] = '(no author)';
83 $operation['uid'] = 0;
84 }
85
86 $operation_items = array();
87 foreach ($revision['paths'] as $path => $rev_action) {
88 $item = array(
89 'type' => $svnlib_mapping['types'][$rev_action['current_item']['type']],
90 'path' => $rev_action['current_item']['path'],
91 'revision' => (string) $rev_action['current_item']['rev'],
92 'action' => $svnlib_mapping['actions'][$rev_action['action']],
93 'source_items' => array(),
94 );
95 if (isset($rev_action['source_item'])) {
96 $item['source_items'][] = array(
97 'type' => $svnlib_mapping['types'][$rev_action['source_item']['type']],
98 'path' => $rev_action['source_item']['path'],
99 'revision' => (string) $rev_action['source_item']['rev'],
100 );
101 }
102 if (isset($rev_action['replaced_item'])) {
103 $item['replaced_item'] = array(
104 'type' => $svnlib_mapping['types'][$rev_action['replaced_item']['type']],
105 'path' => $rev_action['replaced_item']['path'],
106 'revision' => (string) $rev_action['replaced_item']['rev'],
107 );
108 }
109 $operation_items[$item['path']] = $item;
110 }
111
112 // Now that was easy, wasn't it? :P
113 $operation = versioncontrol_insert_operation($operation, $operation_items);
114 if (isset($operation) && $revision['rev'] > $last_revision) {
115 $last_revision = $revision['rev'];
116 }
117 }
118
119 if ($last_revision > $repository['svn_specific']['last_revision']) {
120 $repository['svn_specific']['last_revision'] = $last_revision;
121 $repository['svn_specific']['updated'] = time();
122
123 // Everything's done, remember the last revision that was captured.
124 db_query('UPDATE {versioncontrol_svn_repositories}
125 SET last_revision = %d, updated = %d WHERE repo_id = %d',
126 $repository['svn_specific']['last_revision'],
127 $repository['svn_specific']['updated'], $repository['repo_id']);
128 }
129 return t('Fetched !count new log entries.', array('!count' => count($revisions)));
130 }

  ViewVC Help
Powered by ViewVC 1.1.2