# How to efficiently query dependencies for all changes?

**URL:** <https://discourse.pijul.org/t/how-to-efficiently-query-dependencies-for-all-changes/862>\
**Category:** Question\
**Created:** [January 25, 2022, 5:38pm UTC](https://discourse.pijul.org/t/how-to-efficiently-query-dependencies-for-all-changes/862 "2022-01-25T17:38:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mstrap](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.pijul.org/mstrap/32/429_2.png) [@mstrap](https://discourse.pijul.org/u/mstrap)\
**Post date:** [January 25, 2022, 5:38pm UTC](https://discourse.pijul.org/t/how-to-efficiently-query-dependencies-for-all-changes/862/1 "2022-01-25T17:38:11Z")

</div>

I’m trying to generate a graph of all changes present in a repository and the dependencies between them. I’m only aware of `pijul change`, but forking a separate process for every single change will most likely become too expensive for large repositories. Is there some single command to query the dependencies for all changes at once? I would have expected some option to `pijul log`, but couldn’t find any.

-Marc

---

<div class="post-metadata">

**Author:** ![spacefrogg](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.pijul.org/spacefrogg/32/37_2.png) [@spacefrogg](https://discourse.pijul.org/u/spacefrogg)\
**Post date:** [January 27, 2022, 11:40am UTC](https://discourse.pijul.org/t/how-to-efficiently-query-dependencies-for-all-changes/862/2 "2022-01-27T11:40:48Z")

</div>

The dependencies for _all_ changes are exactly the changes that are returned by `pijul log`. So, likely, that is not what you want to have.

So, what is it you actually want to know? Do you look for the dependency graph, maybe?

---

<div class="post-metadata">

**Author:** ![mstrap](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.pijul.org/mstrap/32/429_2.png) [@mstrap](https://discourse.pijul.org/u/mstrap)\
**Post date:** [January 27, 2022, 1:23pm UTC](https://discourse.pijul.org/t/how-to-efficiently-query-dependencies-for-all-changes/862/3 "2022-01-27T13:23:40Z")

</div>

Right, I’m looking for the dependency graph (in JSON format, not rendered as graph) which comprises exactly those dependencies which are reported by `pijul change`, in `# Dependencies` section, including the dependency-type (normal vs. `+` vs. `*`).

In terms of Git, I’m looking for `git log --format=raw`.

-Marc

---

<div class="post-metadata">

**Author:** ![spacefrogg](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.pijul.org/spacefrogg/32/37_2.png) [@spacefrogg](https://discourse.pijul.org/u/spacefrogg)\
**Post date:** [January 27, 2022, 2:06pm UTC](https://discourse.pijul.org/t/how-to-efficiently-query-dependencies-for-all-changes/862/4 "2022-01-27T14:06:29Z")

</div>

That does not exist, yet. The principle functionality is there and can be seen with `pijul log --output-format json`. It is not yet integrated into `pijul change`, though.

---

<div class="post-metadata">

**Author:** ![mstrap](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.pijul.org/mstrap/32/429_2.png) [@mstrap](https://discourse.pijul.org/u/mstrap)\
**Post date:** [January 27, 2022, 2:57pm UTC](https://discourse.pijul.org/t/how-to-efficiently-query-dependencies-for-all-changes/862/5 "2022-01-27T14:57:08Z")

</div>

Thanks. IMHO, the most intuitive solution to provide these dependencies would be an additional option for `pijul log`. It already has nice pagination with `--limit` and `--offset` and offers `--json`, so it’s quite flexible. A more low-level approach might be to have `pijul change` to accept a list of hashes and optionally output in a machine-parsable format, probably JSON for consistency with the other commands.

Does any of the above sound more reasonable than the other (also taking into account technical considerations)? I’d then file a discussion/RFE for that.

Btw, in the meanwhile I have experimented with a combination of a single `pijul log --hash-only` and one `pijul change` per hash. On Windows, for pijul/pijul, doing this entire query requires ~170 seconds for 765 changes.

-Marc

---

<div class="post-metadata">

**Author:** ![joyously](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.pijul.org/joyously/32/266_2.png) [@joyously](https://discourse.pijul.org/u/joyously)\
**Post date:** [June 27, 2022, 9:53pm UTC](https://discourse.pijul.org/t/how-to-efficiently-query-dependencies-for-all-changes/862/6 "2022-06-27T21:53:02Z")

</div>

I was looking for this also, so I saw a script [saved in a change](https://nest.pijul.com/pijul/pijul/changes/SL45MHGVMBZRSCYCOPWYTXJEY3WKRLELNYXLBYUOT6MKLSRSUCPAC) on one of the [Pijul discussions](https://nest.pijul.com/pijul/pijul/discussions/301). It has some redundant code, so once I reduced it, it’s a lot like what you describe

> combination of a single `pijul log --hash-only` and one `pijul change` per hash

Here is my version of that script:

```auto
#!/bin/bash
LEN=10

(
echo 'digraph PCG {'
echo 'ratio=fill;'
echo 'size=10;'
echo 'overlap=scale;'
echo 'node [shape=rect target="_blank"];'

pijul log --hash-only "$@" | while read ID; do
    pijul change "$ID" | awk -v oid="$ID" -v idlen="$LEN" '
/^message =/ { msg = substr($0, index($0, $3));
	gsub( /"/, "", msg );
	if (length(msg) > idlen*2) {
		gsub(/([^]+ ){3,4}/, "&\\&#92;n", msg);
	}
	print "\"" substr(oid,0,idlen) "\" [label=\"" substr(oid,0,idlen) "\\n" msg "\"];"; }    
$1 == "#" {
    section = $2;
}
$1 != "#" && $2 != "" && section == "Dependencies" && $1 != "[*]" && substr($1,length($1),1) != "+" {
    print "\"" substr(oid,0,idlen) "\" -> \"" substr($2,0,idlen) "\";";
}
'
done
echo '}'
) | dot -Tsvg /dev/stdin -o /dev/stdout

```

I run it on Ubuntu on the pijul repo and it takes 28 seconds to output the text file for the graph of 807 changes. Generating the SVG from the graph takes longer, but it needs better parameters because the changes are so interdependent that you can’t read it.

Since my goal was to unrecord, I found two things:

1. `unrecord` says “A change can only be unrecorded if all changes that depend on it are also unrecorded in the same operation.”  
There seems to be no way to get a list of changes that depend on one change.
2. When you do `pijul unrecord --show-changes`, you get what the log would show if it showed dependencies. So it looks like that code is written already, but inaccessible for a graph since this option puts it into interactive mode.
