Staging instance, all changes can be removed at any time

Skip to content

anlambert/diff_swh_revisions: Add option to compute content diffs

Antoine Lambert requested to merge diff-revisions-compute-content-diffs into master

It enables to compute diffs of contents modified in a revision and add them to the NDJSON output in new diff fields.

Examples of use:

  • plain NDJSON output:
$ ./diff_swh_revisions.py --with-content-diffs swh:1:rev:b7bc77e2f2c714c82aa723445d98fa4c2fb63e90 | jq 
[
  {
    "type": "modify",
    "path": "drivers/pci/of.c",
    "diff": "--- drivers/pci/of.c\n+++ drivers/pci/of.c\n@@ -16,14 +16,32 @@\n #include \"pci.h\"\n \n #ifdef CONFIG_PCI\n-void pci_set_of_node(struct pci_dev *dev)\n-{\n+/**\n+ * pci_set_of_node - Find and set device's DT device_node\n+ * @dev: the PCI device structure to fill\n+ *\n+ * Returns 0 on success with of_node set or when no device is described in the\n+ * DT. Returns -ENODEV if the device is present, but disabled in the DT.\n+ */\n+int pci_set_of_node(struct pci_dev *dev)\n+{\n+\tstruct device_node *node;\n+\n \tif (!dev->bus->dev.of_node)\n-\t\treturn;\n-\tdev->dev.of_node = of_pci_find_child_device(dev->bus->dev.of_node,\n-\t\t\t\t\t\t    dev->devfn);\n-\tif (dev->dev.of_node)\n-\t\tdev->dev.fwnode = &dev->dev.of_node->fwnode;\n+\t\treturn 0;\n+\n+\tnode = of_pci_find_child_device(dev->bus->dev.of_node, dev->devfn);\n+\tif (!node)\n+\t\treturn 0;\n+\n+\tif (!of_device_is_available(node)) {\n+\t\tof_node_put(node);\n+\t\treturn -ENODEV;\n+\t}\n+\n+\tdev->dev.of_node = node;\n+\tdev->dev.fwnode = &node->fwnode;\n+\treturn 0;\n }\n \n void pci_release_of_node(struct pci_dev *dev)\n"
  },
  {
    "type": "modify",
    "path": "drivers/pci/pci.h",
    "diff": "--- drivers/pci/pci.h\n+++ drivers/pci/pci.h\n@@ -624,7 +624,7 @@\n u32 of_pci_get_slot_power_limit(struct device_node *node,\n \t\t\t\tu8 *slot_power_limit_value,\n \t\t\t\tu8 *slot_power_limit_scale);\n-void pci_set_of_node(struct pci_dev *dev);\n+int pci_set_of_node(struct pci_dev *dev);\n void pci_release_of_node(struct pci_dev *dev);\n void pci_set_bus_of_node(struct pci_bus *bus);\n void pci_release_bus_of_node(struct pci_bus *bus);\n@@ -662,7 +662,7 @@\n \treturn 0;\n }\n \n-static inline void pci_set_of_node(struct pci_dev *dev) { }\n+static inline int pci_set_of_node(struct pci_dev *dev) { return 0; }\n static inline void pci_release_of_node(struct pci_dev *dev) { }\n static inline void pci_set_bus_of_node(struct pci_bus *bus) { }\n static inline void pci_release_bus_of_node(struct pci_bus *bus) { }\n"
  },
  {
    "type": "modify",
    "path": "drivers/pci/probe.c",
    "diff": "--- drivers/pci/probe.c\n+++ drivers/pci/probe.c\n@@ -1826,7 +1826,7 @@\n \tu32 class;\n \tu16 cmd;\n \tu8 hdr_type;\n-\tint pos = 0;\n+\tint err, pos = 0;\n \tstruct pci_bus_region region;\n \tstruct resource *res;\n \n@@ -1840,10 +1840,10 @@\n \tdev->error_state = pci_channel_io_normal;\n \tset_pcie_port_type(dev);\n \n-\tpci_set_of_node(dev);\n+\terr = pci_set_of_node(dev);\n+\tif (err)\n+\t\treturn err;\n \tpci_set_acpi_fwnode(dev);\n-\tif (dev->dev.fwnode && !fwnode_device_is_available(dev->dev.fwnode))\n-\t\treturn -ENODEV;\n \n \tpci_dev_assign_slot(dev);\n \n"
  }
]
  • extracting content diffs as raw strings
$ ./diff_swh_revisions.py --with-content-diffs swh:1:rev:b7bc77e2f2c714c82aa723445d98fa4c2fb63e90 | jq -r .[].diff
--- drivers/pci/of.c
+++ drivers/pci/of.c
@@ -16,14 +16,32 @@
 #include "pci.h"
 
 #ifdef CONFIG_PCI
-void pci_set_of_node(struct pci_dev *dev)
-{
+/**
+ * pci_set_of_node - Find and set device's DT device_node
+ * @dev: the PCI device structure to fill
+ *
+ * Returns 0 on success with of_node set or when no device is described in the
+ * DT. Returns -ENODEV if the device is present, but disabled in the DT.
+ */
+int pci_set_of_node(struct pci_dev *dev)
+{
+       struct device_node *node;
+
        if (!dev->bus->dev.of_node)
-               return;
-       dev->dev.of_node = of_pci_find_child_device(dev->bus->dev.of_node,
-                                                   dev->devfn);
-       if (dev->dev.of_node)
-               dev->dev.fwnode = &dev->dev.of_node->fwnode;
+               return 0;
+
+       node = of_pci_find_child_device(dev->bus->dev.of_node, dev->devfn);
+       if (!node)
+               return 0;
+
+       if (!of_device_is_available(node)) {
+               of_node_put(node);
+               return -ENODEV;
+       }
+
+       dev->dev.of_node = node;
+       dev->dev.fwnode = &node->fwnode;
+       return 0;
 }
 
 void pci_release_of_node(struct pci_dev *dev)

--- drivers/pci/pci.h
+++ drivers/pci/pci.h
@@ -624,7 +624,7 @@
 u32 of_pci_get_slot_power_limit(struct device_node *node,
                                u8 *slot_power_limit_value,
                                u8 *slot_power_limit_scale);
-void pci_set_of_node(struct pci_dev *dev);
+int pci_set_of_node(struct pci_dev *dev);
 void pci_release_of_node(struct pci_dev *dev);
 void pci_set_bus_of_node(struct pci_bus *bus);
 void pci_release_bus_of_node(struct pci_bus *bus);
@@ -662,7 +662,7 @@
        return 0;
 }
 
-static inline void pci_set_of_node(struct pci_dev *dev) { }
+static inline int pci_set_of_node(struct pci_dev *dev) { return 0; }
 static inline void pci_release_of_node(struct pci_dev *dev) { }
 static inline void pci_set_bus_of_node(struct pci_bus *bus) { }
 static inline void pci_release_bus_of_node(struct pci_bus *bus) { }

--- drivers/pci/probe.c
+++ drivers/pci/probe.c
@@ -1826,7 +1826,7 @@
        u32 class;
        u16 cmd;
        u8 hdr_type;
-       int pos = 0;
+       int err, pos = 0;
        struct pci_bus_region region;
        struct resource *res;
 
@@ -1840,10 +1840,10 @@
        dev->error_state = pci_channel_io_normal;
        set_pcie_port_type(dev);
 
-       pci_set_of_node(dev);
+       err = pci_set_of_node(dev);
+       if (err)
+               return err;
        pci_set_acpi_fwnode(dev);
-       if (dev->dev.fwnode && !fwnode_device_is_available(dev->dev.fwnode))
-               return -ENODEV;
 
        pci_dev_assign_slot(dev);

Merge request reports

Loading