1

I want to apply the below changes to some code that someone has written and provided a diff output from. Is there a way given only the output below I can easily create a patch and apply it, or (as it's only a few lines) should I just stick with making the changes by hand?

Even excluding the example below, if this was a large diff output then I would really want to know if given only this, can I feed this into patch or similar?

diff -r -c ganeti-2.5.1_orig/lib//constants.py
ganeti-2.5.1/lib//constants.py
*** ganeti-2.5.1_orig/lib//constants.py 2012-05-11 16:55:13.000000000 +0400
--- ganeti-2.5.1/lib//constants.py      2012-06-28 13:30:41.000000000 +0400
***************
*** 698,703 ****
--- 698,704 ----
  HV_KVM_USE_CHROOT = "use_chroot"
  HV_CPU_MASK = "cpu_mask"
  HV_MEM_PATH = "mem_path"
+ HV_PASSTHROUGH = "pci_pass"
  HV_BLOCKDEV_PREFIX = "blockdev_prefix"
  HV_REBOOT_BEHAVIOR = "reboot_behavior"

***************
*** 743,748 ****
--- 744,750 ----
    HV_KVM_USE_CHROOT: VTYPE_BOOL,
    HV_CPU_MASK: VTYPE_STRING,
    HV_MEM_PATH: VTYPE_STRING,
+   HV_PASSTHROUGH: VTYPE_STRING,
    HV_BLOCKDEV_PREFIX: VTYPE_STRING,
    HV_REBOOT_BEHAVIOR: VTYPE_STRING,
    }
***************
*** 1280,1285 ****
--- 1282,1288 ----
      HV_MIGRATION_MODE: HT_MIGRATION_NONLIVE,
      HV_USE_LOCALTIME: False,
      HV_BLOCKDEV_PREFIX: "hd",
+     HV_PASSTHROUGH: "",
      HV_REBOOT_BEHAVIOR: INSTANCE_REBOOT_ALLOWED,
      },
    HT_KVM: {
diff -r -c ganeti-2.5.1_orig/lib//hypervisor/hv_xen.py
ganeti-2.5.1/lib//hypervisor/hv_xen.py
*** ganeti-2.5.1_orig/lib//hypervisor/hv_xen.py 2012-05-11
16:55:13.000000000 +0400
--- ganeti-2.5.1/lib//hypervisor/hv_xen.py      2012-06-28
13:30:43.000000000 +0400
***************
*** 579,585 ****
      constants.HV_USE_LOCALTIME: hv_base.NO_CHECK,
      # TODO: Add a check for the blockdev prefix (matching [a-z:] or
similar).
      constants.HV_BLOCKDEV_PREFIX: hv_base.NO_CHECK,
!     constants.HV_REBOOT_BEHAVIOR:
        hv_base.ParamInSet(True, constants.REBOOT_BEHAVIORS)
      }

--- 579,587 ----
      constants.HV_USE_LOCALTIME: hv_base.NO_CHECK,
      # TODO: Add a check for the blockdev prefix (matching [a-z:] or
similar).
      constants.HV_BLOCKDEV_PREFIX: hv_base.NO_CHECK,
! #passthrough pci
!     constants.HV_PASSTHROUGH:  hv_base.NO_CHECK,
!    constants.HV_REBOOT_BEHAVIOR:
        hv_base.ParamInSet(True, constants.REBOOT_BEHAVIORS)
      }

***************
*** 671,677 ****
        disk_data.append(iso)

      config.write("disk = [%s]\n" % (",".join(disk_data)))
!
      config.write("on_poweroff = 'destroy'\n")
      if hvp[constants.HV_REBOOT_BEHAVIOR] ==
constants.INSTANCE_REBOOT_ALLOWED:
        config.write("on_reboot = 'restart'\n")
--- 673,684 ----
        disk_data.append(iso)

      config.write("disk = [%s]\n" % (",".join(disk_data)))
!     # this is pci pass
!     pci_pass = hvp[constants.HV_PASSTHROUGH]
!     if pci_pass:
!        pci_pass_arr = []
!        pci_pass_arr = pci_pass.split("/")
!        config.write("pci = %s \n" % pci_pass_arr)
      config.write("on_poweroff = 'destroy'\n")
      if hvp[constants.HV_REBOOT_BEHAVIOR] ==
constants.INSTANCE_REBOOT_ALLOWED:
        config.write("on_reboot = 'restart'\n")
diff -r -c ganeti-2.5.1_orig/lib//query.py ganeti-2.5.1/lib//query.py
*** ganeti-2.5.1_orig/lib//query.py     2012-05-11 16:55:13.000000000 +0400
--- ganeti-2.5.1/lib//query.py  2012-06-28 13:30:43.000000000 +0400
***************
*** 1638,1643 ****
--- 1638,1644 ----
      constants.HV_NIC_TYPE: "NIC_type",
      constants.HV_PAE: "PAE",
      constants.HV_VNC_BIND_ADDRESS: "VNC_bind_address",
+     constants.HV_PASSTHROUGH: "pci_pass",
      }

    fields = [
1
  • Yes, that’s how diff/patch works. You find the differences so that you only need to store those instead of the whole file, then you can patch a file automatically. The file above is the patch, you don’t need to create it. You apply it to the existing file (assuming the existing file is from the immediately previous version from the patch). – Synetech Sep 17 '12 at 16:52
1

Yes, you can use patch for applying this diff to a file. Save it as foo.diff and apply it like this:

patch < foo.diff
1
  • Ah yes I see now, sorry for my late reply. It took me a while to test this out. I see now that patch takes direct diff output as input. I didn't realise it would understand the formatting of diff directly and though it may have to be formatted correctly for patch. Thanks! – jwbensley Sep 27 '12 at 15:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.