77from .__info__ import __version__
88from .enums import CommitSpread
99from .repository import Repository
10+ from .contexts import ProfileContext
1011from .batch import get_files_last_commits , claim_files , update_tracked_commits
1112
1213
@@ -66,9 +67,25 @@ def config(ctx, prop): # pylint: disable=missing-function-docstring
6667 "files their permissions changed."
6768 )
6869)
70+ @click .option (
71+ "-p" ,
72+ "--profile" ,
73+ is_flag = True ,
74+ help = (
75+ "Will generate a profile file in the current working directory."
76+ "The file can be opened in a profiler like snakeviz."
77+ ),
78+ )
6979@click .pass_context
70- def update (ctx ):
71- """Update tracked commits with local changes."""
80+ def update (ctx , profile = False ): # pylint: disable=missing-function-docstring
81+ if profile :
82+ with ProfileContext ():
83+ run_update (ctx )
84+ return
85+ run_update (ctx )
86+
87+
88+ def run_update (ctx ): # pylint: disable=missing-function-docstring
7289 repository = Repository .from_filename (ctx .obj .get ("REPOSITORY" , "" ))
7390 if repository :
7491 asyncio .run (update_tracked_commits (repository ))
@@ -94,13 +111,8 @@ def update(ctx):
94111@click .pass_context
95112def status (ctx , filename , profile = False ): # pylint: disable=missing-function-docstring
96113 if profile :
97- import cProfile # pylint: disable=import-outside-toplevel
98- import pstats # pylint: disable=import-outside-toplevel
99-
100- with cProfile .Profile () as pr :
114+ with ProfileContext ():
101115 run_status (ctx , filename )
102- results = pstats .Stats (pr )
103- results .dump_stats ("gitalong.prof" )
104116 return
105117 run_status (ctx , filename )
106118
@@ -132,8 +144,25 @@ def run_status(ctx, filename): # pylint: disable=missing-function-docstring
132144 nargs = - 1 ,
133145 # help="The path to the file that should be made writable."
134146)
147+ @click .option (
148+ "-p" ,
149+ "--profile" ,
150+ is_flag = True ,
151+ help = (
152+ "Will generate a profile file in the current working directory."
153+ "The file can be opened in a profiler like snakeviz."
154+ ),
155+ )
135156@click .pass_context
136- def claim (ctx , filename ): # pylint: disable=missing-function-docstring
157+ def claim (ctx , filename , profile = False ): # pylint: disable=missing-function-docstring
158+ if profile :
159+ with ProfileContext ():
160+ run_claim (ctx , filename )
161+ return
162+ run_claim (ctx , filename )
163+
164+
165+ def run_claim (ctx , filename ): # pylint: disable=missing-function-docstring
137166 absolute_filenames = []
138167 for filename_ in filename :
139168 repository = Repository .from_filename (ctx .obj .get ("REPOSITORY" , filename_ ))
0 commit comments