Skip to content

Commit 21beca6

Browse files
Ubuntuclaude
andcommitted
Rename xdiff to diff, add --summary flag for hash/file changes
The diff command now shows actual content differences by default. Use -s/--summary to see which files changed with hashes (previous diff behavior). Changes: - Rename xdiff command to diff - Add -s/--summary flag for metadata/hash view - Change -s (shell-executable) to -e - Remove old diff command (now covered by -s/--summary) - Update tests and rename test_xdiff.py to test_diff.py 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 41f5a0d commit 21beca6

4 files changed

Lines changed: 110 additions & 841 deletions

File tree

dvx/cli/main.py

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -420,32 +420,6 @@ def commit_cmd(ctx, targets, force, with_deps, recursive):
420420
)
421421

422422

423-
@cli.command("diff")
424-
@click.argument("a_rev", required=False)
425-
@click.argument("b_rev", required=False)
426-
@click.option("--targets", "-t", multiple=True, help="Specific targets to diff.")
427-
@click.option("--json", "as_json", is_flag=True, help="Output as JSON.")
428-
@click.option("--md", "as_md", is_flag=True, help="Output as Markdown.")
429-
@click.option("--hide-missing", is_flag=True, help="Hide missing entries.")
430-
@click.pass_context
431-
def diff_cmd(ctx, a_rev, b_rev, targets, as_json, as_md, hide_missing):
432-
"""Show changes between commits or cache and workspace."""
433-
from dvx.repo import Repo
434-
from dvx.ui import ui
435-
from dvx.compare import show_diff
436-
437-
os.chdir(ctx.obj.cd)
438-
repo = Repo(_wait_for_lock=ctx.obj.wait_for_lock)
439-
with repo:
440-
diff_result = repo.diff(a_rev, b_rev, targets=targets or None)
441-
442-
if as_json:
443-
ui.write_json(diff_result)
444-
elif as_md:
445-
from dvx.compare import show_md
446-
show_md(diff_result)
447-
else:
448-
show_diff(diff_result, hide_missing=hide_missing)
449423

450424

451425
@cli.command("gc")
@@ -786,9 +760,9 @@ def remote_list_cmd(ctx, global_, system, local):
786760
ui.write(f"{name}\t{url}")
787761

788762

789-
# Register the xdiff command from content_diff module
790-
from dvx.commands.content_diff import xdiff
791-
cli.add_command(xdiff)
763+
# Register the diff command from content_diff module
764+
from dvx.commands.content_diff import diff
765+
cli.add_command(diff)
792766

793767

794768
def main(argv=None):

dvx/commands/content_diff.py

Lines changed: 58 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -180,56 +180,103 @@ def _diff_directory(path1, path2, data_path, after):
180180
return 1 if has_diff else 0
181181

182182

183-
@click.command("xdiff", no_args_is_help=True)
183+
def _show_summary(ctx, refspec, ref, targets):
184+
"""Show summary of file/hash changes (like old dvx diff)."""
185+
from dvx.repo import Repo
186+
from dvx.commands.diff import CmdDiff
187+
188+
# Parse refspec
189+
if refspec and ref:
190+
raise click.UsageError("Specify -r/--refspec or -R/--ref, not both")
191+
192+
if ref:
193+
# -R <ref> means compare <ref>^ to <ref>
194+
a_rev = f"{ref}^"
195+
b_rev = ref
196+
elif refspec and ".." in refspec:
197+
a_rev, b_rev = refspec.split("..", 1)
198+
elif refspec:
199+
a_rev = refspec
200+
b_rev = None
201+
else:
202+
a_rev = None
203+
b_rev = None
204+
205+
try:
206+
repo = Repo()
207+
except Exception as e:
208+
raise click.ClickException(f"Not a DVX repository: {e}")
209+
210+
with repo:
211+
diff_result = repo.diff(a_rev, b_rev, targets=targets or None)
212+
213+
CmdDiff._show_diff(diff_result)
214+
ctx.exit(0)
215+
216+
217+
@click.command("diff")
184218
@click.option("-b", "--both", is_flag=True, help="Merge stderr into stdout in pipeline commands.")
185219
@click.option("-c/-C", "--color/--no-color", default=None, help="Force or prevent colorized output.")
186220
@click.option("-r", "--refspec", help="<commit1>..<commit2> or <commit> (compare to worktree).")
187221
@click.option("-R", "--ref", help="Shorthand for -r <ref>^..<ref> (compare commit to parent).")
188-
@click.option("-s", "--shell-executable", help="Shell to use for executing commands.")
222+
@click.option("-e", "--shell-executable", help="Shell to use for executing commands.")
189223
@click.option("-S", "--no-shell", is_flag=True, help="Don't use shell for subprocess execution.")
224+
@click.option("-s", "--summary", is_flag=True, help="Show summary of changes (files and hashes) instead of content diff.")
190225
@click.option("-U", "--unified", type=int, help="Number of lines of context.")
191226
@click.option("-v", "--verbose", is_flag=True, help="Log intermediate commands to stderr.")
192227
@click.option("-w", "--ignore-whitespace", is_flag=True, help="Ignore whitespace differences.")
193228
@click.option("-x", "--exec-cmd", "exec_cmds", multiple=True, help="Command to execute before diffing.")
194229
@click.argument("args", nargs=-1, metavar="[cmd...] <path>")
195230
@click.pass_context
196-
def xdiff(
231+
def diff(
197232
ctx,
198233
both: bool,
199234
color: Optional[bool],
200235
refspec: Optional[str],
201236
ref: Optional[str],
202237
shell_executable: Optional[str],
203238
no_shell: bool,
239+
summary: bool,
204240
unified: Optional[int],
205241
verbose: bool,
206242
ignore_whitespace: bool,
207243
exec_cmds: Tuple[str, ...],
208244
args: Tuple[str, ...],
209245
):
210-
"""Diff a DVC-tracked file between commits, optionally through preprocessing commands.
246+
"""Diff DVC-tracked files between commits.
247+
248+
By default, shows actual content differences. Use -s/--summary to show
249+
a summary of which files changed (with hashes) instead.
211250
212251
Examples:
213252
214253
\b
215-
dvx xdiff -r HEAD^..HEAD wc -l foo.dvc
216-
Compare line count of foo at previous vs current commit.
254+
dvx diff data.csv
255+
Show content diff of data.csv between HEAD and worktree.
217256
218257
\b
219-
dvx xdiff md5sum foo
220-
Diff md5sum of foo at HEAD vs current worktree.
258+
dvx diff -r HEAD^..HEAD data.csv
259+
Show content diff between previous and current commit.
221260
222261
\b
223-
dvx xdiff -R abc123 cat data.csv
224-
Show what changed in data.csv at commit abc123.
262+
dvx diff -s
263+
Show summary of all changed files with hashes.
264+
265+
\b
266+
dvx diff -R abc123 wc -l data.csv
267+
Compare line count of data.csv at commit abc123 vs its parent.
225268
"""
226269
from dvx.repo import Repo
227270

271+
# Handle summary mode (shows file/hash changes, not content)
272+
if summary:
273+
return _show_summary(ctx, refspec, ref, args)
274+
228275
# Combine exec_cmds and args
229276
remaining = list(exec_cmds) + list(args)
230277

231278
if not remaining:
232-
raise click.UsageError("Must specify [cmd...] <path>")
279+
raise click.UsageError("Must specify [cmd...] <path> (or use -s/--summary)")
233280

234281
*cmds, target = remaining
235282
data_path, dvc_path = _normalize_path(target)

0 commit comments

Comments
 (0)