Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Unified Diff: sky/tools/pretty-diff

Issue 944193003: Add a dedicated pretty-diff command. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sky/tools/webkitpy/common/checkout/scm/git.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/tools/pretty-diff
diff --git a/sky/tools/webkit-patch b/sky/tools/pretty-diff
similarity index 51%
copy from sky/tools/webkit-patch
copy to sky/tools/pretty-diff
index 2ed9d8daef37b112036410c87670d5036640c46f..5ddeab0ac66030e6f0e1725329d35bcd6a92e24e 100755
--- a/sky/tools/webkit-patch
+++ b/sky/tools/pretty-diff
@@ -32,52 +32,62 @@
#
# A tool for automating dealing with bugzilla, posting patches, committing patches, etc.
-import logging
-import os
-import signal
-import sys
-import codecs
+import time
+import urllib
+import webbrowser
-import webkitpy.common.version_check
+from webkitpy.common.prettypatch import PrettyPatch
+from webkitpy.common.system import logutils
+from webkitpy.common.system.executive import Executive
+from webkitpy.common.system.executive import ScriptError
+from webkitpy.common.system.filesystem import FileSystem
+from webkitpy.common.checkout.scm.detection import detect_scm_system
-from webkitpy.common.system.logutils import configure_logging
-from webkitpy.tool.main import WebKitPatch
-# A StreamWriter will by default try to encode all objects passed
-# to write(), so when passed a raw string already encoded as utf8,
-# it will blow up with an UnicodeDecodeError. This does not match
-# the default behaviour of writing to sys.stdout, so we intercept
-# the case of writing raw strings and make sure StreamWriter gets
-# input that it can handle.
-class ForgivingUTF8Writer(codecs.lookup('utf-8')[-1]):
- def write(self, object):
- if isinstance(object, str):
- # Assume raw strings are utf-8 encoded. If this line
- # fails with an UnicodeDecodeError, our assumption was
- # wrong, and the stacktrace should show you where we
- # write non-Unicode/UTF-8 data (which we shouldn't).
- object = object.decode('utf-8')
- return codecs.StreamWriter.write(self, object)
+_log = logutils.get_logger(__file__)
-# By default, sys.stdout assumes ascii encoding. Since our messages can
-# contain unicode strings (as with some peoples' names) we need to apply
-# the utf-8 codec to prevent throwing and exception.
-# Not having this was the cause of https://bugs.webkit.org/show_bug.cgi?id=63452.
-sys.stdout = ForgivingUTF8Writer(sys.stdout)
-_log = logging.getLogger("webkit-patch")
+def can_open_url():
+ try:
+ webbrowser.get()
+ return True
+ except webbrowser.Error, e:
+ return False
-def main():
- # This is a hack to let us enable DEBUG logging as early as possible.
- # Note this can't be ternary as versioning.check_version()
- # hasn't run yet and this python might be older than 2.5.
- if set(["-v", "--verbose"]).intersection(set(sys.argv)):
- logging_level = logging.DEBUG
- else:
- logging_level = logging.INFO
- configure_logging(logging_level=logging_level)
- WebKitPatch(os.path.abspath(__file__)).main()
+def open_url(url):
+ if not can_open_url():
+ _log.warn("Failed to open %s" % url)
+ webbrowser.open(url)
+def show_pretty_diff():
+ if not can_open_url():
+ return None
+
+ try:
+ pretty_patch = PrettyPatch(Executive())
+ pretty_diff_file = pretty_patch.pretty_diff_file(diff())
+ url = "file://%s" % urllib.quote(pretty_diff_file.name)
+ open_url(url)
+ # We return the pretty_diff_file here because we need to keep the
+ # file alive until the user has had a chance to confirm the diff.
+ return pretty_diff_file
+ except ScriptError, e:
+ _log.warning("PrettyPatch failed. :(")
+ except OSError, e:
+ _log.warning("PrettyPatch unavailable.")
+
+def diff():
+ scm = detect_scm_system(FileSystem().getcwd())
+ changed_files = scm.changed_files()
+ return scm.create_patch(None, changed_files=changed_files)
+
+def main():
+ pretty_diff_file = show_pretty_diff()
+ # This is a terrible hack. Try to give enough time for the
+ # browser to actually load the file.
+ time.sleep(1)
+ if pretty_diff_file:
+ pretty_diff_file.close()
if __name__ == "__main__":
try:
« no previous file with comments | « no previous file | sky/tools/webkitpy/common/checkout/scm/git.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698