comparison hgext/mq.py @ 2934:2f190e998eb3

Teach mq about git patches
author Brendan Cully <brendan@kublai.com>
date Wed, 16 Aug 2006 19:49:45 -0700
parents 773c5b82d052
children 21bf8929efc8
comparison
equal deleted inserted replaced
2933:439fd013360d 2934:2f190e998eb3
250 subject = None 250 subject = None
251 diffstart = 0 251 diffstart = 0
252 252
253 for line in file(pf): 253 for line in file(pf):
254 line = line.rstrip() 254 line = line.rstrip()
255 if line.startswith('diff --git'):
256 diffstart = 2
257 break
255 if diffstart: 258 if diffstart:
256 if line.startswith('+++ '): 259 if line.startswith('+++ '):
257 diffstart = 2 260 diffstart = 2
258 break 261 break
259 if line.startswith("--- "): 262 if line.startswith("--- "):
406 self.ui.note(str(inst) + '\n') 409 self.ui.note(str(inst) + '\n')
407 if not self.ui.verbose: 410 if not self.ui.verbose:
408 self.ui.warn("patch failed, unable to continue (try -v)\n") 411 self.ui.warn("patch failed, unable to continue (try -v)\n")
409 return (False, [], False) 412 return (False, [], False)
410 413
411 return (True, files.keys(), fuzz) 414 return (True, files, fuzz)
412 415
413 def apply(self, repo, series, list=False, update_status=True, 416 def apply(self, repo, series, list=False, update_status=True,
414 strict=False, patchdir=None, merge=None, wlock=None): 417 strict=False, patchdir=None, merge=None, wlock=None):
415 # TODO unify with commands.py 418 # TODO unify with commands.py
416 if not patchdir: 419 if not patchdir:
419 if not wlock: 422 if not wlock:
420 wlock = repo.wlock() 423 wlock = repo.wlock()
421 lock = repo.lock() 424 lock = repo.lock()
422 tr = repo.transaction() 425 tr = repo.transaction()
423 n = None 426 n = None
424 for patch in series: 427 for patchname in series:
425 pushable, reason = self.pushable(patch) 428 pushable, reason = self.pushable(patchname)
426 if not pushable: 429 if not pushable:
427 self.explain_pushable(patch, all_patches=True) 430 self.explain_pushable(patchname, all_patches=True)
428 continue 431 continue
429 self.ui.warn("applying %s\n" % patch) 432 self.ui.warn("applying %s\n" % patchname)
430 pf = os.path.join(patchdir, patch) 433 pf = os.path.join(patchdir, patchname)
431 434
432 try: 435 try:
433 message, comments, user, date, patchfound = self.readheaders(patch) 436 message, comments, user, date, patchfound = self.readheaders(patchname)
434 except: 437 except:
435 self.ui.warn("Unable to read %s\n" % pf) 438 self.ui.warn("Unable to read %s\n" % patchname)
436 err = 1 439 err = 1
437 break 440 break
438 441
439 if not message: 442 if not message:
440 message = "imported patch %s\n" % patch 443 message = "imported patch %s\n" % patchname
441 else: 444 else:
442 if list: 445 if list:
443 message.append("\nimported patch %s" % patch) 446 message.append("\nimported patch %s" % patchname)
444 message = '\n'.join(message) 447 message = '\n'.join(message)
445 448
446 (patcherr, files, fuzz) = self.patch(repo, pf) 449 (patcherr, files, fuzz) = self.patch(repo, pf)
447 patcherr = not patcherr 450 patcherr = not patcherr
448 451
449 if merge and len(files) > 0: 452 if merge and files:
450 # Mark as merged and update dirstate parent info 453 # Mark as merged and update dirstate parent info
451 repo.dirstate.update(repo.dirstate.filterfiles(files), 'm') 454 repo.dirstate.update(repo.dirstate.filterfiles(files.keys()), 'm')
452 p1, p2 = repo.dirstate.parents() 455 p1, p2 = repo.dirstate.parents()
453 repo.dirstate.setparents(p1, merge) 456 repo.dirstate.setparents(p1, merge)
454 if len(files) > 0: 457 files = patch.updatedir(self.ui, repo, files, wlock=wlock)
455 cwd = repo.getcwd()
456 cfiles = files
457 if cwd:
458 cfiles = [util.pathto(cwd, f) for f in files]
459 cmdutil.addremove(repo, cfiles, wlock=wlock)
460 n = repo.commit(files, message, user, date, force=1, lock=lock, 458 n = repo.commit(files, message, user, date, force=1, lock=lock,
461 wlock=wlock) 459 wlock=wlock)
462 460
463 if n == None: 461 if n == None:
464 raise util.Abort(_("repo commit failed")) 462 raise util.Abort(_("repo commit failed"))
465 463
466 if update_status: 464 if update_status:
467 self.applied.append(statusentry(revlog.hex(n), patch)) 465 self.applied.append(statusentry(revlog.hex(n), patchname))
468 466
469 if patcherr: 467 if patcherr:
470 if not patchfound: 468 if not patchfound:
471 self.ui.warn("patch %s is empty\n" % patch) 469 self.ui.warn("patch %s is empty\n" % patchname)
472 err = 0 470 err = 0
473 else: 471 else:
474 self.ui.warn("patch failed, rejects left in working dir\n") 472 self.ui.warn("patch failed, rejects left in working dir\n")
475 err = 1 473 err = 1
476 break 474 break
997 changes=(m, a, r, [], u), fp=patchf) 995 changes=(m, a, r, [], u), fp=patchf)
998 patchf.close() 996 patchf.close()
999 997
1000 changes = repo.changelog.read(tip) 998 changes = repo.changelog.read(tip)
1001 repo.dirstate.setparents(*cparents) 999 repo.dirstate.setparents(*cparents)
1000 copies = [(f, repo.dirstate.copied(f)) for f in a]
1002 repo.dirstate.update(a, 'a') 1001 repo.dirstate.update(a, 'a')
1002 for dst, src in copies:
1003 repo.dirstate.copy(src, dst)
1003 repo.dirstate.update(r, 'r') 1004 repo.dirstate.update(r, 'r')
1004 repo.dirstate.update(m, 'n') 1005 repo.dirstate.update(m, 'n')
1005 repo.dirstate.forget(forget) 1006 repo.dirstate.forget(forget)
1006 1007
1007 if not msg: 1008 if not msg: