This repository has been archived by the owner on Jul 24, 2020. It is now read-only.
Fix for issue #213 [hg outgoing fails on empty repository] #221
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
"In some situations where a reference is being used but does not exist in _map_git or _map_hg, silently skip the reference rather than throwing an error. This allows hg outgoing to work on repositories which do not contain any revisions at all."
This patch is very short, but I am not sure I went about implementing the fix the right way so I am going to overexplain what I did.
I was trying to address #213
I did some testing on 2 repos exhibiting this problem but which gave different error messages. I used mercurial 1.8.4, dulwich [newest] and top of tree hg-git.
The first one I tried was git+ssh://git@github.com:mcclure/hg-git.git
(I made a fork of the hg-git repository, but it contained no commits yet).
This one got the "TypeError: a2b_hex() argument 1 must be string or read-only buffer, not None" error. (See the pastie on issue 213).
The problem turned out to be occurring because map_hg_get in git_handler.py was returning None for a particular value in old_refs when called in get_refs on this line:
This happened because one of the keys in old_refs:
'.have': '0c865452c0a6cfd26e4b61ff5d49136665530caf
Did not exist in _map_git (and in fact didn't exist in "mapfile").
The second error saw the "TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'" symptom. In this case the repo was git+ssh://git@github.com:mcclure/empty.git
(This is a repository I made on github and have never committed to)
In this case, the failure was occurring in update_references in git_handler.py, on the line
In this case, "key" was equal to "MASTER", heads[key] was equal to 0000000000000000000000000000000000000000, and self.map_git_get(heads[key]) was equal to None. map_git_get did this because _map_hg was actually empty. This meant None was being passed in to the self.git.refs setitem, causing a crash.
My fix in both cases was to check for "None" and, if None, ignore that particular commit rather than attempting to do the operation which threw the error (bin() or refs[]=). After making this change, both repositories would perform correctly (printing "no changes" or the appropriate change list as... appropriate).
My questions: