cross-project_revision_and_commit_links_v1.diff

Support for cross-project revision and commit links v1 - Babar O'Cap, 2009-08-18 12:39

Download (4.17 KB)

View differences:

J:\application_helper_new.rb
422 422
    #     #52 -> Link to issue #52
423 423
    #   Changesets:
424 424
    #     r52 -> Link to revision 52
425
    #     r:project:52 -> Link to revision 52 of an other project, using project name or identifier
425 426
    #     commit:a85130f -> Link to scmid starting with a85130f
427
    #     commit:project:a85130f -> Link to scmid starting with a85130f of an other project, using project name or identifier
426 428
    #   Documents:
427 429
    #     document#17 -> Link to document with id 17
428 430
    #     document:Greetings -> Link to the document with title "Greetings"
......
441 446
    #     export:some/file -> Force the download of the file
442 447
    #  Forum messages:
443 448
    #     message#1218 -> Link to message with id 1218
444
    text = text.gsub(%r{([\s\(,\-\>]|^)(!)?(attachment|document|version|commit|source|export|message)?((#|r)(\d+)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|,|\s|<|$)}) do |m|
445
      leading, esc, prefix, sep, oid = $1, $2, $3, $5 || $7, $6 || $8
449
    text = text.gsub(%r{([\s\(,\-\>]|^)(!)?(attachment|document|version|commit|source|export|message)?((#|r)(:[^\:]+:)?(\d+)|(:)([^\:]+:)?([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|,|\s|<|$)}) do |m|
450
      leading, esc, prefix, sep, revproj, oid = $1, $2, $3, $8 || $5, $9 || $6, $10 || $7
446 451
      link = nil
447 452
      if esc.nil?
448 453
        if prefix.nil? && sep == 'r'
454
          if revproj.nil?
449 455
          if project && (changeset = project.changesets.find_by_revision(oid))
450 456
            link = link_to("r#{oid}", {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => oid},
451 457
                                      :class => 'changeset',
452 458
                                      :title => truncate_single_line(changeset.comments, :length => 100))
453 459
          end
460
          else
461
            revproj.gsub!(/[\:"]/,'')
462
            link_project = Project.find_by_name(h(revproj)) || Project.find_by_identifier(h(revproj))
463
            if link_project && (changeset = link_project.changesets.find_by_revision(oid))
464
              link = link_to h("#{revproj}:r#{oid}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => link_project, :rev => oid},
465
                :class => 'changeset',
466
                :title => truncate_single_line(changeset.comments, :length => 100)
467
            end            
468
          end
454 469
        elsif sep == '#'
455 470
          oid = oid.to_i
456 471
          case prefix
......
497 512
                                              :class => 'version'
498 513
            end
499 514
          when 'commit'
515
            if revproj.nil?
500 516
            if project && (changeset = project.changesets.find(:first, :conditions => ["scmid LIKE ?", "#{name}%"]))
501 517
              link = link_to h("#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.revision},
502 518
                                           :class => 'changeset',
503 519
                                           :title => truncate_single_line(changeset.comments, :length => 100)
504 520
            end
521
            else
522
              revproj.gsub!(/[\:"]/,'')
523
              link_project = Project.find_by_name(h(revproj)) || Project.find_by_identifier(h(revproj))
524
              if link_project && (changeset = link_project.changesets.find(:first, :conditions => ["scmid LIKE ?", "#{name}%"]))
525
                link = link_to h("#{revproj}:#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => link_project, :rev => changeset.revision},
526
                  :class => 'changeset',
527
                  :title => truncate_single_line(changeset.comments, :length => 100)
528
              end
529
            end
505 530
          when 'source', 'export'
506 531
            if project && project.repository
507 532
              name =~ %r{^[/\\]*(.*?)(@([0-9a-f]+))?(#(L\d+))?$}