Commits

Patrick Mézard committed 51d151a

climport: add command to import changelist, only print with --dry-run

  • Participants
  • Parent commits 5ccbe93

Comments (0)

Files changed (2)

File lib/codereview/codereview.py

 	else:
 		ui.status('Issue closed. URL: %s\n' % cl.url)
 
+@hgcommand
+def climport(ui, repo, clname, **opts):
+	"""import a change list from code review server"""
+	if codereview_disabled:
+		raise hg_util.Abort(codereview_disabled)
+	cl, vers, patch, err = DownloadCL(ui, repo, clname, skip_contributors=True)
+	if err:
+		raise hg_util.Abort(err)
+	if patch == emptydiff:
+		ui.warn("codereview issue %s has no diff" % clname)
+		return 1
+	if opts.get('dry_run'):
+		ui.write(patch)
+		return 0
+	raise hg_util.Abort("not implemented")
+
 def clidkw(**args):
 	""":clid: String. Codereview changelist identifier or the empty string."""
 	_, name = extractclname(args['ctx'].description())
 		],
 		"[OPTIONS] REV",
 	),
+	"^climport": (
+		climport,
+		[
+			('n', 'dry-run', None, 'do not apply the changes, print them'),
+		],
+		"CLID",
+	),
 }
 
 #######################################################################
 			return True
 	return False
 
-def DownloadCL(ui, repo, clname):
+def DownloadCL(ui, repo, clname, skip_contributors=None):
 	set_status("downloading CL " + clname)
 	cl, err = LoadCL(ui, repo, clname, web=True)
 	if err != "":
 
 	diffdata = MySend(diff, force_auth=False)
 	
+	if skip_contributors:
+		return cl, vers, diffdata, ""
 	# Print warning if email is not in CONTRIBUTORS file.
-	email = cl.dict.get("owner_email", "")
 	if not email:
 		return None, None, None, "cannot find owner for %s" % (clname)
 	him = FindContributor(ui, repo, email)

File tests/test-codereview-clpush.t

 
   $ hg log -r . --template 'CLID: {clid}\n'
   CLID: \d+ (re)
+  $ clid=$(hg log -r . --template '{clid}')
+
+Import invalid changelist
+
+  $ hg climport 65010045
+  .*HTTP Error 404: Not Found (re)
+  abort: error loading CL \d+: cannot load CL \d+ from server (re)
+  [255]
+
+Test climport --dry-run
+
+  $ hg climport --dry-run ${clid}
+  Index: a
+  ===================================================================
+  new file mode 100644
+  --- /dev/null
+  +++ b/a
+  @@ -0,0 +1,2 @@
+  +a
+  +a
 
 Test clclose arguments