<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -20,6 +20,6 @@ class SysApi &lt; ActionWebService::API::Base
              :expects =&gt; [],
              :returns =&gt; [[Project]]
   api_method :repository_created,
-             :expects =&gt; [:int, :string],
+             :expects =&gt; [:string, :string],
              :returns =&gt; [:int]
 end</diff>
      <filename>app/apis/sys_api.rb</filename>
    </modified>
    <modified>
      <diff>@@ -22,18 +22,21 @@ class SysController &lt; ActionController::Base
   
   before_invocation :check_enabled
   
+  # Returns the projects list, with their repositories
   def projects
     Project.find(:all, :include =&gt; :repository)
   end
 
-  def repository_created(project_id, url)
-    project = Project.find_by_id(project_id)
+  # Registers a repository for the given project identifier
+  # (Subversion specific)
+  def repository_created(identifier, url)
+    project = Project.find_by_identifier(identifier)
+    # Do not create the repository if the project has already one
     return 0 unless project &amp;&amp; project.repository.nil?
-    logger.debug &quot;Repository for #{project.name} created&quot;
-    repository = Repository.new(:project =&gt; project, :url =&gt; url)
-    repository.root_url = url
+    logger.debug &quot;Repository for #{project.name} was created&quot;
+    repository = Repository.factory('Subversion', :project =&gt; project, :url =&gt; url)
     repository.save
-    repository.id
+    repository.id || 0
   end
 
 protected</diff>
      <filename>app/controllers/sys_controller.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2,7 +2,7 @@
 
 # == Synopsis
 #
-# reposman: manages your svn repositories with redMine
+# reposman: manages your svn repositories with Redmine
 #
 # == Usage
 #
@@ -16,14 +16,28 @@
 #    use DIR as base directory for svn repositories
 #
 # -r, --redmine-host=HOST
-#    assume redMine is hosted on HOST.
+#    assume Redmine is hosted on HOST.
 #    you can use :
 #    * -r redmine.mydomain.foo        (will add http://)
 #    * -r http://redmine.mydomain.foo
 #    * -r https://mydomain.foo/redmine
 #
 # == Options
-# 
+#
+# -o, --owner=OWNER
+#    owner of the repository. using the rails login allow user to browse
+#    the repository in Redmine even for private project
+#
+# -u, --url=URL
+#    the base url Redmine will use to access your repositories. This
+#    will be used to register the repository in Redmine so that user
+#    doesn't need to do anything. reposman will add the identifier to this url :
+#
+#    -u https://my.svn.server/my/reposity/root # if the repository can be access by http
+#    -u file:///var/svn/                       # if the repository is local
+#    if this option isn't set, reposman won't register the repository
+#
+#
 # -h, --help:
 #    show help and exit
 #
@@ -48,6 +62,8 @@ Version = &quot;1.0&quot;
 opts = GetoptLong.new(
                       ['--svn-dir',      '-s', GetoptLong::REQUIRED_ARGUMENT],
                       ['--redmine-host', '-r', GetoptLong::REQUIRED_ARGUMENT],
+                      ['--owner',        '-o', GetoptLong::REQUIRED_ARGUMENT],
+                      ['--url',          '-u', GetoptLong::REQUIRED_ARGUMENT],
                       ['--verbose',      '-v', GetoptLong::NO_ARGUMENT],
                       ['--version',      '-V', GetoptLong::NO_ARGUMENT],
                       ['--help'   ,      '-h', GetoptLong::NO_ARGUMENT],
@@ -58,6 +74,8 @@ $verbose      = 0
 $quiet        = false
 $redmine_host = ''
 $repos_base   = ''
+$svn_owner    = 'root'
+$svn_url      = false
 
 def log(text,level=0, exit=false)
   return if $quiet or level &gt; $verbose
@@ -68,8 +86,10 @@ end
 begin
   opts.each do |opt, arg|
     case opt
-    when '--svn-dir';        $repos_base = arg.dup
+    when '--svn-dir';        $repos_base   = arg.dup
     when '--redmine-host';   $redmine_host = arg.dup
+    when '--owner';          $svn_owner    = arg.dup
+    when '--url';            $svn_url      = arg.dup
     when '--verbose';        $verbose += 1
     when '--version';        puts Version; exit
     when '--help';           RDoc::usage
@@ -80,6 +100,8 @@ rescue
   exit 1
 end
 
+$svn_url += &quot;/&quot; if $svn_url and not $svn_url.match(/\/$/)
+
 if ($redmine_host.empty? or $repos_base.empty?)
   RDoc::usage
 end
@@ -88,7 +110,7 @@ unless File.directory?($repos_base)
   log(&quot;directory '#{$repos_base}' doesn't exists&quot;, 0, true)
 end
 
-log(&quot;querying redMine for projects...&quot;, 1);
+log(&quot;querying Redmine for projects...&quot;, 1);
 
 $redmine_host.gsub!(/^/, &quot;http://&quot;) unless $redmine_host.match(&quot;^https?://&quot;)
 $redmine_host.gsub!(/\/$/, '')
@@ -109,28 +131,53 @@ end
 
 log(&quot;retrieved #{projects.size} projects&quot;, 1)
 
-projects.each do |p|
-  log(&quot;treating project #{p.name}&quot;, 1)
+def set_owner_and_rights(project, repos_path, &amp;block)
+  if RUBY_PLATFORM =~ /mswin/
+    yield if block_given?
+  else
+    uid, gid = Etc.getpwnam($svn_owner).uid, Etc.getgrnam(project.identifier).gid
+    right = project.is_public ? 0575 : 0570
+    yield if block_given?
+    Find.find(repos_path) do |f|
+      File.chmod right, f
+      File.chown uid, gid, f
+    end
+  end
+end
+
+def other_read_right?(file)
+  (File.stat(file).mode &amp; 0007).zero? ? false : true
+end
+
+def owner_name(file)
+  RUBY_PLATFORM =~ /mswin/ ?
+    $svn_owner :
+    Etc.getpwuid( File.stat(file).uid ).name  
+end
 
-  if p.identifier.empty?
-    log(&quot;\tno identifier for project #{p.name}&quot;)
+projects.each do |project|
+  log(&quot;treating project #{project.name}&quot;, 1)
+
+  if project.identifier.empty?
+    log(&quot;\tno identifier for project #{project.name}&quot;)
     next
-  elsif not p.identifier.match(/^[a-z0-9\-]+$/)
-    log(&quot;\tinvalid identifier for project #{p.name} : #{p.identifier}&quot;);
+  elsif not project.identifier.match(/^[a-z0-9\-]+$/)
+    log(&quot;\tinvalid identifier for project #{project.name} : #{project.identifier}&quot;);
     next;
   end
 
-  repos_path = $repos_base + &quot;/&quot; + p.identifier
+  repos_path = $repos_base + &quot;/&quot; + project.identifier
 
   if File.directory?(repos_path)
 
-    other_read = (File.stat(repos_path).mode &amp; 0007).zero? ? false : true
-    next if p.is_public == other_read
-
-    right = p.is_public ? 0775 : 0770
+    # we must verify that repository has the good owner and the good
+    # rights before leaving
+    other_read = other_read_right?(repos_path)
+    owner      = owner_name(repos_path)
+    next if project.is_public == other_read and owner == $svn_owner
 
     begin
-      Find.find(repos_path) { |f| File.chmod right, f }
+      set_owner_and_rights(project, repos_path)
     rescue Errno::EPERM =&gt; e
       log(&quot;\tunable to change mode on #{repos_path} : #{e}\n&quot;)
       next
@@ -139,17 +186,26 @@ projects.each do |p|
     log(&quot;\tmode change on #{repos_path}&quot;);
 
   else
-    p.is_public ? File.umask(0002) : File.umask(0007)
+    project.is_public ? File.umask(0202) : File.umask(0207)
 
     begin
-      uid, gid = Etc.getpwnam(&quot;root&quot;).uid, Etc.getgrnam(p.identifier).gid
-      raise &quot;svnadmin create #{repos_path} failed&quot; unless system(&quot;svnadmin&quot;, &quot;create&quot;, repos_path)
-      Find.find(repos_path) { |f| File.chown uid, gid, f }
+      set_owner_and_rights(project, repos_path) do
+        raise &quot;svnadmin create #{repos_path} failed&quot; unless system(&quot;svnadmin&quot;, &quot;create&quot;, repos_path)
+      end
     rescue =&gt; e
       log(&quot;\tunable to create #{repos_path} : #{e}\n&quot;)
       next
     end
 
+    if $svn_url
+      ret = soap.RepositoryCreated project.identifier, &quot;#{$svn_url}#{project.identifier}&quot;
+      if ret &gt; 0
+        log(&quot;\trepository #{repos_path} registered in Redmine with url #{$svn_url}#{project.identifier}&quot;);
+      else
+        log(&quot;\trepository #{repos_path} not registered in Redmine. Look in your log to find why.&quot;);
+      end
+    end
+
     log(&quot;\trepository #{repos_path} created&quot;);
   end
 </diff>
      <filename>extra/svn/reposman.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>0d605006a3eb95e0e62de9ea68c20e24926ae3bb</id>
    </parent>
  </parents>
  <author>
    <name>Jean-Philippe Lang</name>
    <email>jp_lang@yahoo.fr</email>
  </author>
  <url>http://github.com/edavis10/redmine/commit/cedca57620e36fc8deb22653e91ef3e63fe63cf2</url>
  <id>cedca57620e36fc8deb22653e91ef3e63fe63cf2</id>
  <committed-date>2007-10-21T09:26:14-07:00</committed-date>
  <authored-date>2007-10-21T09:26:14-07:00</authored-date>
  <message>SVN integration: reposman.rb can now register created repositories in Redmine, so that the administrator doesn't have to enter the repository url in Redmine once it's created.
To do so, use the --url option when running reposman (see reposman help).

git-svn-id: http://redmine.rubyforge.org/svn/trunk@860 e93f8b46-1217-0410-a6f0-8f06a7374b81</message>
  <tree>6265b15323eab04dc3953778bc6bd86a1bc9ca9b</tree>
  <committer>
    <name>Jean-Philippe Lang</name>
    <email>jp_lang@yahoo.fr</email>
  </committer>
</commit>
