Project

General

Profile

Actions

Defect #29601

closed

Redmine::VERSION::revision may return wrong value

Defect #29601: Redmine::VERSION::revision may return wrong value

Added by Yuichi HARADA about 8 years ago. Updated about 7 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Administration
Target version:
Resolution:
Fixed
Affected version:

Description

Currently, Redmine::VERSION::revision return 'Revision'.

$ ruby bin/about

Environment:
  Redmine version                3.4.3.stable.17480
  Ruby version                   2.2.5-p319 (2016-04-26) [x86_64-darwin17]
  Rails version                  4.2.8
  Environment                    production
  Database adapter               SQLite
SCM:
  Subversion                     1.9.7
  Git                            2.15.2
  Filesystem
Redmine plugins:
  no plugin installed

But, Revision of checkout URL is 'Last Changed Rev'.
$ svn info --xml

<?xml version="1.0" encoding="UTF-8"?>
<info>
<entry
   path="." 
   revision="17480" 
   kind="dir">               <!-- Currently shown Redmine::VERSION::revision (17480) -->
<url>https://svn.redmine.org/redmine/tags/3.4.3</url>
<relative-url>^/tags/3.4.3</relative-url>
<repository>
<root>https://svn.redmine.org/redmine</root>
<uuid>e93f8b46-1217-0410-a6f0-8f06a7374b81</uuid>
</repository>
<wc-info>
<wcroot-abspath>/path/to/redmine</wcroot-abspath>
<schedule>normal</schedule>
<depth>infinity</depth>
</wc-info>
<commit
   revision="17010">         <!-- Revision of checkout URL (17010) -->
<author>jplang</author>
<date>2017-10-15T19:54:11.195354Z</date>
</commit>
</entry>
</info>

I would like to change it as follows.
Index: lib/redmine/version.rb
===================================================================
diff --git a/trunk/lib/redmine/version.rb b/trunk/lib/redmine/version.rb
--- a/trunk/lib/redmine/version.rb    (revision 17480)
+++ b/trunk/lib/redmine/version.rb    (working copy)
@@ -18,7 +18,7 @@
       if File.directory?(File.join(Rails.root, '.svn'))
         begin
           path = Redmine::Scm::Adapters::AbstractAdapter.shell_quote(Rails.root.to_s)
-          if `#{Redmine::Scm::Adapters::SubversionAdapter.client_command} info --xml #{path}` =~ /revision="(\d+)"/
+          if `#{Redmine::Scm::Adapters::SubversionAdapter.client_command} info --xml #{path}` =~ /commit\s+revision="(\d+)"/
             return $1.to_i
           end
         rescue


Files

Updated by Go MAEDA about 8 years ago Actions #2

  • Category set to Administration

Updated by Go MAEDA about 7 years ago Actions #3

I have confirmed the issue.


Now the current directory is the working copy of /branches/4.0-stable branch.

laphroaig:4.0-stable maeda$ svn info
Path: .
Working Copy Root Path: /Users/maeda/redmines/4.0-stable
URL: https://svn.redmine.org/redmine/branches/4.0-stable
Relative URL: ^/branches/4.0-stable
Repository Root: https://svn.redmine.org/redmine
Repository UUID: e93f8b46-1217-0410-a6f0-8f06a7374b81
Revision: 18593
Node Kind: directory
Schedule: normal
Last Changed Author: maeda
Last Changed Rev: 18591
Last Changed Date: 2019-10-04 08:30:08 +0900 (Fri, 04 Oct 2019)

The latest change is r18591.

laphroaig:4.0-stable maeda$ svn log | head
------------------------------------------------------------------------
r18591 | maeda | 2019-10-04 08:30:08 +0900 (Fri, 04 Oct 2019) | 2 lines

Merged r18589 from trunk to 4.0-stable (#32110).

------------------------------------------------------------------------
r18590 | maeda | 2019-10-04 08:28:00 +0900 (Fri, 04 Oct 2019) | 2 lines

Merged r18588 from trunk to 4.0-stable (#32189).

But the admin/info page says the revision is r18593.

After applying the patch, admin/info page reports the correct revision number r18591.

Updated by Go MAEDA about 7 years ago Actions #4

  • Subject changed from When using 'svn checkout' to acquire Redmine, Redmine::VERSION::revision should be 'Last Changed Rev' to Redmine::VERSION::revision may return wrong value

Updated by Go MAEDA about 7 years ago Actions #5

We don't have to parse XML with regexp if we use `svn info --show-item last-changed-revision`. The command simply returns the number of last changed revision without any other unnecessary data.

$ svn info
Path: .
Working Copy Root Path: /Users/maeda/redmines/4.0-stable
URL: https://svn.redmine.org/redmine/branches/4.0-stable
Relative URL: ^/branches/4.0-stable
Repository Root: https://svn.redmine.org/redmine
Repository UUID: e93f8b46-1217-0410-a6f0-8f06a7374b81
Revision: 18593
Node Kind: directory
Schedule: normal
Last Changed Author: maeda
Last Changed Rev: 18591
Last Changed Date: 2019-10-04 08:30:08 +0900 (Fri, 04 Oct 2019)

$ svn info --show-item last-changed-revision
18591
diff --git a/lib/redmine/version.rb b/lib/redmine/version.rb
index 03eeadef9..40122ebd6 100644
--- a/lib/redmine/version.rb
+++ b/lib/redmine/version.rb
@@ -20,9 +20,7 @@ module Redmine
       if File.directory?(File.join(Rails.root, '.svn'))
         begin
           path = Redmine::Scm::Adapters::AbstractAdapter.shell_quote(Rails.root.to_s)
-          if `#{Redmine::Scm::Adapters::SubversionAdapter.client_command} info --xml #{path}` =~ /revision="(\d+)"/
-            return $1.to_i
-          end
+          return Integer(`#{Redmine::Scm::Adapters::SubversionAdapter.client_command} info --show-item last-changed-revision #{path}`)
         rescue
           # Could not find the current revision
         end

Updated by Mischa The Evil about 7 years ago Actions #6

Go MAEDA wrote:

We don't have to parse XML with regexp if we use `svn info --show-item last-changed-revision`.

That's nice indeed. The issue however could be that by utilizing svn info --show item ... we effectively drop support for Subversion <1.9 because that command is introduced only as part of the 1.9 branch (see the "Subversion Mailinglist thread":http://mail-archives.ap%3e).

Given the circumstances, I don't think that this change in approach of getting the revision number with the corresponding performance increase is worth the raise of compatibility requirements for the Subversion binary.

Updated by Go MAEDA about 7 years ago Actions #7

Mischa The Evil wrote:

The issue however could be that by utilizing svn info --show item ... we effectively drop support for Subversion <1.9 because that command is introduced only as part of the 1.9 branch (see the "Subversion Mailinglist thread":http://mail-archives.ap%3e).

Thanks, I didn't know that the option is only available in Subversion 1.9. The patch I posted should not be applied.

Updated by Go MAEDA about 7 years ago Actions #8

  • Status changed from Confirmed to Closed
  • Assignee set to Go MAEDA
  • Target version changed from 4.2.0 to 4.1.0
  • Resolution set to Fixed

Committed the patch. Thank you for your contribution.

Updated by Mischa The Evil about 7 years ago Actions #9

Go MAEDA wrote:

Mischa The Evil wrote:

The issue however could be that by utilizing svn info --show item ... we effectively drop support for Subversion <1.9 because that command is introduced only as part of the 1.9 branch (see the "Subversion Mailinglist thread":http://mail-archives.ap%3e).

Thanks, I didn't know that the option is only available in Subversion 1.9.

FWIW and FTR: what I meant to say is that the svn info --show item ... command is only available in Subversion 1.9 and up, not that it is 1.9 only.

Actions

Also available in: PDF Atom