1. TortoiseHg
  2. TortoiseHg
  3. thg
  4. Issues
Issue #841 resolved

Error while importing patch from the clipboard

James Jensen
created an issue

I'm new to Mercurial, and was trying to figure out how to apply a set of changes to multiple branches. I right-clicked a change set and chose Export>Copy Patch. Then I used the Repository menu > Import > Import from Clipboard.

Following is what was added to the clipboard:

{{{

HG changeset patch

User James Jensen james@truenorthlogic.com

Date 1309380044 21600

Node ID c52b9021c42a7aed0f3fedb8aec41f6ae667f99f

Parent a438166ecbbac912a5b2475b73d7a08b353b5928

Testing commits not made to the head.

diff -r a438166ecbba -r c52b9021c42a Website/LogTime.aspx.cs --- a/Website/LogTime.aspx.cs Wed Jun 29 12:11:54 2011 -0600 +++ b/Website/LogTime.aspx.cs Wed Jun 29 14:40:44 2011 -0600 @@ -1,15 +1,12 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.Security; using TimesheetBL; using TimesheetDAL; -using TimesheetBL.DisplayObjects;

-public partial class LogTime : System.Web.UI.Page +public partial class LogTime : Page { private UserBO userBO = new UserBO(); private EntityCategoryBo catBO = new EntityCategoryBo();

}}}

However, I noticed that when I pasted this into NotePad, the line with the text "Using System;" is displayed in a really small font. Also, when I move the cursor along that line, it pauses just before the "u" in "using" as if there's an invisible character there.

Here's the error information it gave:

{{{

!python

Mercurial version (1.8.4). TortoiseHg version (2.0.5) Command: log CWD: D:\Work\timesheets Extensions loaded: fixfrozenexts Python version: 2.6.6 (r266:84297, Aug 24 2010, 18:13:38) [MSC v.1500 64 bit (AMD64)] Windows version: (6, 1, 7601, 2, 'Service Pack 1') Processor architecture: x64 Qt-4.7.1 PyQt-4.8.3 Traceback (most recent call last): File "tortoisehg\hgqt\thgimport.pyo", line 195, in getcliptext File "tortoisehg\util\hglib.pyo", line 75, in fromunicode File "encodings\cp1252.pyo", line 12, in encode UnicodeEncodeError: 'charmap' codec can't encode character u'\ufeff' in position 435: character maps to <undefined>

}}}

Comments (11)

  1. James Jensen reporter

    I thought that this issue may have been fixed because I didn't encounter it for a while, but it just happened again on Mercurial version (2.0). TortoiseHg version (2.2), Qt-4.7.1, PyQt-4.8.3

  2. Anonymous

    Getting this error on 2.2.2

    ** Mercurial version (2.0.2).  TortoiseHg version (2.2.2)
    ** Command: 
    ** CWD: C:\Windows\system32
    ** Encoding: cp1252
    ** Extensions loaded: 
    ** Python version: 2.6.6 (r266:84297, Aug 24 2010, 18:13:38) [MSC v.1500 64 bit (AMD64)]
    ** Windows version: (6, 1, 7601, 2, 'Service Pack 1')
    ** Processor architecture: x64
    ** Qt-4.7.4 PyQt-4.8.6
    Traceback (most recent call last):
      File "tortoisehg\hgqt\thgimport.pyo", line 196, in getcliptext
      File "tortoisehg\util\hglib.pyo", line 115, in fromunicode
      File "encodings\cp1252.pyo", line 12, in encode
    UnicodeEncodeError: 'charmap' codec can't encode character u'\ufeff' in position 226: character maps to <undefined>
    
  3. James Alexander

    I'm also getting an error similar to this: (i.e. character maps to <undefined>)

    ** Mercurial version (1.9+10-e9264b45237d).  TortoiseHg version (2.1.1)
    ** Command: --nofork workbench
    ** CWD: D:\HGDev\DiscoverDev
    ** Extensions loaded: kilnauth, kilnpath, kiln, purge, graphlog
    ** Python version: 2.6.6 (r266:84297, Aug 24 2010, 18:13:38) [MSC v.1500 64 bit (AMD64)]
    ** Windows version: (6, 1, 7601, 2, 'Service Pack 1')
    ** Processor architecture: x64
    ** Qt-4.7.1 PyQt-4.8.3
    Traceback (most recent call last):
      File "tortoisehg\hgqt\thgimport.pyo", line 195, in getcliptext
      File "tortoisehg\util\hglib.pyo", line 109, in fromunicode
      File "encodings\cp1252.pyo", line 12, in encode
    UnicodeEncodeError: 'charmap' codec can't encode character u'\ufeff' in position 4650: character maps to <undefined>
    
  4. Yuya Nishihara

    It happens because Visual Studio saves UTF-8 file with BOM.

    In the above example, "LogTime.aspx.cs" is saved with BOM, the patch happens to contain invisible U+FEFF between hunk marker "@@ -1,15 +1,12 @@" and the first line "using System;". Of course, U+FEFF cannot be encoded to cp1252, thus UnicodeEncodeError occurs.

  5. Log in to comment