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

Crash during push to Hg repo #50

Closed
itronics opened this issue Oct 31, 2013 · 2 comments
Closed

Crash during push to Hg repo #50

itronics opened this issue Oct 31, 2013 · 2 comments

Comments

@itronics
Copy link

git-remote-hg sometimes crashes on pushing local commits to Hg repo with error:

Traceback (most recent call last):
  File "/usr/local/bin/git-remote-hg", line 1234, in <module>
    sys.exit(main(sys.argv))
  File "/usr/local/bin/git-remote-hg", line 1218, in main
    do_export(parser)
  File "/usr/local/bin/git-remote-hg", line 1021, in do_export
    parse_commit(parser)
  File "/usr/local/bin/git-remote-hg", line 731, in parse_commit
    f = { 'mode' : hgmode(m), 'data' : blob_marks[mark] }
KeyError: 13617

If you will try again after the crash, git answers with 'Everything up-to-day' message. The crash is replicable, but seems to depend both on commit as well as repo content. Moreover, when after the crash you will delete mark related to the failed commit in marks-git file, next push ends successfully.

Steps to reproduce (using clone of our SF net repository):

#!/bin/bash
mkdir ./t
cd ./t
hg clone http://hg.code.sf.net/p/frontaccounting/mercurial h
hg update unstable
git clone hg::h -b branches/unstable g
cd g
echo '--- a/purchasing/includes/purchasing_db.inc
+++ b/purchasing/includes/purchasing_db.inc
@@ -9,6 +9,8 @@
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
 ***********************************************************************/
+include_once($path_to_root . "/purchasing/includes/supp_trans_class.inc");
+
 include_once($path_to_root . "/includes/banking.inc");

 include_once($path_to_root . "/includes/date_functions.inc");

' | patch -p1
git commit -a -m "test"
git push

Tested on git 1.7.9.5 and 1.7.10.4.

@felipec
Copy link
Owner

felipec commented Oct 31, 2013

That is due to another bug in Git that is already fixed in the latest version.

And you are right, if you push again the issue should be gone.

You can try the old code this way:

diff --git a/git-remote-hg.py b/git-remote-hg.py
index cf149f3..cce3172 100755
--- a/git-remote-hg.py
+++ b/git-remote-hg.py
@@ -264,27 +264,12 @@ def fix_file_path(path):
         return path
     return os.path.relpath(path, '/')

-def export_files(files):
-    final = []
-    for f in files:
-        fid = node.hex(f.filenode())
-
-        if fid in filenodes:
-            mark = filenodes[fid]
-        else:
-            mark = marks.next_mark()
-            filenodes[fid] = mark
-            d = f.data()
-
-            print "blob"
-            print "mark :%u" % mark
-            print "data %d" % len(d)
-            print d
-
-        path = fix_file_path(f.path())
-        final.append((gitmode(f.flags()), mark, path))
-
-    return final
+def export_file(fc):
+    d = fc.data()
+    path = fix_file_path(fc.path())
+    print "M %s inline %s" % (gitmode(fc.flags()), path)
+    print "data %d" % len(d)
+    print d

 def get_filechanges(repo, ctx, parent):
     modified = set()
@@ -505,8 +490,6 @@ def export_ref(repo, name, kind, head):
         if len(parents) == 0 and rev:
             print 'reset %s/%s' % (prefix, ename)

-        modified_final = export_files(c.filectx(f) for f in modified)
-
         print "commit %s/%s" % (prefix, ename)
         print "mark :%d" % (marks.get_mark(c.hex()))
         print "author %s" % (author)
@@ -521,8 +504,8 @@ def export_ref(repo, name, kind, head):

         for f in removed:
             print "D %s" % (fix_file_path(f))
-        for f in modified_final:
-            print "M %s :%u %s" % f
+        for f in modified:
+            export_file(c.filectx(f))
         print

         progress = (rev - tip)
@@ -1157,7 +1140,6 @@ def main(args):
     global peer, mode, bad_mail, bad_name
     global track_branches, force_push, is_tmp
     global parsed_tags
-    global filenodes
     global fake_bmark, hg_version
     global dry_run
     global notes, alias
@@ -1199,7 +1181,6 @@ def main(args):
     blob_marks = {}
     parsed_refs = {}
     parsed_tags = {}
-    filenodes = {}
     fake_bmark = None
     try:
         hg_version = tuple(int(e) for e in util.version().split('.'))

@felipec felipec closed this as completed Oct 31, 2013
@itronics
Copy link
Author

You are unbeatable! Thank you very much for the patch above, works indeed as expected :).

Janusz

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