Edgewall Software
Modify

Opened 6 years ago

Closed 6 years ago

#13077 closed defect (fixed)

Error "No such node" for HG diff

Reported by: anonymous Owned by: Jun Omae
Priority: normal Milestone: plugin - mercurial
Component: plugin/mercurial Version:
Severity: normal Keywords:
Cc: Branch:
Release Notes:

Fix NoSuchNode raised when paths of MercurialRepository.get_changes() are different.

API Changes:
Internal Changes:

Description

But I did not request prefs.py, so why does it show this error?

Attachments (0)

Change History (6)

comment:1 by Jun Omae, 6 years ago

You should use same path to both From: input and To: input in diff page.

Anyway, I think we could make MercurialRepository.get_changes() robust, or require same path for old_path and new_path parameters like GitRepository.get_changes().

>>> from trac.env import open_environment
>>> from trac.versioncontrol.api import RepositoryManager
>>> env = open_environment('/home/jun66j5/var/trac/1.0-sqlite')
>>> rm = RepositoryManager(env)
>>> repos = rm.get_repository('jomae.hg')
>>> for d in repos.get_changes(new_path='tracopt/notification/subscriber', new_rev='9077964163dfb21950aceb127dd8585524e6ff16', old_path='tracopt/notification', old_rev='57272e5f3505770022d7b33f7f103918b5ea0470'): d
...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/jun66j5/src/mercurial-plugin/tracext/hg/backend.py", line 889, in get_changes
    changes.append((str_path, old_node.subnode(str_np), None,
  File "/home/jun66j5/src/mercurial-plugin/tracext/hg/backend.py", line 1104, in subnode
    self.changectx, self.manifest, subctx, str_path)
  File "/home/jun66j5/src/mercurial-plugin/tracext/hg/backend.py", line 956, in __init__
    raise NoSuchNode(path, changectx.hex())
trac.versioncontrol.api.NoSuchNode: No node tracopt/notification/subscriber/prefs.py at revision 57272e5f3505770022d7b33f7f103918b5ea0470

in reply to:  1 comment:2 by anonymous, 6 years ago

You should use same path to both From: input and To: input in diff page.

Using different paths is a hugely useful feature:

git checkout -b feature13077
mkdir f && cd f
vim a.py
vim b.py
vim c.py
git add a.py
git add b.py
git add c.py
git commit -m "New feature #13077"
git push

echo Trac comment:1 Me: "New feature in log:repo.git@feature13077"
echo Trac comment:2 You reply: "Please rename folder `f` to `foo`.

echo 1 year and many commits later:

git fetch origin
git rebase origin/master
git branch -m feature13077 feature13077_v2
git mv f foo
vim a.py 
vim b.py 
vim c.py 
git add a.py
git add b.py
git add c.py
git commit --amend
git push

echo Trac comment:3 Me: "Rebased in log:repo@feature13077_v2. Renamed folder as requested.
Please review further changes: /diff?old_rev=feature13077&old_path=/repo.git/f/&new_rev=feature13077_v2&new_path=/repo.git/foo/

This works well in some cases and is very useful.

comment:3 by anonymous, 6 years ago

Thank you for the example with get MercurialRepository.get_changes(). It was easy to locate and fix the bug:

  • tracext/hg/backend.py

    diff -r d54f77082b03 -r c837819ca8e8 tracext/hg/backend.py
    a b  
    886886                # 'deleted' if not present in new manifest
    887887                str_np = str_new_path + str_path[len(str_old_path):]
    888888                if str_np not in new_node.manifest:
    889                     changes.append((str_path, old_node.subnode(str_np), None,
     889                    changes.append((str_path, old_node.subnode(str_path), None,
    890890                                    Node.FILE, Changeset.DELETE))
    891891            # Note: `str_path` only used as a key, no need to convert to_u
    892892            for change in sorted(changes, key=lambda c: c[0]):

comment:4 by anonymous, 6 years ago

Regression test:

  • tracext/hg/tests/backend.py

    diff -r fedb9d2141eb -r c9f2efa16762 tracext/hg/tests/backend.py
    a b  
    444444        self.assertTrue(browser_mod.match_request(req))
    445445        browser_mod.process_request(req)
    446446
     447    def test_diff(self):
     448        # regression test for #13077
     449        self._hg_init(data=False)
     450        self._add_repository()
     451        repos = self._repomgr.get_repository('hgrepos')
     452        self._create_commit('lunch', 'lunch/menu.txt')
     453        self._create_commit('pasta', 'lunch/lasagna/pasta.txt')
     454        self._create_commit('coke', 'lunch/lasagna/drink.txt', content='coke')
     455        self._hg_update('0')
     456        self._create_commit('fish', 'lunch/fish/chips.txt')
     457        self._create_commit('coffee', 'lunch/fish/drink.txt', content='coffee')
     458        repos.repo.invalidate()
     459
     460        diffs = list(repos.get_changes(new_path='lunch/fish/', new_rev='4', old_path='lunch/lasagna/', old_rev='2'))
     461        self.assertEqual(3, len(diffs))
     462
     463        add = diffs[0]
     464        self.assertEqual('add', add[3])
     465        self.assertEqual('lunch/fish/chips.txt', add[1].path)
     466
     467        edit = diffs[1]
     468        self.assertEqual('edit', edit[3])
     469        self.assertEqual('lunch/lasagna/drink.txt', edit[0].path)
     470        self.assertEqual('lunch/fish/drink.txt', edit[1].path)
     471
     472        delete =  diffs[2]
     473        self.assertEqual('delete', delete[3])
     474        self.assertEqual('lunch/lasagna/pasta.txt', delete[0].path)
     475
    447476
    448477def test_suite():
    449478    suite = unittest.TestSuite()

comment:5 by Jun Omae, 6 years ago

Owner: set to Jun Omae
Status: newassigned

Tested with all versions of Trac and Mercurial. The changes work well.

[tox]
envlist = py27-trac{10,12,13}-hg{26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,}

[testenv]
deps =
    trac10: Trac>=1.0,<1.1
    trac12: Trac>=1.2,<1.3
    trac13: https://download.edgewall.org/trac/Trac-1.3.3.tar.gz
    hg26: Mercurial>=2.6,<2.7
    hg27: Mercurial>=2.7,<2.8
    hg28: Mercurial>=2.8,<2.9
    hg29: Mercurial>=2.9,<3.0
    hg30: Mercurial>=3.0,<3.1
    hg31: Mercurial>=3.1,<3.2
    hg32: Mercurial>=3.2,<3.3
    hg33: Mercurial>=3.3,<3.4
    hg34: Mercurial>=3.4,<3.5
    hg35: Mercurial>=3.5,<3.6
    hg36: Mercurial>=3.6,<3.7
    hg37: Mercurial>=3.7,<3.8
    hg38: Mercurial>=3.8,<3.9
    hg39: Mercurial>=3.9,<4.0
    hg40: Mercurial>=4.0,<4.1
    hg41: Mercurial>=4.1,<4.2
    hg42: Mercurial>=4.2,<4.3
    hg43: Mercurial>=4.3,<4.4
    hg44: Mercurial>=4.4,<4.5
    hg45: Mercurial>=4.5,<4.6
    hg46: Mercurial>=4.6,<4.7
    hg47: Mercurial>=4.7,<4.8
    hg: Mercurial

comment:6 by Jun Omae, 6 years ago

Release Notes: modified (diff)
Resolution: fixed
Status: assignedclosed

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Jun Omae.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Jun Omae to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.