Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paths != Tree Keys When Paths Are Windows Paths #5

Closed
cbilson opened this issue Jan 11, 2010 · 5 comments
Closed

Paths != Tree Keys When Paths Are Windows Paths #5

cbilson opened this issue Jan 11, 2010 · 5 comments

Comments

@cbilson
Copy link

cbilson commented Jan 11, 2010

Hi,

I am using dulwich with hg-git on windows and have run into a problem committing:

(2) C:\s\p\Powershell2 -» hg push git://github.com/cbilson/Powershell2.git
pushing to git://github.com/cbilson/Powershell2.git
importing Hg objects into Git
at: 0/3
Path:
Path: Automating_Your_.NET_Application
Path: Automating_Your_.NET_Application\TipCalculator
** unknown exception encountered, details follow
** report bug details to http://mercurial.selenic.com/bts/
** or mercurial@selenic.com
** Mercurial Distributed SCM (version 1.4.1)
** Extensions loaded: bookmarks, extdiff, fetch, graphlog, mq, purge, record, rebase, activity, hgshelve, histedit, svn, hggit
Traceback (most recent call last):
  File "C:\Python26\Scripts\hg", line 5, in 
    pkg_resources.run_script('mercurial==1.4.1', 'hg')
  File "C:\Python26\lib\site-packages\pkg_resources.py", line 489, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "C:\Python26\lib\site-packages\pkg_resources.py", line 1207, in run_script
    execfile(script_filename, namespace, namespace)
  File "c:\python26\lib\site-packages\mercurial-1.4.1-py2.6-win32.egg\EGG-INFO\scripts\hg", line 27, in 
    mercurial.dispatch.run()
  File "C:\Python26\lib\site-packages\mercurial-1.4.1-py2.6-win32.egg\mercurial\dispatch.py", line 16, in run
    sys.exit(dispatch(sys.argv[1:]))
  File "C:\Python26\lib\site-packages\mercurial-1.4.1-py2.6-win32.egg\mercurial\dispatch.py", line 30, in dispatch
    return _runcatch(u, args)
  File "C:\Python26\lib\site-packages\mercurial-1.4.1-py2.6-win32.egg\mercurial\dispatch.py", line 46, in _runcatch
    return _dispatch(ui, args)
  File "C:\Python26\lib\site-packages\mercurial-1.4.1-py2.6-win32.egg\mercurial\dispatch.py", line 449, in _dispatch
    return runcommand(lui, repo, cmd, fullargs, ui, options, d)
  File "C:\Python26\lib\site-packages\mercurial-1.4.1-py2.6-win32.egg\mercurial\dispatch.py", line 319, in runcommand
    ret = _runcommand(ui, options, cmd, d)
  File "C:\Python26\lib\site-packages\mercurial-1.4.1-py2.6-win32.egg\mercurial\dispatch.py", line 500, in _runcommand
    return checkargs()
  File "C:\Python26\lib\site-packages\mercurial-1.4.1-py2.6-win32.egg\mercurial\dispatch.py", line 454, in checkargs
    return cmdfunc()
  File "C:\Python26\lib\site-packages\mercurial-1.4.1-py2.6-win32.egg\mercurial\dispatch.py", line 448, in 
    d = lambda: util.checksignature(func)(ui, *args, **cmdoptions)
  File "C:\Python26\lib\site-packages\mercurial-1.4.1-py2.6-win32.egg\mercurial\util.py", line 386, in check
    return func(*args, **kwargs)
  File "C:\Python26\lib\site-packages\mercurial-1.4.1-py2.6-win32.egg\mercurial\extensions.py", line 116, in wrap
    util.checksignature(origfn), *args, **kwargs)
  File "C:\Python26\lib\site-packages\mercurial-1.4.1-py2.6-win32.egg\mercurial\util.py", line 386, in check
    return func(*args, **kwargs)
  File "C:\src\ThirdParty\hgsubversion\hgsubversion\wrappers.py", line 419, in generic
    return orig(ui, repo, *args, **opts)
  File "C:\Python26\lib\site-packages\mercurial-1.4.1-py2.6-win32.egg\mercurial\util.py", line 386, in check
    return func(*args, **kwargs)
  File "C:\Python26\lib\site-packages\mercurial-1.4.1-py2.6-win32.egg\mercurial\commands.py", line 2356, in push
    r = repo.push(other, opts.get('force'), revs=revs)
  File "c:\src\ThirdParty\hg-git\hggit\hgrepo.py", line 19, in push
    git.push(remote.path, revs, force)
  File "c:\src\ThirdParty\hg-git\hggit\git_handler.py", line 145, in push
    self.export_commits()
  File "c:\src\ThirdParty\hg-git\hggit\git_handler.py", line 113, in export_commits
    self.export_git_objects()
  File "c:\src\ThirdParty\hg-git\hggit\git_handler.py", line 189, in export_git_objects
    self.export_hg_commit(rev)
  File "c:\src\ThirdParty\hg-git\hggit\git_handler.py", line 238, in export_hg_commit
    tree_sha = commit_tree(self.git.object_store, self.iterblobs(ctx))
  File "C:\Python26\lib\site-packages\dulwich-0.4.1-py2.6-win32.egg\dulwich\index.py", line 301, in commit_tree
    return build_tree("")
  File "C:\Python26\lib\site-packages\dulwich-0.4.1-py2.6-win32.egg\dulwich\index.py", line 295, in build_tree
    sha = build_tree(os.path.join(path, basename))
  File "C:\Python26\lib\site-packages\dulwich-0.4.1-py2.6-win32.egg\dulwich\index.py", line 295, in build_tree
    sha = build_tree(os.path.join(path, basename))
  File "C:\Python26\lib\site-packages\dulwich-0.4.1-py2.6-win32.egg\dulwich\index.py", line 292, in build_tree
    for basename, entry in trees[path].iteritems():
KeyError: 'Automating_Your_.NET_Application\\TipCalculator'

I don't really know python, but was able to get the debugger to run hg-git and let me stop when the error occurred. I noticed that if I replaced the "" with "/" in the path in "trees[path]" it worked:

diff -r 03f98a25f119 dulwich/index.py
--- a/dulwich/index.py  Mon Dec 07 14:51:49 2009 +0100
+++ b/dulwich/index.py  Sun Jan 10 17:14:04 2010 -0800
@@ -288,7 +288,9 @@

     def build_tree(path):
         tree = Tree()
-        for basename, entry in trees[path].iteritems():
+
+        treePath = path.replace("\\", "/")
+        for basename, entry in trees[treePath].iteritems():
             if type(entry) == dict:
                 mode = stat.S_IFDIR
                 sha = build_tree(os.path.join(path, basename))

It worked, but I suspect there will be other problems like this elsewhere? I don't mind trying to find and fix them myself, but would just like to talk with someone about this first. Any thoughts? Thanks!

@jelmer
Copy link
Owner

jelmer commented Jan 13, 2010

Thanks for the patch. Rather than fixing the paths later on, I think we should be making sure that we just generate paths with forward slashes in them everywhere. i.e. rather than using os.path.join, please use "/".join

@cbilson
Copy link
Author

cbilson commented Jan 14, 2010

So am I correct in assuming dulwich needs to be able to accept platform specific paths everywhere and just convert them to "/" paths?

@jelmer
Copy link
Owner

jelmer commented Jan 16, 2010

No, it should accept / paths everywhere only.

The problem here though is that it is not generating / paths by itself, but path-dependent paths.

@jelmer
Copy link
Owner

jelmer commented Feb 27, 2010

This is fixed in trunk now

@ghost
Copy link

ghost commented Mar 4, 2010

I suppose the difference is very small between that and using "/".join(..), but if you want you can import posixpath explicitly, to always use that whatever the platform.

jelmer pushed a commit that referenced this issue Oct 25, 2016
# This is the 1st commit message:
Support linked working directories

Support for linked working directories:
- Add `commondir()` (equivalent to `GIT_COMMON_DIR`)
- Read the `commondir` file, to set it.

See `git-worktree(1)` and `gitrepository-layout(5)`.

# The commit message #2 will be skipped:

#	Fix DiskRefsContainer.refpath()

# The commit message #3 will be skipped:

#	Add a testsuite

# The commit message #4 will be skipped:

#	Add @skipIf for WorkingTreeTestCase

# The commit message #5 will be skipped:

#	worktree is optional and default to path

# The commit message #6 will be skipped:

#	add a TODO

# The commit message #7 will be skipped:

#	Save one syscall
#
#	See https://github.com/jelmer/dulwich/pull/454/files/0927deb7cd2ad24294b89e319ea060ed488acbba#r82424872

# The commit message #8 will be skipped:

#	Read commondir with get_named_file()
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants