STAG-DIFF(1p)

πŸ“¦
version 0.14 Β· 3 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu questing

✨ STAG-DIFF ✨

okay bestie, so this is the manual page for stag-diff, part of the User Contributed Perl Documentation collection. if you've ever needed to know whether two stag files are actually the same vibe or lowkey beefing, this is your girl πŸ¦‹


🌸 NAME 🌸

stag-diff β€” finds the difference between two stag files. yes that's it. that's the whole job. and she does it beautifully. πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

stag-diff -ignore foo-id -ignore bar-id file1.xml file2.xml

like. look at her. so simple. so iconic. πŸ‘‘


πŸ’– DESCRIPTION πŸ’–

So basically she compares two data trees and reports whether they match. and if they don't match?? bestie she WILL tell you. the mismatch gets reported. no secrets here, we're in a healthy communicative relationship πŸ’œ

🧚 ARGUMENTS

  • -help|h β€” shows this document. self care. read the docs, babes 🫢
  • -ignore|i ELEMENT β€” these nodes get ignored for the purposes of comparison. lowkey ghosting them, and honestly? valid.
⚠️ important detail: attributes are treated as elements, prefixed by the containing element id. so keep that in mind, okay?

for example, if you have

<foo ID="wibble">

and you wish to ignore the ID attribute, then you would use the switch

-ignore foo-ID

you can specify multiple elements to ignore like this:

-i foo -i bar -i baz

you can also specify paths:

-i foo/bar/bar-id
  • -parser|p FORMAT β€” which parser to use. the default is XML. this can also be autodetected by the file suffix. other alternatives are sxpr and itext. see Data::Stag for details πŸ‘€
  • -report|r ELEMENT β€” report mismatches as they occur on each element of type ELEMENT. and yes bestie, multiple elements can be specified. we love options πŸ’–
  • -verbose|v β€” used in conjunction with the -report switch. shows the tree of the mismatching element. it's giving forensic investigator πŸ”βœ¨

πŸ”₯ OUTPUT

if a mismatch is reported, a report is generated displaying the subpart of the tree that could not be matched. this will look like this:

REASON: no_matching_node: annotation
  no_matching_node: feature_set
    no_matching_node: feature_span
      no_matching_node: evidence
        no_matching_node: evidence-id
          data_mismatch(:15077290 ne :15077291): evidence-id AND
evidence-id

ngl, due to the nature of tree matching, it can be difficult to specify exactly how trees do not match 😭. to investigate this, you may need to use the -r and -v options. for the above output, I would recommend using

stag-diff -r feature_span -v

she's got layers, okay?? you just gotta dig a lil πŸ’…


🌈 ALGORITHM 🌈

both trees are recursively traversed... see the actual code for how this works πŸ’€ (yes, that's genuinely what the docs say, and honestly? respect the honesty)

the order of elements is not important. eg

<foo>
  <bar>
    <baz>1</baz>
  </bar>
  <bar>
    <baz>2</baz>
  </bar>
</foo>

matches

<foo>
  <bar>
    <baz>2</baz>
  </bar>
  <bar>
    <baz>1</baz>
  </bar>
</foo>

see?? same energy. different order. she does not care about your sequencing, she cares about your content πŸ’–

⚠️ the drama part: the recursive nature of this algorithm means that certain tree comparisons will explode wrt time and memory. I think this will only happen with very deep trees where nodes high up in the tree can only be differentiated by nodes low down in the tree. so like... don't do that?? 😭
⚠️ also: both trees are loaded into memory to begin with, so it may thrash with very large documents. she's holding everything in her head at once, which is so relatable but also a warning 🌸

πŸ‘‘ AUTHOR πŸ‘‘

Chris Mungall β€” cjm at fruitfly dot org. thank you for your service king 🫢


⭐ SEE ALSO ⭐

  • Data::Stag

and that's the whole page bestie!! this was documented with perl v5.34.0, dated 2022-06-12, and filed under STAG-DIFF(1p) πŸ’œ stay matching, stay iconic βœ¨πŸŽ€

πŸ“¦ where this page comes from