Ticket #10843 (closed defect: fixed)

Opened 4 months ago

Last modified 3 months ago

Adding bibfile from svn source fails with Trac 1.0 and tracbibplugin-r12578

Reported by: anonymous Assigned to: Amfortas
Priority: normal Component: TracBibPlugin
Severity: blocker Keywords: BibtexSourceSource
Cc: Trac Release: 1.0

Description

On a Trac 1.0 instance I installed the trunk version of tracbibplugin-r12578.zip. Having the following repository setup

[repositories]
project.description = This is the ''main'' project repository.
project.dir = /var/share/svn/myrepo
project.type = svn
project.url = https://myserver/repos/myrepo

a wiki page with the BibAdd macro

[[BibAdd(source:project/trunk/vat.bib)]]

produces the following error (the source path was verified to be accessible with a simple [source:project/trunk/vat.bib]-macro):

2013-01-29 17:32:12,223 Trac[formatter] DEBUG: Executing Wiki macro BibAdd by provider <tracbib.tracbib.BibAddMacro object at 0x7f19eae6dad0>
2013-01-29 17:32:12,227 Trac[formatter] ERROR: Macro BibAdd(source:project/trunk/vat.bib) failed: 
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/trac/wiki/formatter.py", line 765, in _macro_formatter
    return macro.ensure_inline(macro.process(args))
  File "/usr/local/lib/python2.7/dist-packages/trac/wiki/formatter.py", line 356, in process
    text = self.processor(text)
  File "/usr/local/lib/python2.7/dist-packages/trac/wiki/formatter.py", line 343, in _macro_processor
    text)
  File "build/bdist.linux-x86_64/egg/tracbib/tracbib.py", line 198, in expand_macro
    loaded.append(source.source(formatter.req, args[0]))
  File "build/bdist.linux-x86_64/egg/tracbib/source.py", line 91, in source
    bib = repos.get_node(file, revision)
AttributeError: 'NoneType' object has no attribute 'get_node'

Attachments

Change History

(follow-up: ↓ 2 ) 02/05/13 07:44:40 changed by stelminator

yup, I ran into this, too. I think it's do with the default configuration to be for there to not be a default repository. Basically, TracBib is expecting the old style where there's only one repository, and even if there's more than one, for the common use case (and the default configuration in Trac) is for there to be a default repository.

Anyway, looks like TracBib hasn't been updated for multiple repositories (at least not for this use case).

Fix below for

  1. don't hardcode default revision for SVN (I'm using Git). (latest -> None).
    • This may or may not solve #9028, it's not very specific, and I don't have a Mercurial repository set up to test with at the moment.
  2. use the new API method get_repository_by_path on RepositoryManager to just magically do the right thing.
diff --git a/tracbib/source.py b/tracbib/source.py
index 0a75f5d..5a5b574 100644
--- a/tracbib/source.py
+++ b/tracbib/source.py
@@ -28,6 +28,7 @@ This class provides different container implementations of bibtex files.
 """
 from api import IBibSourceProvider
 from trac.core import implements, Component, TracError
+from trac.versioncontrol import RepositoryManager
 
 import bibtexparse
 from helper import def_strings
@@ -79,16 +80,16 @@ class BibtexSourceSource(Component):
         if len(arg) < 2:
             raise TracError('[[Usage: BibAdd(source:file[@rev])')
         elif len(arg) == 2:
-            revision = 'latest'
+            revision = None
         else:
             revision = arg[2]
 
         file = arg[1]
 
-        repos = self.env.get_repository()
+        (reponame, repos, path) = RepositoryManager(self.env).get_repository_by_path(file)
 
         # load the file from the repository
-        bib = repos.get_node(file, revision)
+        bib = repos.get_node(path, revision)
         file = bib.get_content()
         text = file.read()
 

(in reply to: ↑ 1 ; follow-up: ↓ 3 ) 02/06/13 17:30:04 changed by anonymous

Replying to stelminator:

I tried your patch(es) with the environment described in this ticket's description:

  • 1. (don't hardcode default revision for SVN) doesn't fix the behavior
  • 2. (use the new API method) suffices to fix the reported problem
  • 1. + 2. (complete patch from stelminator) also fixes the problem

So I hope your patch is going to be part of the next version of TracBibPlugin.

(in reply to: ↑ 2 ) 02/06/13 19:15:11 changed by stelminator

Replying to anonymous:

Replying to stelminator: I tried your patch(es) with the environment described in this ticket's description: - 1. (don't hardcode default revision for SVN) doesn't fix the behavior - 2. (use the new API method) suffices to fix the reported problem - 1. + 2. (complete patch from stelminator) also fixes the problem So I hope your patch is going to be part of the next version of TracBibPlugin.

My description of 1. was incomplete. 'latest' and None are functionally equivalent for SVN, but not for other version control systems, where None is correct. I wouldn't expect it to have any effect for someone using SVN. The rest of the patch compensates for multiple repositories, including the related API changes for Trac 1.0.

Glad to hear that it worked for someone else.

02/09/13 22:16:10 changed by Amfortas

  • status changed from new to closed.
  • resolution set to fixed.

Thank you for your reports! Fixed in r12604.

Tested with git, svn and hg on Trac 1.0 and 0.12.

Roman


Add/Change #10843 (Adding bibfile from svn source fails with Trac 1.0 and tracbibplugin-r12578)




Change Properties
Action